t9001: style modernisation phase #4
[gitweb.git] / walker.c
index b8a5441d6a7cf1d3981ef17473f41a1984e73647..f149371e71ebdcdbd12336aace15b0fc20f74569 100644 (file)
--- a/walker.c
+++ b/walker.c
@@ -205,7 +205,7 @@ static int mark_complete(const char *path, const unsigned char *sha1, int flag,
        struct commit *commit = lookup_commit_reference_gently(sha1, 1);
        if (commit) {
                commit->object.flags |= COMPLETE;
-               commit_list_insert_by_date(commit, &complete);
+               commit_list_insert(commit, &complete);
        }
        return 0;
 }
@@ -228,8 +228,8 @@ int walker_targets_stdin(char ***target, const char ***write_ref)
 
                if (targets >= targets_alloc) {
                        targets_alloc = targets_alloc ? targets_alloc * 2 : 64;
-                       *target = xrealloc(*target, targets_alloc * sizeof(**target));
-                       *write_ref = xrealloc(*write_ref, targets_alloc * sizeof(**write_ref));
+                       REALLOC_ARRAY(*target, targets_alloc);
+                       REALLOC_ARRAY(*write_ref, targets_alloc);
                }
                (*target)[targets] = xstrdup(tg_one);
                (*write_ref)[targets] = rf_one ? xstrdup(rf_one) : NULL;
@@ -267,8 +267,11 @@ int walker_fetch(struct walker *walker, int targets, char **target,
                        goto done;
                }
        }
-       if (!walker->get_recover)
+
+       if (!walker->get_recover) {
                for_each_ref(mark_complete, NULL);
+               commit_list_sort_by_date(&complete);
+       }
 
        for (i = 0; i < targets; i++) {
                if (interpret_target(walker, target[i], &sha1[20 * i])) {
@@ -286,8 +289,7 @@ int walker_fetch(struct walker *walker, int targets, char **target,
                goto done;
        }
        if (write_ref_log_details) {
-               msg = xmalloc(strlen(write_ref_log_details) + 12);
-               sprintf(msg, "fetch from %s", write_ref_log_details);
+               msg = xstrfmt("fetch from %s", write_ref_log_details);
        } else {
                msg = NULL;
        }
@@ -298,14 +300,13 @@ int walker_fetch(struct walker *walker, int targets, char **target,
                strbuf_addf(&refname, "refs/%s", write_ref[i]);
                if (ref_transaction_update(transaction, refname.buf,
                                           &sha1[20 * i], NULL, 0, 0,
+                                          msg ? msg : "fetch (unknown)",
                                           &err)) {
                        error("%s", err.buf);
                        goto done;
                }
        }
-       if (ref_transaction_commit(transaction,
-                                  msg ? msg : "fetch (unknown)",
-                                  &err)) {
+       if (ref_transaction_commit(transaction, &err)) {
                error("%s", err.buf);
                goto done;
        }