diff
sgit.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/sgit.c b/sgit.c
index 8fb08b7..06096ed 100644
--- a/sgit.c
+++ b/sgit.c
@@ -146,8 +146,6 @@ main(int argc, char *argv[])
discover_repos(input, &repos, &nrepos, &cap);
if (nrepos == 0)
errx(1, "no git repositories found in %s", input);
- qsort(repos, nrepos, sizeof(struct repo), repo_cmp);
-
ensure_dir(output);
multi = nrepos > 1;
@@ -181,6 +179,7 @@ main(int argc, char *argv[])
}
if (multi) {
+ qsort(repos, nrepos, sizeof(struct repo), repo_cmp);
make_index(output, repos, nrepos);
}
@@ -597,9 +596,21 @@ static int
repo_cmp(const void *a, const void *b)
{
const struct repo *ra, *rb;
+ int c;
ra = a;
rb = b;
+
+ if (ra->last_date != NULL && rb->last_date != NULL) {
+ c = strcmp(rb->last_date, ra->last_date);
+ if (c != 0)
+ return c;
+ } else if (ra->last_date == NULL && rb->last_date != NULL) {
+ return 1;
+ } else if (ra->last_date != NULL && rb->last_date == NULL) {
+ return -1;
+ }
+
return strcmp(ra->name, rb->name);
}