{"thread":{"id":"38042","subject":"[PATCH v2 1/7] prune_remote(): exit early if there are no stale references","startedAt":"2014-11-25T08:02:28Z","lastAt":"2014-11-26T17:55:09Z","messageCount":12,"participants":["Michael Haggerty","Junio C Hamano","Stefan Beller"],"isPatch":true,"patchVersion":2,"patchTotal":7},"messages":[{"id":"252501","messageId":"1416902555-10748-1-git-send-email-mhagger@alum.mit.edu","threadId":"38042","inReplyTo":null,"subject":"[PATCH v2 0/7] repack_without_refs(): convert to string_list","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2014-11-25T08:02:28Z","receivedAt":"2014-11-25T08:02:28Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"This is a re-roll of v1 [1] with the following changes:\n\n* Fix some nits in the commit message and comment change in patch 4/7\n  that were pointed out by Jonathan.\n\n* Add a new patch 7/7 that renames sort_string_list() to\n  string_list_sort() as suggested by Junio.\n\nI would have submitted the name change as a separate patch, but since\nthis patch series uses the function the two series would have\nconflicted. Since I didn't see any other patch series in-flight that\nuse sort_string_list(), I just renamed the function everywhere rather\nthan going to the trouble of deprecating the old function and adding\nthe new function.\n\nThanks to Junio, Jonathan, and Stefan for their reviews of v1.\n\n[1] http://thread.gmane.org/gmane.comp.version-control.git/259831/focus=260030\n\nMichael Haggerty (7):\n  prune_remote(): exit early if there are no stale references\n  prune_remote(): initialize both delete_refs lists in a single loop\n  prune_remote(): sort delete_refs_list references en masse\n  repack_without_refs(): make the refnames argument a string_list\n  prune_remote(): rename local variable\n  prune_remote(): iterate using for_each_string_list_item()\n  Rename sort_string_list() to string_list_sort()\n\n Documentation/technical/api-string-list.txt |  4 +-\n builtin/apply.c                             |  2 +-\n builtin/receive-pack.c                      |  2 +-\n builtin/remote.c                            | 69 +++++++++++++----------------\n builtin/repack.c                            |  2 +-\n connect.c                                   |  2 +-\n notes.c                                     |  2 +-\n refs.c                                      | 38 ++++++++--------\n refs.h                                      | 10 ++++-\n remote.c                                    |  6 +--\n sha1_file.c                                 |  2 +-\n string-list.c                               |  4 +-\n string-list.h                               |  2 +-\n 13 files changed, 75 insertions(+), 70 deletions(-)\n\n-- \n2.1.3\n"},{"id":"252499","messageId":"1416902555-10748-2-git-send-email-mhagger@alum.mit.edu","threadId":"38042","inReplyTo":"1416902555-10748-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH v2 1/7] prune_remote(): exit early if there are no stale references","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2014-11-25T08:02:29Z","receivedAt":"2014-11-25T08:02:29Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"Aside from making the logic clearer, this avoids a call to\nwarn_dangling_symrefs(), which always does a for_each_rawref()\niteration.\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\nReviewed-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n builtin/remote.c | 39 +++++++++++++++++++++------------------\n 1 file changed, 21 insertions(+), 18 deletions(-)\n\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex 7f28f92..d2b684c 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -1325,25 +1325,28 @@ static int prune_remote(const char *remote, int dry_run)\n \tmemset(&states, 0, sizeof(states));\n \tget_remote_ref_states(remote, &states, GET_REF_STATES);\n \n-\tif (states.stale.nr) {\n-\t\tprintf_ln(_(\"Pruning %s\"), remote);\n-\t\tprintf_ln(_(\"URL: %s\"),\n-\t\t       states.remote->url_nr\n-\t\t       ? states.remote->url[0]\n-\t\t       : _(\"(no URL)\"));\n-\n-\t\tdelete_refs = xmalloc(states.stale.nr * sizeof(*delete_refs));\n-\t\tfor (i = 0; i < states.stale.nr; i++)\n-\t\t\tdelete_refs[i] = states.stale.items[i].util;\n-\t\tif (!dry_run) {\n-\t\t\tstruct strbuf err = STRBUF_INIT;\n-\t\t\tif (repack_without_refs(delete_refs, states.stale.nr,\n-\t\t\t\t\t\t&err))\n-\t\t\t\tresult |= error(\"%s\", err.buf);\n-\t\t\tstrbuf_release(&err);\n-\t\t}\n-\t\tfree(delete_refs);\n+\tif (!states.stale.nr) {\n+\t\tfree_remote_ref_states(&states);\n+\t\treturn 0;\n+\t}\n+\n+\tprintf_ln(_(\"Pruning %s\"), remote);\n+\tprintf_ln(_(\"URL: %s\"),\n+\t\t  states.remote->url_nr\n+\t\t  ? states.remote->url[0]\n+\t\t  : _(\"(no URL)\"));\n+\n+\tdelete_refs = xmalloc(states.stale.nr * sizeof(*delete_refs));\n+\tfor (i = 0; i < states.stale.nr; i++)\n+\t\tdelete_refs[i] = states.stale.items[i].util;\n+\tif (!dry_run) {\n+\t\tstruct strbuf err = STRBUF_INIT;\n+\t\tif (repack_without_refs(delete_refs, states.stale.nr,\n+\t\t\t\t\t&err))\n+\t\t\tresult |= error(\"%s\", err.buf);\n+\t\tstrbuf_release(&err);\n \t}\n+\tfree(delete_refs);\n \n \tfor (i = 0; i < states.stale.nr; i++) {\n \t\tconst char *refname = states.stale.items[i].util;\n-- \n2.1.3\n"},{"id":"252500","messageId":"1416902555-10748-3-git-send-email-mhagger@alum.mit.edu","threadId":"38042","inReplyTo":"1416902555-10748-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH v2 2/7] prune_remote(): initialize both delete_refs lists in a single loop","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2014-11-25T08:02:30Z","receivedAt":"2014-11-25T08:02:30Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"Also free them together at the end of the function.\n\nIn a moment, the array version will become redundant. Managing them\ntogether makes later steps more obvious.\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\nReviewed-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n builtin/remote.c | 15 +++++++++------\n 1 file changed, 9 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex d2b684c..d5a5a16 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -1337,8 +1337,13 @@ static int prune_remote(const char *remote, int dry_run)\n \t\t  : _(\"(no URL)\"));\n \n \tdelete_refs = xmalloc(states.stale.nr * sizeof(*delete_refs));\n-\tfor (i = 0; i < states.stale.nr; i++)\n-\t\tdelete_refs[i] = states.stale.items[i].util;\n+\tfor (i = 0; i < states.stale.nr; i++) {\n+\t\tconst char *refname = states.stale.items[i].util;\n+\n+\t\tdelete_refs[i] = refname;\n+\t\tstring_list_insert(&delete_refs_list, refname);\n+\t}\n+\n \tif (!dry_run) {\n \t\tstruct strbuf err = STRBUF_INIT;\n \t\tif (repack_without_refs(delete_refs, states.stale.nr,\n@@ -1346,13 +1351,10 @@ static int prune_remote(const char *remote, int dry_run)\n \t\t\tresult |= error(\"%s\", err.buf);\n \t\tstrbuf_release(&err);\n \t}\n-\tfree(delete_refs);\n \n \tfor (i = 0; i < states.stale.nr; i++) {\n \t\tconst char *refname = states.stale.items[i].util;\n \n-\t\tstring_list_insert(&delete_refs_list, refname);\n-\n \t\tif (!dry_run)\n \t\t\tresult |= delete_ref(refname, NULL, 0);\n \n@@ -1365,8 +1367,9 @@ static int prune_remote(const char *remote, int dry_run)\n \t}\n \n \twarn_dangling_symrefs(stdout, dangling_msg, &delete_refs_list);\n-\tstring_list_clear(&delete_refs_list, 0);\n \n+\tfree(delete_refs);\n+\tstring_list_clear(&delete_refs_list, 0);\n \tfree_remote_ref_states(&states);\n \treturn result;\n }\n-- \n2.1.3\n"},{"id":"252502","messageId":"1416902555-10748-4-git-send-email-mhagger@alum.mit.edu","threadId":"38042","inReplyTo":"1416902555-10748-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH v2 3/7] prune_remote(): sort delete_refs_list references en masse","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2014-11-25T08:02:31Z","receivedAt":"2014-11-25T08:02:31Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"Inserting items into a list in sorted order is O(N^2) whereas\nappending them unsorted and then sorting the list all at once is\nO(N lg N).\n\nstring_list_insert() also removes duplicates, and this change loses\nthat functionality. But the strings in this list, which ultimately\ncome from a for_each_ref() iteration, cannot contain duplicates.\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\nReviewed-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n builtin/remote.c | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex d5a5a16..7d5c8d2 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -1341,8 +1341,9 @@ static int prune_remote(const char *remote, int dry_run)\n \t\tconst char *refname = states.stale.items[i].util;\n \n \t\tdelete_refs[i] = refname;\n-\t\tstring_list_insert(&delete_refs_list, refname);\n+\t\tstring_list_append(&delete_refs_list, refname);\n \t}\n+\tsort_string_list(&delete_refs_list);\n \n \tif (!dry_run) {\n \t\tstruct strbuf err = STRBUF_INIT;\n-- \n2.1.3\n"},{"id":"252503","messageId":"1416902555-10748-5-git-send-email-mhagger@alum.mit.edu","threadId":"38042","inReplyTo":"1416902555-10748-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH v2 4/7] repack_without_refs(): make the refnames argument a string_list","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2014-11-25T08:02:32Z","receivedAt":"2014-11-25T08:02:32Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"Most of the callers have string_lists available already, whereas two\nof them had to read data out of a string_list into an array of strings\njust to call this function. So change repack_without_refs() to take\nthe list of refnames to omit as a string_list, and change the callers\naccordingly.\n\nSuggested-by: Ronnie Sahlberg <sahlberg@google.com>\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n builtin/remote.c | 14 ++------------\n refs.c           | 38 ++++++++++++++++++++------------------\n refs.h           | 10 +++++++++-\n 3 files changed, 31 insertions(+), 31 deletions(-)\n\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex 7d5c8d2..63a6709 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -750,16 +750,11 @@ static int mv(int argc, const char **argv)\n static int remove_branches(struct string_list *branches)\n {\n \tstruct strbuf err = STRBUF_INIT;\n-\tconst char **branch_names;\n \tint i, result = 0;\n \n-\tbranch_names = xmalloc(branches->nr * sizeof(*branch_names));\n-\tfor (i = 0; i < branches->nr; i++)\n-\t\tbranch_names[i] = branches->items[i].string;\n-\tif (repack_without_refs(branch_names, branches->nr, &err))\n+\tif (repack_without_refs(branches, &err))\n \t\tresult |= error(\"%s\", err.buf);\n \tstrbuf_release(&err);\n-\tfree(branch_names);\n \n \tfor (i = 0; i < branches->nr; i++) {\n \t\tstruct string_list_item *item = branches->items + i;\n@@ -1317,7 +1312,6 @@ static int prune_remote(const char *remote, int dry_run)\n \tint result = 0, i;\n \tstruct ref_states states;\n \tstruct string_list delete_refs_list = STRING_LIST_INIT_NODUP;\n-\tconst char **delete_refs;\n \tconst char *dangling_msg = dry_run\n \t\t? _(\" %s will become dangling!\")\n \t\t: _(\" %s has become dangling!\");\n@@ -1336,19 +1330,16 @@ static int prune_remote(const char *remote, int dry_run)\n \t\t  ? states.remote->url[0]\n \t\t  : _(\"(no URL)\"));\n \n-\tdelete_refs = xmalloc(states.stale.nr * sizeof(*delete_refs));\n \tfor (i = 0; i < states.stale.nr; i++) {\n \t\tconst char *refname = states.stale.items[i].util;\n \n-\t\tdelete_refs[i] = refname;\n \t\tstring_list_append(&delete_refs_list, refname);\n \t}\n \tsort_string_list(&delete_refs_list);\n \n \tif (!dry_run) {\n \t\tstruct strbuf err = STRBUF_INIT;\n-\t\tif (repack_without_refs(delete_refs, states.stale.nr,\n-\t\t\t\t\t&err))\n+\t\tif (repack_without_refs(&delete_refs_list, &err))\n \t\t\tresult |= error(\"%s\", err.buf);\n \t\tstrbuf_release(&err);\n \t}\n@@ -1369,7 +1360,6 @@ static int prune_remote(const char *remote, int dry_run)\n \n \twarn_dangling_symrefs(stdout, dangling_msg, &delete_refs_list);\n \n-\tfree(delete_refs);\n \tstring_list_clear(&delete_refs_list, 0);\n \tfree_remote_ref_states(&states);\n \treturn result;\ndiff --git a/refs.c b/refs.c\nindex 5ff457e..b675e01 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -2639,22 +2639,25 @@ static int curate_packed_ref_fn(struct ref_entry *entry, void *cb_data)\n \treturn 0;\n }\n \n-int repack_without_refs(const char **refnames, int n, struct strbuf *err)\n+int repack_without_refs(struct string_list *refnames, struct strbuf *err)\n {\n \tstruct ref_dir *packed;\n \tstruct string_list refs_to_delete = STRING_LIST_INIT_DUP;\n-\tstruct string_list_item *ref_to_delete;\n-\tint i, ret, removed = 0;\n+\tstruct string_list_item *refname, *ref_to_delete;\n+\tint ret, needs_repacking = 0, removed = 0;\n \n \tassert(err);\n \n \t/* Look for a packed ref */\n-\tfor (i = 0; i < n; i++)\n-\t\tif (get_packed_ref(refnames[i]))\n+\tfor_each_string_list_item(refname, refnames) {\n+\t\tif (get_packed_ref(refname->string)) {\n+\t\t\tneeds_repacking = 1;\n \t\t\tbreak;\n+\t\t}\n+\t}\n \n \t/* Avoid locking if we have nothing to do */\n-\tif (i == n)\n+\tif (!needs_repacking)\n \t\treturn 0; /* no refname exists in packed refs */\n \n \tif (lock_packed_refs(0)) {\n@@ -2664,8 +2667,8 @@ int repack_without_refs(const char **refnames, int n, struct strbuf *err)\n \tpacked = get_packed_refs(&ref_cache);\n \n \t/* Remove refnames from the cache */\n-\tfor (i = 0; i < n; i++)\n-\t\tif (remove_entry(packed, refnames[i]) != -1)\n+\tfor_each_string_list_item(refname, refnames)\n+\t\tif (remove_entry(packed, refname->string) != -1)\n \t\t\tremoved = 1;\n \tif (!removed) {\n \t\t/*\n@@ -3738,10 +3741,11 @@ static int ref_update_reject_duplicates(struct ref_update **updates, int n,\n int ref_transaction_commit(struct ref_transaction *transaction,\n \t\t\t   struct strbuf *err)\n {\n-\tint ret = 0, delnum = 0, i;\n-\tconst char **delnames;\n+\tint ret = 0, i;\n \tint n = transaction->nr;\n \tstruct ref_update **updates = transaction->updates;\n+\tstruct string_list refs_to_delete = STRING_LIST_INIT_NODUP;\n+\tstruct string_list_item *ref_to_delete;\n \n \tassert(err);\n \n@@ -3753,9 +3757,6 @@ int ref_transaction_commit(struct ref_transaction *transaction,\n \t\treturn 0;\n \t}\n \n-\t/* Allocate work space */\n-\tdelnames = xmalloc(sizeof(*delnames) * n);\n-\n \t/* Copy, sort, and reject duplicate refs */\n \tqsort(updates, n, sizeof(*updates), ref_update_compare);\n \tif (ref_update_reject_duplicates(updates, n, err)) {\n@@ -3815,16 +3816,17 @@ int ref_transaction_commit(struct ref_transaction *transaction,\n \t\t\t}\n \n \t\t\tif (!(update->flags & REF_ISPRUNING))\n-\t\t\t\tdelnames[delnum++] = update->lock->ref_name;\n+\t\t\t\tstring_list_append(&refs_to_delete,\n+\t\t\t\t\t\t   update->lock->ref_name);\n \t\t}\n \t}\n \n-\tif (repack_without_refs(delnames, delnum, err)) {\n+\tif (repack_without_refs(&refs_to_delete, err)) {\n \t\tret = TRANSACTION_GENERIC_ERROR;\n \t\tgoto cleanup;\n \t}\n-\tfor (i = 0; i < delnum; i++)\n-\t\tunlink_or_warn(git_path(\"logs/%s\", delnames[i]));\n+\tfor_each_string_list_item(ref_to_delete, &refs_to_delete)\n+\t\tunlink_or_warn(git_path(\"logs/%s\", ref_to_delete->string));\n \tclear_loose_ref_cache(&ref_cache);\n \n cleanup:\n@@ -3833,7 +3835,7 @@ cleanup:\n \tfor (i = 0; i < n; i++)\n \t\tif (updates[i]->lock)\n \t\t\tunlock_ref(updates[i]->lock);\n-\tfree(delnames);\n+\tstring_list_clear(&refs_to_delete, 0);\n \treturn ret;\n }\n \ndiff --git a/refs.h b/refs.h\nindex 2bc3556..405c657 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -163,7 +163,15 @@ extern void rollback_packed_refs(void);\n  */\n int pack_refs(unsigned int flags);\n \n-extern int repack_without_refs(const char **refnames, int n,\n+/*\n+ * Rewrite the packed-refs file, omitting any refs listed in\n+ * 'refnames'. On error, packed-refs will be unchanged, the return\n+ * value is nonzero, and a message about the error is written to the\n+ * 'err' strbuf.\n+ *\n+ * The refs in 'refnames' needn't be sorted. `err` must not be NULL.\n+ */\n+extern int repack_without_refs(struct string_list *refnames,\n \t\t\t       struct strbuf *err);\n \n extern int ref_exists(const char *);\n-- \n2.1.3\n"},{"id":"252504","messageId":"1416902555-10748-6-git-send-email-mhagger@alum.mit.edu","threadId":"38042","inReplyTo":"1416902555-10748-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH v2 5/7] prune_remote(): rename local variable","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2014-11-25T08:02:33Z","receivedAt":"2014-11-25T08:02:33Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"Rename \"delete_refs_list\" to \"refs_to_prune\". The new name is more\nself-explanatory.\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\nReviewed-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n builtin/remote.c | 12 ++++++------\n 1 file changed, 6 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex 63a6709..efbf5fb 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -1311,7 +1311,7 @@ static int prune_remote(const char *remote, int dry_run)\n {\n \tint result = 0, i;\n \tstruct ref_states states;\n-\tstruct string_list delete_refs_list = STRING_LIST_INIT_NODUP;\n+\tstruct string_list refs_to_prune = STRING_LIST_INIT_NODUP;\n \tconst char *dangling_msg = dry_run\n \t\t? _(\" %s will become dangling!\")\n \t\t: _(\" %s has become dangling!\");\n@@ -1333,13 +1333,13 @@ static int prune_remote(const char *remote, int dry_run)\n \tfor (i = 0; i < states.stale.nr; i++) {\n \t\tconst char *refname = states.stale.items[i].util;\n \n-\t\tstring_list_append(&delete_refs_list, refname);\n+\t\tstring_list_append(&refs_to_prune, refname);\n \t}\n-\tsort_string_list(&delete_refs_list);\n+\tsort_string_list(&refs_to_prune);\n \n \tif (!dry_run) {\n \t\tstruct strbuf err = STRBUF_INIT;\n-\t\tif (repack_without_refs(&delete_refs_list, &err))\n+\t\tif (repack_without_refs(&refs_to_prune, &err))\n \t\t\tresult |= error(\"%s\", err.buf);\n \t\tstrbuf_release(&err);\n \t}\n@@ -1358,9 +1358,9 @@ static int prune_remote(const char *remote, int dry_run)\n \t\t\t       abbrev_ref(refname, \"refs/remotes/\"));\n \t}\n \n-\twarn_dangling_symrefs(stdout, dangling_msg, &delete_refs_list);\n+\twarn_dangling_symrefs(stdout, dangling_msg, &refs_to_prune);\n \n-\tstring_list_clear(&delete_refs_list, 0);\n+\tstring_list_clear(&refs_to_prune, 0);\n \tfree_remote_ref_states(&states);\n \treturn result;\n }\n-- \n2.1.3\n"},{"id":"252506","messageId":"1416902555-10748-7-git-send-email-mhagger@alum.mit.edu","threadId":"38042","inReplyTo":"1416902555-10748-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH v2 6/7] prune_remote(): iterate using for_each_string_list_item()","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2014-11-25T08:02:34Z","receivedAt":"2014-11-25T08:02:34Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"Iterate over refs_to_prune using for_each_string_list_item() rather\nthan writing out the loop in longhand.\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\nReviewed-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n builtin/remote.c | 14 ++++++--------\n 1 file changed, 6 insertions(+), 8 deletions(-)\n\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex efbf5fb..7fec170 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -1309,9 +1309,10 @@ static int set_head(int argc, const char **argv)\n \n static int prune_remote(const char *remote, int dry_run)\n {\n-\tint result = 0, i;\n+\tint result = 0;\n \tstruct ref_states states;\n \tstruct string_list refs_to_prune = STRING_LIST_INIT_NODUP;\n+\tstruct string_list_item *item;\n \tconst char *dangling_msg = dry_run\n \t\t? _(\" %s will become dangling!\")\n \t\t: _(\" %s has become dangling!\");\n@@ -1330,11 +1331,8 @@ static int prune_remote(const char *remote, int dry_run)\n \t\t  ? states.remote->url[0]\n \t\t  : _(\"(no URL)\"));\n \n-\tfor (i = 0; i < states.stale.nr; i++) {\n-\t\tconst char *refname = states.stale.items[i].util;\n-\n-\t\tstring_list_append(&refs_to_prune, refname);\n-\t}\n+\tfor_each_string_list_item(item, &states.stale)\n+\t\tstring_list_append(&refs_to_prune, item->util);\n \tsort_string_list(&refs_to_prune);\n \n \tif (!dry_run) {\n@@ -1344,8 +1342,8 @@ static int prune_remote(const char *remote, int dry_run)\n \t\tstrbuf_release(&err);\n \t}\n \n-\tfor (i = 0; i < states.stale.nr; i++) {\n-\t\tconst char *refname = states.stale.items[i].util;\n+\tfor_each_string_list_item(item, &states.stale) {\n+\t\tconst char *refname = item->util;\n \n \t\tif (!dry_run)\n \t\t\tresult |= delete_ref(refname, NULL, 0);\n-- \n2.1.3\n"},{"id":"252507","messageId":"1416902555-10748-8-git-send-email-mhagger@alum.mit.edu","threadId":"38042","inReplyTo":"1416902555-10748-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH v2 7/7] Rename sort_string_list() to string_list_sort()","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2014-11-25T08:02:35Z","receivedAt":"2014-11-25T08:02:35Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"The new name is more consistent with the names of other\nstring_list-related functions.\n\nSuggested-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n Documentation/technical/api-string-list.txt |  4 ++--\n builtin/apply.c                             |  2 +-\n builtin/receive-pack.c                      |  2 +-\n builtin/remote.c                            | 12 ++++++------\n builtin/repack.c                            |  2 +-\n connect.c                                   |  2 +-\n notes.c                                     |  2 +-\n remote.c                                    |  6 +++---\n sha1_file.c                                 |  2 +-\n string-list.c                               |  4 ++--\n string-list.h                               |  2 +-\n 11 files changed, 20 insertions(+), 20 deletions(-)\n\ndiff --git a/Documentation/technical/api-string-list.txt b/Documentation/technical/api-string-list.txt\nindex d51a657..c08402b 100644\n--- a/Documentation/technical/api-string-list.txt\n+++ b/Documentation/technical/api-string-list.txt\n@@ -29,7 +29,7 @@ member (you need this if you add things later) and you should set the\n   `unsorted_string_list_has_string` and get it from the list using\n   `string_list_lookup` for sorted lists.\n \n-. Can sort an unsorted list using `sort_string_list`.\n+. Can sort an unsorted list using `string_list_sort`.\n \n . Can remove duplicate items from a sorted list using\n   `string_list_remove_duplicates`.\n@@ -146,7 +146,7 @@ write `string_list_insert(...)->util = ...;`.\n \townership of a malloc()ed string to a `string_list` that has\n \t`strdup_string` set.\n \n-`sort_string_list`::\n+`string_list_sort`::\n \n \tSort the list's entries by string value in `strcmp()` order.\n \ndiff --git a/builtin/apply.c b/builtin/apply.c\nindex 6696ea4..22218f9 100644\n--- a/builtin/apply.c\n+++ b/builtin/apply.c\n@@ -4180,7 +4180,7 @@ static int write_out_results(struct patch *list)\n \tif (cpath.nr) {\n \t\tstruct string_list_item *item;\n \n-\t\tsort_string_list(&cpath);\n+\t\tstring_list_sort(&cpath);\n \t\tfor_each_string_list_item(item, &cpath)\n \t\t\tfprintf(stderr, \"U %s\\n\", item->string);\n \t\tstring_list_clear(&cpath, 0);\ndiff --git a/builtin/receive-pack.c b/builtin/receive-pack.c\nindex 32fc540..d7ce643 100644\n--- a/builtin/receive-pack.c\n+++ b/builtin/receive-pack.c\n@@ -964,7 +964,7 @@ static void check_aliased_updates(struct command *commands)\n \t\t\tstring_list_append(&ref_list, cmd->ref_name);\n \t\titem->util = (void *)cmd;\n \t}\n-\tsort_string_list(&ref_list);\n+\tstring_list_sort(&ref_list);\n \n \tfor (cmd = commands; cmd; cmd = cmd->next) {\n \t\tif (!cmd->error_string)\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex 7fec170..46ecfd9 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -352,9 +352,9 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat\n \tfree_refs(stale_refs);\n \tfree_refs(fetch_map);\n \n-\tsort_string_list(&states->new);\n-\tsort_string_list(&states->tracked);\n-\tsort_string_list(&states->stale);\n+\tstring_list_sort(&states->new);\n+\tstring_list_sort(&states->tracked);\n+\tstring_list_sort(&states->stale);\n \n \treturn 0;\n }\n@@ -909,7 +909,7 @@ static int get_remote_ref_states(const char *name,\n \t\t\tget_push_ref_states(remote_refs, states);\n \t} else {\n \t\tfor_each_ref(append_ref_to_tracked_list, states);\n-\t\tsort_string_list(&states->tracked);\n+\t\tstring_list_sort(&states->tracked);\n \t\tget_push_ref_states_noquery(states);\n \t}\n \n@@ -1128,7 +1128,7 @@ static int show_all(void)\n \tif (!result) {\n \t\tint i;\n \n-\t\tsort_string_list(&list);\n+\t\tstring_list_sort(&list);\n \t\tfor (i = 0; i < list.nr; i++) {\n \t\t\tstruct string_list_item *item = list.items + i;\n \t\t\tif (verbose)\n@@ -1333,7 +1333,7 @@ static int prune_remote(const char *remote, int dry_run)\n \n \tfor_each_string_list_item(item, &states.stale)\n \t\tstring_list_append(&refs_to_prune, item->util);\n-\tsort_string_list(&refs_to_prune);\n+\tstring_list_sort(&refs_to_prune);\n \n \tif (!dry_run) {\n \t\tstruct strbuf err = STRBUF_INIT;\ndiff --git a/builtin/repack.c b/builtin/repack.c\nindex 2845620..0705d68 100644\n--- a/builtin/repack.c\n+++ b/builtin/repack.c\n@@ -379,7 +379,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)\n \n \tif (delete_redundant) {\n \t\tint opts = 0;\n-\t\tsort_string_list(&names);\n+\t\tstring_list_sort(&names);\n \t\tfor_each_string_list_item(item, &existing_packs) {\n \t\t\tchar *sha1;\n \t\t\tsize_t len = strlen(item->string);\ndiff --git a/connect.c b/connect.c\nindex d47d0ec..16f74b0 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -93,7 +93,7 @@ static void annotate_refs_with_symref_info(struct ref *ref)\n \t\tparse_one_symref_info(&symref, val, len);\n \t\tfeature_list = val + 1;\n \t}\n-\tsort_string_list(&symref);\n+\tstring_list_sort(&symref);\n \n \tfor (; ref; ref = ref->next) {\n \t\tstruct string_list_item *item;\ndiff --git a/notes.c b/notes.c\nindex 5fe691d..40f4418 100644\n--- a/notes.c\n+++ b/notes.c\n@@ -902,7 +902,7 @@ int combine_notes_cat_sort_uniq(unsigned char *cur_sha1,\n \tif (string_list_add_note_lines(&sort_uniq_list, new_sha1))\n \t\tgoto out;\n \tstring_list_remove_empty_items(&sort_uniq_list, 0);\n-\tsort_string_list(&sort_uniq_list);\n+\tstring_list_sort(&sort_uniq_list);\n \tstring_list_remove_duplicates(&sort_uniq_list, 0);\n \n \t/* create a new blob object from sort_uniq_list */\ndiff --git a/remote.c b/remote.c\nindex f624217..ae4ecfa 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -1356,7 +1356,7 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds\n \t}\n \tclear_commit_marks_many(sent_tips.nr, sent_tips.tip, TMP_MARK);\n \n-\tsort_string_list(&dst_tag);\n+\tstring_list_sort(&dst_tag);\n \n \t/* Collect tags they do not have. */\n \tfor (ref = src; ref; ref = ref->next) {\n@@ -1421,7 +1421,7 @@ static void prepare_ref_index(struct string_list *ref_index, struct ref *ref)\n \tfor ( ; ref; ref = ref->next)\n \t\tstring_list_append_nodup(ref_index, ref->name)->util = ref;\n \n-\tsort_string_list(ref_index);\n+\tstring_list_sort(ref_index);\n }\n \n /*\n@@ -2135,7 +2135,7 @@ struct ref *get_stale_heads(struct refspec *refs, int ref_count, struct ref *fet\n \tinfo.ref_count = ref_count;\n \tfor (ref = fetch_map; ref; ref = ref->next)\n \t\tstring_list_append(&ref_names, ref->name);\n-\tsort_string_list(&ref_names);\n+\tstring_list_sort(&ref_names);\n \tfor_each_ref(get_stale_heads_cb, &info);\n \tstring_list_clear(&ref_names, 0);\n \treturn stale_refs;\ndiff --git a/sha1_file.c b/sha1_file.c\nindex d7f1838..30995e6 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1198,7 +1198,7 @@ static void report_pack_garbage(struct string_list *list)\n \tif (!report_garbage)\n \t\treturn;\n \n-\tsort_string_list(list);\n+\tstring_list_sort(list);\n \n \tfor (i = 0; i < list->nr; i++) {\n \t\tconst char *path = list->items[i].string;\ndiff --git a/string-list.c b/string-list.c\nindex c5aa076..2f69c32 100644\n--- a/string-list.c\n+++ b/string-list.c\n@@ -220,7 +220,7 @@ struct string_list_item *string_list_append(struct string_list *list,\n /* Yuck */\n static compare_strings_fn compare_for_qsort;\n \n-/* Only call this from inside sort_string_list! */\n+/* Only call this from inside string_list_sort! */\n static int cmp_items(const void *a, const void *b)\n {\n \tconst struct string_list_item *one = a;\n@@ -228,7 +228,7 @@ static int cmp_items(const void *a, const void *b)\n \treturn compare_for_qsort(one->string, two->string);\n }\n \n-void sort_string_list(struct string_list *list)\n+void string_list_sort(struct string_list *list)\n {\n \tcompare_for_qsort = list->cmp ? list->cmp : strcmp;\n \tqsort(list->items, list->nr, sizeof(*list->items), cmp_items);\ndiff --git a/string-list.h b/string-list.h\nindex 494eb5d..2cc5e48 100644\n--- a/string-list.h\n+++ b/string-list.h\n@@ -85,7 +85,7 @@ struct string_list_item *string_list_append(struct string_list *list, const char\n  */\n struct string_list_item *string_list_append_nodup(struct string_list *list, char *string);\n \n-void sort_string_list(struct string_list *list);\n+void string_list_sort(struct string_list *list);\n int unsorted_string_list_has_string(struct string_list *list, const char *string);\n struct string_list_item *unsorted_string_list_lookup(struct string_list *list,\n \t\t\t\t\t\t     const char *string);\n-- \n2.1.3\n"},{"id":"252531","messageId":"xmqq61e3tang.fsf@gitster.dls.corp.google.com","threadId":"38042","inReplyTo":"1416902555-10748-2-git-send-email-mhagger@alum.mit.edu","subject":"Re: [PATCH v2 1/7] prune_remote(): exit early if there are no stale references","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-11-25T18:09:23Z","receivedAt":"2014-11-25T18:09:23Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michael Haggerty <mhagger@alum.mit.edu> writes:\n\n> Aside from making the logic clearer, this avoids a call to\n> warn_dangling_symrefs(), which always does a for_each_rawref()\n> iteration.\n\nMakes sense.  Thanks.\n"},{"id":"252533","messageId":"xmqq1tortaaq.fsf@gitster.dls.corp.google.com","threadId":"38042","inReplyTo":"1416902555-10748-8-git-send-email-mhagger@alum.mit.edu","subject":"Re: [PATCH v2 7/7] Rename sort_string_list() to string_list_sort()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-11-25T18:17:01Z","receivedAt":"2014-11-25T18:17:01Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michael Haggerty <mhagger@alum.mit.edu> writes:\n\n> The new name is more consistent with the names of other\n> string_list-related functions.\n>\n> Suggested-by: Junio C Hamano <gitster@pobox.com>\n> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n> ---\n\nThanks.  I do not think I deserve a credit, though ;-)\n\nLooking at string-list.h, I think this was one of the bigger wart.\nI think we should do the same for filter_string_list(), but let's\nworry about it outside this series.\n\nprint_string_list() is probably not useful in general use (who uses\nit???) in the first place, so I do not care too much about it ;-)\n"},{"id":"252559","messageId":"CAGZ79kan-SetY=ZM=t69pE3JAL3PaZ9c5x0oDbq9QqU1JfPOug@mail.gmail.com","threadId":"38042","inReplyTo":"1416902555-10748-1-git-send-email-mhagger@alum.mit.edu","subject":"Re: [PATCH v2 0/7] repack_without_refs(): convert to string_list","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2014-11-26T01:15:36Z","receivedAt":"2014-11-26T01:15:36Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Tue, Nov 25, 2014 at 12:02 AM, Michael Haggerty <mhagger@alum.mit.edu> wrote:\n> This is a re-roll of v1 [1] with the following changes:\n>\n> * Fix some nits in the commit message and comment change in patch 4/7\n>   that were pointed out by Jonathan.\n>\n> * Add a new patch 7/7 that renames sort_string_list() to\n>   string_list_sort() as suggested by Junio.\n>\n> I would have submitted the name change as a separate patch, but since\n> this patch series uses the function the two series would have\n> conflicted. Since I didn't see any other patch series in-flight that\n> use sort_string_list(), I just renamed the function everywhere rather\n> than going to the trouble of deprecating the old function and adding\n> the new function.\n>\n> Thanks to Junio, Jonathan, and Stefan for their reviews of v1.\n\nThis series is also\nReviewed-By: Stefan Beller <sbeller@google.com>\n\nAs this is in conflict with origin/sb/simplify-repack-without-refs\nwe'd need to decide, which we'd take. I'd gladly go with this series as it seems\ncleaner and easier to read.\n\n>\n> [1] http://thread.gmane.org/gmane.comp.version-control.git/259831/focus=260030\n>\n> Michael Haggerty (7):\n>   prune_remote(): exit early if there are no stale references\n>   prune_remote(): initialize both delete_refs lists in a single loop\n>   prune_remote(): sort delete_refs_list references en masse\n>   repack_without_refs(): make the refnames argument a string_list\n>   prune_remote(): rename local variable\n>   prune_remote(): iterate using for_each_string_list_item()\n>   Rename sort_string_list() to string_list_sort()\n>\n>  Documentation/technical/api-string-list.txt |  4 +-\n>  builtin/apply.c                             |  2 +-\n>  builtin/receive-pack.c                      |  2 +-\n>  builtin/remote.c                            | 69 +++++++++++++----------------\n>  builtin/repack.c                            |  2 +-\n>  connect.c                                   |  2 +-\n>  notes.c                                     |  2 +-\n>  refs.c                                      | 38 ++++++++--------\n>  refs.h                                      | 10 ++++-\n>  remote.c                                    |  6 +--\n>  sha1_file.c                                 |  2 +-\n>  string-list.c                               |  4 +-\n>  string-list.h                               |  2 +-\n>  13 files changed, 75 insertions(+), 70 deletions(-)\n>\n> --\n> 2.1.3\n>\n"},{"id":"252585","messageId":"xmqqtx1lrgn6.fsf@gitster.dls.corp.google.com","threadId":"38042","inReplyTo":"CAGZ79kan-SetY=ZM=t69pE3JAL3PaZ9c5x0oDbq9QqU1JfPOug@mail.gmail.com","subject":"Re: [PATCH v2 0/7] repack_without_refs(): convert to string_list","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-11-26T17:55:09Z","receivedAt":"2014-11-26T17:55:09Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Stefan Beller <sbeller@google.com> writes:\n\n> As this is in conflict with origin/sb/simplify-repack-without-refs\n> we'd need to decide, which we'd take. I'd gladly go with this series as it seems\n> cleaner and easier to read.\n\nI'll drop sb/simlify-repack-without-refs and replace it with this\nseries (naturally called mh/simlify-repack-without-refs ;-).\n\nThanks, all.\n"}]}