diff options
Diffstat (limited to 'sha1_name.c')
-rw-r--r-- | sha1_name.c | 117 |
1 files changed, 19 insertions, 98 deletions
diff --git a/sha1_name.c b/sha1_name.c index ff5992acc9..5d81ea0564 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -241,91 +241,6 @@ static int ambiguous_path(const char *path, int len) return slash; } -/* - * *string and *len will only be substituted, and *string returned (for - * later free()ing) if the string passed in is a magic short-hand form - * to name a branch. - */ -static char *substitute_branch_name(const char **string, int *len) -{ - struct strbuf buf = STRBUF_INIT; - int ret = interpret_branch_name(*string, &buf); - - if (ret == *len) { - size_t size; - *string = strbuf_detach(&buf, &size); - *len = size; - return (char *)*string; - } - - return NULL; -} - -int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref) -{ - char *last_branch = substitute_branch_name(&str, &len); - const char **p, *r; - int refs_found = 0; - - *ref = NULL; - for (p = ref_rev_parse_rules; *p; p++) { - char fullref[PATH_MAX]; - unsigned char sha1_from_ref[20]; - unsigned char *this_result; - int flag; - - this_result = refs_found ? sha1_from_ref : sha1; - mksnpath(fullref, sizeof(fullref), *p, len, str); - r = resolve_ref(fullref, this_result, 1, &flag); - if (r) { - if (!refs_found++) - *ref = xstrdup(r); - if (!warn_ambiguous_refs) - break; - } else if ((flag & REF_ISSYMREF) && strcmp(fullref, "HEAD")) - warning("ignoring dangling symref %s.", fullref); - } - free(last_branch); - return refs_found; -} - -int dwim_log(const char *str, int len, unsigned char *sha1, char **log) -{ - char *last_branch = substitute_branch_name(&str, &len); - const char **p; - int logs_found = 0; - - *log = NULL; - for (p = ref_rev_parse_rules; *p; p++) { - struct stat st; - unsigned char hash[20]; - char path[PATH_MAX]; - const char *ref, *it; - - mksnpath(path, sizeof(path), *p, len, str); - ref = resolve_ref(path, hash, 1, NULL); - if (!ref) - continue; - if (!stat(git_path("logs/%s", path), &st) && - S_ISREG(st.st_mode)) - it = path; - else if (strcmp(ref, path) && - !stat(git_path("logs/%s", ref), &st) && - S_ISREG(st.st_mode)) - it = ref; - else - continue; - if (!logs_found++) { - *log = xstrdup(it); - hashcpy(sha1, hash); - } - if (!warn_ambiguous_refs) - break; - } - free(last_branch); - return logs_found; -} - static inline int upstream_mark(const char *string, int len) { const char *suffix[] = { "@{upstream}", "@{u}" }; @@ -501,12 +416,6 @@ struct object *peel_to_type(const char *name, int namelen, { if (name && !namelen) namelen = strlen(name); - if (!o) { - unsigned char sha1[20]; - if (get_sha1_1(name, namelen, sha1)) - return NULL; - o = parse_object(sha1); - } while (1) { if (!o || (!o->parsed && !parse_object(o->sha1))) return NULL; @@ -947,10 +856,22 @@ int interpret_branch_name(const char *name, struct strbuf *buf) len = cp + tmp_len - name; cp = xstrndup(name, cp - name); upstream = branch_get(*cp ? cp : NULL); - if (!upstream - || !upstream->merge - || !upstream->merge[0]->dst) - return error("No upstream branch found for '%s'", cp); + /* + * Upstream can be NULL only if cp refers to HEAD and HEAD + * points to something different than a branch. + */ + if (!upstream) + return error(_("HEAD does not point to a branch")); + if (!upstream->merge || !upstream->merge[0]->dst) { + if (!ref_exists(upstream->refname)) + return error(_("No such branch: '%s'"), cp); + if (!upstream->merge) + return error(_("No upstream configured for branch '%s'"), + upstream->name); + return error( + _("Upstream branch '%s' not stored as a remote-tracking branch"), + upstream->merge[0]->src); + } free(cp); cp = shorten_unambiguous_ref(upstream->merge[0]->dst, 0); strbuf_reset(buf); @@ -972,9 +893,9 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name) { strbuf_branchname(sb, name); if (name[0] == '-') - return CHECK_REF_FORMAT_ERROR; + return -1; strbuf_splice(sb, 0, 0, "refs/heads/", 11); - return check_ref_format(sb->buf); + return check_refname_format(sb->buf, 0); } /* @@ -1206,7 +1127,7 @@ int get_sha1_with_context_1(const char *name, unsigned char *sha1, if (new_filename) filename = new_filename; ret = get_tree_entry(tree_sha1, filename, sha1, &oc->mode); - if (only_to_die) { + if (ret && only_to_die) { diagnose_invalid_sha1_path(prefix, filename, tree_sha1, object_name); free(object_name); |