diff options
Diffstat (limited to 'sha1_name.c')
-rw-r--r-- | sha1_name.c | 59 |
1 files changed, 38 insertions, 21 deletions
diff --git a/sha1_name.c b/sha1_name.c index 90419efe10..0e5fe7f937 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -52,7 +52,7 @@ static void update_candidates(struct disambiguate_state *ds, const unsigned char } if (!ds->candidate_ok) { - /* discard the candidate; we know it does not satisify fn */ + /* discard the candidate; we know it does not satisfy fn */ hashcpy(ds->candidate, current); ds->candidate_checked = 0; return; @@ -241,7 +241,7 @@ static int disambiguate_committish_only(const unsigned char *sha1, void *cb_data return 0; /* We need to do this the hard way... */ - obj = deref_tag(lookup_object(sha1), NULL, 0); + obj = deref_tag(parse_object(sha1), NULL, 0); if (obj && obj->type == OBJ_COMMIT) return 1; return 0; @@ -445,20 +445,22 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1) "\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\""); + "running \"git config advice.objectNameWarning false\""); unsigned char tmp_sha1[20]; char *real_ref = NULL; int refs_found = 0; int at, reflog_len, nth_prior = 0; 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)); + if (warn_on_object_refname_ambiguity) { + 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); } - free(real_ref); return 0; } @@ -675,11 +677,13 @@ static int peel_onion(const char *name, int len, unsigned char *sha1) return -1; sp++; /* beginning of type name, or closing brace for empty */ - if (!strncmp(commit_type, sp, 6) && sp[6] == '}') + if (!prefixcmp(sp, "commit}")) expected_type = OBJ_COMMIT; - else if (!strncmp(tree_type, sp, 4) && sp[4] == '}') + else if (!prefixcmp(sp, "tag}")) + expected_type = OBJ_TAG; + else if (!prefixcmp(sp, "tree}")) expected_type = OBJ_TREE; - else if (!strncmp(blob_type, sp, 4) && sp[4] == '}') + else if (!prefixcmp(sp, "blob}")) expected_type = OBJ_BLOB; else if (!prefixcmp(sp, "object}")) expected_type = OBJ_ANY; @@ -1005,9 +1009,20 @@ int get_sha1_mb(const char *name, unsigned char *sha1) /* parse @something syntax, when 'something' is not {.*} */ static int interpret_empty_at(const char *name, int namelen, int len, struct strbuf *buf) { + const char *next; + if (len || name[1] == '{') return -1; + /* make sure it's a single @, or @@{.*}, not @foo */ + next = strchr(name + len + 1, '@'); + if (next && next[1] != '{') + return -1; + if (!next) + next = name + namelen; + if (next != name + 1) + return -1; + strbuf_reset(buf); strbuf_add(buf, "HEAD", 4); return 1; @@ -1021,7 +1036,7 @@ static int reinterpret(const char *name, int namelen, int len, struct strbuf *bu int ret; strbuf_add(buf, name + len, namelen - len); - ret = interpret_branch_name(buf->buf, &tmp); + ret = interpret_branch_name(buf->buf, buf->len, &tmp); /* that data was not interpreted, remove our cruft */ if (ret < 0) { strbuf_setlen(buf, used); @@ -1055,14 +1070,16 @@ static int reinterpret(const char *name, int namelen, int len, struct strbuf *bu * If the input was ok but there are not N branch switches in the * reflog, it returns 0. */ -int interpret_branch_name(const char *name, struct strbuf *buf) +int interpret_branch_name(const char *name, int namelen, struct strbuf *buf) { char *cp; struct branch *upstream; - int namelen = strlen(name); int len = interpret_nth_prior_checkout(name, buf); int tmp_len; + if (!namelen) + namelen = strlen(name); + if (!len) { return len; /* syntax Ok, not enough switches */ } else if (len > 0) { @@ -1115,7 +1132,7 @@ int interpret_branch_name(const char *name, struct strbuf *buf) int strbuf_branchname(struct strbuf *sb, const char *name) { int len = strlen(name); - int used = interpret_branch_name(name, sb); + int used = interpret_branch_name(name, len, sb); if (used == len) return 0; @@ -1145,13 +1162,13 @@ int get_sha1(const char *name, unsigned char *sha1) } /* - * Many callers know that the user meant to name a committish by + * Many callers know that the user meant to name a commit-ish by * syntactical positions where the object name appears. Calling this * function allows the machinery to disambiguate shorter-than-unique - * abbreviated object names between committish and others. + * abbreviated object names between commit-ish and others. * * Note that this does NOT error out when the named object is not a - * committish. It is merely to give a hint to the disambiguation + * commit-ish. It is merely to give a hint to the disambiguation * machinery. */ int get_sha1_committish(const char *name, unsigned char *sha1) @@ -1234,7 +1251,7 @@ static void diagnose_invalid_index_path(int stage, const char *filename) { struct stat st; - struct cache_entry *ce; + const struct cache_entry *ce; int pos; unsigned namelen = strlen(filename); unsigned fullnamelen; @@ -1328,7 +1345,7 @@ static int get_sha1_with_context_1(const char *name, */ if (name[0] == ':') { int stage = 0; - struct cache_entry *ce; + const struct cache_entry *ce; char *new_path = NULL; int pos; if (!only_to_die && namelen > 2 && name[1] == '/') { |