{"thread":{"id":"43023","subject":"[PATCH] use strbuf_add_unique_abbrev() for adding short hashes","startedAt":"2016-08-06T22:03:51Z","lastAt":"2016-08-07T23:14:19Z","messageCount":3,"participants":["René Scharfe","Johannes Schindelin","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"293305","messageId":"57A6050D.50200@web.de","threadId":"43023","inReplyTo":null,"subject":"[PATCH] use strbuf_add_unique_abbrev() for adding short hashes","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2016-08-06T15:41:01Z","receivedAt":"2016-08-06T22:03:51Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Call strbuf_add_unique_abbrev() to add abbreviated hashes to strbufs\ninstead of taking detours through find_unique_abbrev() and its static\nbuffer.  This is shorter and a bit more efficient.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n builtin/checkout.c |  3 +--\n pretty.c           | 13 ++++++-------\n transport.c        | 11 ++++-------\n 3 files changed, 11 insertions(+), 16 deletions(-)\n\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex 27c1a05..0a7d24c 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -703,8 +703,7 @@ static int add_pending_uninteresting_ref(const char *refname,\n static void describe_one_orphan(struct strbuf *sb, struct commit *commit)\n {\n \tstrbuf_addstr(sb, \"  \");\n-\tstrbuf_addstr(sb,\n-\t\tfind_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV));\n+\tstrbuf_add_unique_abbrev(sb, commit->object.oid.hash, DEFAULT_ABBREV);\n \tstrbuf_addch(sb, ' ');\n \tif (!parse_commit(commit))\n \t\tpp_commit_easy(CMIT_FMT_ONELINE, commit, sb);\ndiff --git a/pretty.c b/pretty.c\nindex 9fa42c2..9609afb 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -1143,8 +1143,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */\n \t\t\tstrbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_RESET));\n \t\t\treturn 1;\n \t\t}\n-\t\tstrbuf_addstr(sb, find_unique_abbrev(commit->object.oid.hash,\n-\t\t\t\t\t\t     c->pretty_ctx->abbrev));\n+\t\tstrbuf_add_unique_abbrev(sb, commit->object.oid.hash,\n+\t\t\t\t\t c->pretty_ctx->abbrev);\n \t\tstrbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_RESET));\n \t\tc->abbrev_commit_hash.len = sb->len - c->abbrev_commit_hash.off;\n \t\treturn 1;\n@@ -1154,8 +1154,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */\n \tcase 't':\t\t/* abbreviated tree hash */\n \t\tif (add_again(sb, &c->abbrev_tree_hash))\n \t\t\treturn 1;\n-\t\tstrbuf_addstr(sb, find_unique_abbrev(commit->tree->object.oid.hash,\n-\t\t\t\t\t\t     c->pretty_ctx->abbrev));\n+\t\tstrbuf_add_unique_abbrev(sb, commit->tree->object.oid.hash,\n+\t\t\t\t\t c->pretty_ctx->abbrev);\n \t\tc->abbrev_tree_hash.len = sb->len - c->abbrev_tree_hash.off;\n \t\treturn 1;\n \tcase 'P':\t\t/* parent hashes */\n@@ -1171,9 +1171,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */\n \t\tfor (p = commit->parents; p; p = p->next) {\n \t\t\tif (p != commit->parents)\n \t\t\t\tstrbuf_addch(sb, ' ');\n-\t\t\tstrbuf_addstr(sb, find_unique_abbrev(\n-\t\t\t\t\tp->item->object.oid.hash,\n-\t\t\t\t\tc->pretty_ctx->abbrev));\n+\t\t\tstrbuf_add_unique_abbrev(sb, p->item->object.oid.hash,\n+\t\t\t\t\t\t c->pretty_ctx->abbrev);\n \t\t}\n \t\tc->abbrev_parent_hashes.len = sb->len -\n \t\t                              c->abbrev_parent_hashes.off;\ndiff --git a/transport.c b/transport.c\nindex 4ba48b0..557f399 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -321,11 +321,6 @@ static void print_ref_status(char flag, const char *summary, struct ref *to, str\n \t}\n }\n \n-static const char *status_abbrev(unsigned char sha1[20])\n-{\n-\treturn find_unique_abbrev(sha1, DEFAULT_ABBREV);\n-}\n-\n static void print_ok_ref_status(struct ref *ref, int porcelain)\n {\n \tif (ref->deletion)\n@@ -340,7 +335,8 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)\n \t\tchar type;\n \t\tconst char *msg;\n \n-\t\tstrbuf_addstr(&quickref, status_abbrev(ref->old_oid.hash));\n+\t\tstrbuf_add_unique_abbrev(&quickref, ref->old_oid.hash,\n+\t\t\t\t\t DEFAULT_ABBREV);\n \t\tif (ref->forced_update) {\n \t\t\tstrbuf_addstr(&quickref, \"...\");\n \t\t\ttype = '+';\n@@ -350,7 +346,8 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)\n \t\t\ttype = ' ';\n \t\t\tmsg = NULL;\n \t\t}\n-\t\tstrbuf_addstr(&quickref, status_abbrev(ref->new_oid.hash));\n+\t\tstrbuf_add_unique_abbrev(&quickref, ref->new_oid.hash,\n+\t\t\t\t\t DEFAULT_ABBREV);\n \n \t\tprint_ref_status(type, quickref.buf, ref, ref->peer_ref, msg, porcelain);\n \t\tstrbuf_release(&quickref);\n-- \n2.9.2\n\n"},{"id":"293318","messageId":"alpine.DEB.2.20.1608071051540.5786@virtualbox","threadId":"43023","inReplyTo":"57A6050D.50200@web.de","subject":"Re: [PATCH] use strbuf_add_unique_abbrev() for adding short hashes","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2016-08-07T08:53:34Z","receivedAt":"2016-08-07T08:53:54Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi René,\n\nOn Sat, 6 Aug 2016, René Scharfe wrote:\n\n> Call strbuf_add_unique_abbrev() to add abbreviated hashes to strbufs\n> instead of taking detours through find_unique_abbrev() and its static\n> buffer.  This is shorter and a bit more efficient.\n\nAnd less error-prone.\n\nIt is also a thing I need to change in my upcoming rebase--helper patches:\nI had not known about this function.\n\nThank you,\nDscho"},{"id":"293330","messageId":"20160807231410.7cwclya7yykcg2cy@sigill.intra.peff.net","threadId":"43023","inReplyTo":"alpine.DEB.2.20.1608071051540.5786@virtualbox","subject":"Re: [PATCH] use strbuf_add_unique_abbrev() for adding short hashes","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-08-07T23:14:11Z","receivedAt":"2016-08-07T23:14:19Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Aug 07, 2016 at 10:53:34AM +0200, Johannes Schindelin wrote:\n\n> On Sat, 6 Aug 2016, René Scharfe wrote:\n> \n> > Call strbuf_add_unique_abbrev() to add abbreviated hashes to strbufs\n> > instead of taking detours through find_unique_abbrev() and its static\n> > buffer.  This is shorter and a bit more efficient.\n> \n> And less error-prone.\n> \n> It is also a thing I need to change in my upcoming rebase--helper patches:\n> I had not known about this function.\n\nGreat. I added it several months ago to avoid some hairy allocation\ncode, so I am glad to see it finding new uses (both this patch and\npotential new ones).\n\n-Peff\n"}]}