From: Junio C Hamano Date: Tue, 11 Jun 2013 20:31:23 +0000 (-0700) Subject: Merge branch 'fc/at-head' X-Git-Tag: v1.8.4-rc0~180 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bb1c8fbcc86b31a1e86a1f6cadcb82d67fab1dc0;p=thirdparty%2Fgit.git Merge branch 'fc/at-head' Instead of typing four capital letters "HEAD", you can say "@" instead. * fc/at-head: sha1_name: compare variable with constant, not constant with variable Add new @ shortcut for HEAD sha1_name: refactor reinterpret() sha1_name: check @{-N} errors sooner sha1_name: reorganize get_sha1_basic() sha1_name: don't waste cycles in the @-parsing loop sha1_name: remove unnecessary braces sha1_name: remove no-op tests: at-combinations: @{N} versus HEAD@{N} tests: at-combinations: increase coverage tests: at-combinations: improve nonsense() tests: at-combinations: check ref names directly tests: at-combinations: simplify setup --- bb1c8fbcc86b31a1e86a1f6cadcb82d67fab1dc0 diff --cc sha1_name.c index a695d16d8c,5a58720d85..90419efe10 --- a/sha1_name.c +++ b/sha1_name.c @@@ -435,31 -436,12 +436,31 @@@ static int interpret_nth_prior_checkout static int get_sha1_basic(const char *str, int len, unsigned char *sha1) { static const char *warn_msg = "refname '%.*s' is ambiguous."; + static const char *object_name_msg = N_( + "Git normally never creates a ref that ends with 40 hex characters\n" + "because it will be ignored when you just specify 40-hex. These refs\n" + "may be created by mistake. For example,\n" + "\n" + " git checkout -b $br $(git rev-parse ...)\n" + "\n" + "where \"$br\" is somehow empty and a 40-hex ref is created. Please\n" + "examine these refs and maybe delete them. Turn this message off by\n" + "running \"git config advice.object_name_warning false\""); + unsigned char tmp_sha1[20]; char *real_ref = NULL; int refs_found = 0; - int at, reflog_len; + int at, reflog_len, nth_prior = 0; - if (len == 40 && !get_sha1_hex(str, sha1)) + if (len == 40 && !get_sha1_hex(str, sha1)) { + refs_found = dwim_ref(str, len, tmp_sha1, &real_ref); + if (refs_found > 0 && warn_ambiguous_refs) { + warning(warn_msg, len, str); + if (advice_object_name_warning) + fprintf(stderr, "%s\n", _(object_name_msg)); + } + free(real_ref); return 0; + } /* basic@{time or number or -number} format to query ref-log */ reflog_len = at = 0;