From: Junio C Hamano Date: Fri, 17 Mar 2017 20:50:24 +0000 (-0700) Subject: Merge branch 'bc/object-id' X-Git-Tag: v2.13.0-rc0~108 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e1fae930193b3e8ff02cee936605625f63e1d1e4;p=thirdparty%2Fgit.git Merge branch 'bc/object-id' "uchar [40]" to "struct object_id" conversion continues. * bc/object-id: wt-status: convert to struct object_id builtin/merge-base: convert to struct object_id Convert object iteration callbacks to struct object_id sha1_file: introduce an nth_packed_object_oid function refs: simplify parsing of reflog entries refs: convert each_reflog_ent_fn to struct object_id reflog-walk: convert struct reflog_info to struct object_id builtin/replace: convert to struct object_id Convert remaining callers of resolve_refdup to object_id builtin/merge: convert to struct object_id builtin/clone: convert to struct object_id builtin/branch: convert to struct object_id builtin/grep: convert to struct object_id builtin/fmt-merge-message: convert to struct object_id builtin/fast-export: convert to struct object_id builtin/describe: convert to struct object_id builtin/diff-tree: convert to struct object_id builtin/commit: convert to struct object_id hex: introduce parse_oid_hex --- e1fae930193b3e8ff02cee936605625f63e1d1e4 diff --cc builtin/branch.c index 5d44e36cba,faf472ff8f..52688f2e1b --- a/builtin/branch.c +++ b/builtin/branch.c @@@ -255,7 -251,7 +255,7 @@@ static int delete_branches(int argc, co goto next; } - if (delete_ref(NULL, name, is_null_sha1(sha1) ? NULL : sha1, - if (delete_ref(name, is_null_oid(&oid) ? NULL : oid.hash, ++ if (delete_ref(NULL, name, is_null_oid(&oid) ? NULL : oid.hash, REF_NODEREF)) { error(remote_branch ? _("Error deleting remote-tracking branch '%s'") diff --cc builtin/grep.c index 9304c33e75,0393b0fdc4..837836fb3e --- a/builtin/grep.c +++ b/builtin/grep.c @@@ -1150,69 -1149,26 +1150,69 @@@ int cmd_grep(int argc, const char **arg compile_grep_patterns(&opt); - /* Check revs and then paths */ + /* + * We have to find "--" in a separate pass, because its presence + * influences how we will parse arguments that come before it. + */ + for (i = 0; i < argc; i++) { + if (!strcmp(argv[i], "--")) { + seen_dashdash = 1; + break; + } + } + + /* + * Resolve any rev arguments. If we have a dashdash, then everything up + * to it must resolve as a rev. If not, then we stop at the first + * non-rev and assume everything else is a path. + */ + allow_revs = use_index && !untracked; for (i = 0; i < argc; i++) { const char *arg = argv[i]; - unsigned char sha1[20]; + struct object_id oid; struct object_context oc; - /* Is it a rev? */ - if (!get_sha1_with_context(arg, 0, oid.hash, &oc)) { - struct object *object = parse_object_or_die(oid.hash, arg); - if (!seen_dashdash) - verify_non_filename(prefix, arg); - add_object_array_with_path(object, arg, &list, oc.mode, oc.path); - continue; - } + struct object *object; + if (!strcmp(arg, "--")) { i++; - seen_dashdash = 1; + break; } - break; + + if (!allow_revs) { + if (seen_dashdash) + die(_("--no-index or --untracked cannot be used with revs")); + break; + } + - if (get_sha1_with_context(arg, 0, sha1, &oc)) { ++ if (get_sha1_with_context(arg, 0, oid.hash, &oc)) { + if (seen_dashdash) + die(_("unable to resolve revision: %s"), arg); + break; + } + - object = parse_object_or_die(sha1, arg); ++ object = parse_object_or_die(oid.hash, arg); + if (!seen_dashdash) + verify_non_filename(prefix, arg); + add_object_array_with_path(object, arg, &list, oc.mode, oc.path); } + /* + * Anything left over is presumed to be a path. But in the non-dashdash + * "do what I mean" case, we verify and complain when that isn't true. + */ + if (!seen_dashdash) { + int j; + for (j = i; j < argc; j++) + verify_filename(prefix, argv[j], j == i && allow_revs); + } + + parse_pathspec(&pathspec, 0, + PATHSPEC_PREFER_CWD | + (opt.max_depth != -1 ? PATHSPEC_MAXDEPTH_VALID : 0), + prefix, argv + i); + pathspec.max_depth = opt.max_depth; + pathspec.recursive = 1; + #ifndef NO_PTHREADS if (list.nr || cached || show_in_pager) num_threads = 0; diff --cc builtin/merge.c index 848a298556,099cfab447..7554b8d412 --- a/builtin/merge.c +++ b/builtin/merge.c @@@ -438,10 -438,10 +438,10 @@@ static void merge_name(const char *remo char *found_ref; int len, early; - strbuf_branchname(&bname, remote); + strbuf_branchname(&bname, remote, 0); remote = bname.buf; - memset(branch_head, 0, sizeof(branch_head)); + oidclr(&branch_head); remote_head = get_merge_parent(remote); if (!remote_head) die(_("'%s' does not point to a commit"), remote); diff --cc builtin/replace.c index 226d0f9523,f7716a5472..f83e7b8fc1 --- a/builtin/replace.c +++ b/builtin/replace.c @@@ -119,9 -119,9 +119,9 @@@ static int for_each_replace_name(const } static int delete_replace_ref(const char *name, const char *ref, - const unsigned char *sha1) + const struct object_id *oid) { - if (delete_ref(NULL, ref, sha1, 0)) - if (delete_ref(ref, oid->hash, 0)) ++ if (delete_ref(NULL, ref, oid->hash, 0)) return 1; printf("Deleted replace ref '%s'\n", name); return 0; diff --cc cache.h index d3265cca12,724e905f7a..dc261f40dd --- a/cache.h +++ b/cache.h @@@ -1363,37 -1319,16 +1363,46 @@@ extern char *oid_to_hex_r(char *out, co extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */ extern char *oid_to_hex(const struct object_id *oid); /* same static buffer as sha1_to_hex */ + /* + * Parse a 40-character hexadecimal object ID starting from hex, updating the + * pointer specified by end when parsing stops. The resulting object ID is + * stored in oid. Returns 0 on success. Parsing will stop on the first NUL or + * other invalid character. end is only updated on success; otherwise, it is + * unmodified. + */ + extern int parse_oid_hex(const char *hex, struct object_id *oid, const char **end); + -extern int interpret_branch_name(const char *str, int len, struct strbuf *); +/* + * This reads short-hand syntax that not only evaluates to a commit + * object name, but also can act as if the end user spelled the name + * of the branch from the command line. + * + * - "@{-N}" finds the name of the Nth previous branch we were on, and + * places the name of the branch in the given buf and returns the + * number of characters parsed if successful. + * + * - "@{upstream}" finds the name of the other ref that + * is configured to merge with (missing defaults + * to the current branch), and places the name of the branch in the + * given buf and returns the number of characters parsed if + * successful. + * + * If the input is not of the accepted format, it returns a negative + * number to signal an error. + * + * If the input was ok but there are not N branch switches in the + * reflog, it returns 0. + * + * If "allowed" is non-zero, it is a treated as a bitfield of allowable + * expansions: local branches ("refs/heads/"), remote branches + * ("refs/remotes/"), or "HEAD". If no "allowed" bits are set, any expansion is + * allowed, even ones to refs outside of those namespaces. + */ +#define INTERPRET_BRANCH_LOCAL (1<<0) +#define INTERPRET_BRANCH_REMOTE (1<<1) +#define INTERPRET_BRANCH_HEAD (1<<2) +extern int interpret_branch_name(const char *str, int len, struct strbuf *, + unsigned allowed); extern int get_oid_mb(const char *str, struct object_id *oid); extern int validate_headref(const char *ref);