From 249c8f4a164c8502f8274c505a48b9c686f458d0 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 2 Jul 2012 12:56:44 -0700 Subject: sha1_name.c: get rid of get_sha1_with_mode() There are only two callers, and they will benefit from being able to pass disambiguation hints to underlying get_sha1_with_context() API once it happens. Signed-off-by: Junio C Hamano --- revision.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'revision.c') diff --git a/revision.c b/revision.c index 064e351084..86a14c8af6 100644 --- a/revision.c +++ b/revision.c @@ -1097,7 +1097,7 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, int cant_be_filename) { - unsigned mode; + struct object_context oc; char *dotdot; struct object *object; unsigned char sha1[20]; @@ -1180,13 +1180,13 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, local_flags = UNINTERESTING; arg++; } - if (get_sha1_with_mode(arg, sha1, &mode)) + if (get_sha1_with_context(arg, sha1, &oc)) return revs->ignore_missing ? 0 : -1; if (!cant_be_filename) verify_non_filename(revs->prefix, arg); object = get_reference(revs, arg, sha1, flags ^ local_flags); add_rev_cmdline(revs, object, arg_, REV_CMD_REV, flags ^ local_flags); - add_pending_object_with_mode(revs, object, arg, mode); + add_pending_object_with_mode(revs, object, arg, oc.mode); return 0; } @@ -1794,11 +1794,11 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s if (revs->def && !revs->pending.nr && !got_rev_arg) { unsigned char sha1[20]; struct object *object; - unsigned mode; - if (get_sha1_with_mode(revs->def, sha1, &mode)) + struct object_context oc; + if (get_sha1_with_context(revs->def, sha1, &oc)) die("bad default revision '%s'", revs->def); object = get_reference(revs, revs->def, sha1, 0); - add_pending_object_with_mode(revs, object, revs->def, mode); + add_pending_object_with_mode(revs, object, revs->def, oc.mode); } /* Did the user ask for any diff output? Run the diff! */ -- cgit v1.2.1 From 33bd598c3902c40c5a10a68aeaa3004484239258 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 2 Jul 2012 10:32:11 -0700 Subject: sha1_name.c: teach lookup context to get_sha1_with_context() The function takes user input string and returns the object name (binary SHA-1) with mode bits and path when the object was looked up in a tree. Additionally give hints to help disambiguation of abbreviated object names when the caller knows what it is looking for. Signed-off-by: Junio C Hamano --- revision.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'revision.c') diff --git a/revision.c b/revision.c index 86a14c8af6..7444f2eaa1 100644 --- a/revision.c +++ b/revision.c @@ -1180,7 +1180,7 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, local_flags = UNINTERESTING; arg++; } - if (get_sha1_with_context(arg, sha1, &oc)) + if (get_sha1_with_context(arg, 0, sha1, &oc)) return revs->ignore_missing ? 0 : -1; if (!cant_be_filename) verify_non_filename(revs->prefix, arg); @@ -1795,7 +1795,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s unsigned char sha1[20]; struct object *object; struct object_context oc; - if (get_sha1_with_context(revs->def, sha1, &oc)) + if (get_sha1_with_context(revs->def, 0, sha1, &oc)) die("bad default revision '%s'", revs->def); object = get_reference(revs, revs->def, sha1, 0); add_pending_object_with_mode(revs, object, revs->def, oc.mode); -- cgit v1.2.1 From cd74e4733db3e2353077bdc7021caa70bed2a483 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 2 Jul 2012 12:04:52 -0700 Subject: sha1_name.c: introduce get_sha1_committish() Many callers know that the user meant to name a committish 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. 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 machinery. Signed-off-by: Junio C Hamano --- revision.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'revision.c') diff --git a/revision.c b/revision.c index 7444f2eaa1..c3160f2e6f 100644 --- a/revision.c +++ b/revision.c @@ -979,7 +979,7 @@ static int add_parents_only(struct rev_info *revs, const char *arg_, int flags) flags ^= UNINTERESTING; arg++; } - if (get_sha1(arg, sha1)) + if (get_sha1_committish(arg, sha1)) return 0; while (1) { it = get_reference(revs, arg, sha1, 0); @@ -1120,8 +1120,8 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, next = "HEAD"; if (dotdot == arg) this = "HEAD"; - if (!get_sha1(this, from_sha1) && - !get_sha1(next, sha1)) { + if (!get_sha1_committish(this, from_sha1) && + !get_sha1_committish(next, sha1)) { struct commit *a, *b; struct commit_list *exclude; -- cgit v1.2.1 From 8e676e8ba567eccee1510b90ec2e0364dcc2f3b4 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 2 Jul 2012 12:33:52 -0700 Subject: revision.c: allow handle_revision_arg() to take other flags The existing "cant_be_filename" that tells the function that the caller knows the arg is not a path (hence it does not have to be checked for absense of the file whose name matches it) is made into a bit in the flag word. Signed-off-by: Junio C Hamano --- revision.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'revision.c') diff --git a/revision.c b/revision.c index c3160f2e6f..929497f013 100644 --- a/revision.c +++ b/revision.c @@ -1093,9 +1093,7 @@ static void prepare_show_merge(struct rev_info *revs) revs->limited = 1; } -int handle_revision_arg(const char *arg_, struct rev_info *revs, - int flags, - int cant_be_filename) +int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsigned revarg_opt) { struct object_context oc; char *dotdot; @@ -1103,6 +1101,7 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, unsigned char sha1[20]; int local_flags; const char *arg = arg_; + int cant_be_filename = revarg_opt & REVARG_CANNOT_BE_FILENAME; dotdot = strstr(arg, ".."); if (dotdot) { @@ -1236,7 +1235,7 @@ static void read_revisions_from_stdin(struct rev_info *revs, } die("options not supported in --stdin mode"); } - if (handle_revision_arg(sb.buf, revs, 0, 1)) + if (handle_revision_arg(sb.buf, revs, 0, REVARG_CANNOT_BE_FILENAME)) die("bad revision '%s'", sb.buf); } if (seen_dashdash) @@ -1684,7 +1683,7 @@ static int handle_revision_pseudo_opt(const char *submodule, */ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct setup_revision_opt *opt) { - int i, flags, left, seen_dashdash, read_from_stdin, got_rev_arg = 0; + int i, flags, left, seen_dashdash, read_from_stdin, got_rev_arg = 0, revarg_opt; struct cmdline_pathspec prune_data; const char *submodule = NULL; @@ -1708,6 +1707,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s /* Second, deal with arguments and options */ flags = 0; + revarg_opt = seen_dashdash ? REVARG_CANNOT_BE_FILENAME : 0; read_from_stdin = 0; for (left = i = 1; i < argc; i++) { const char *arg = argv[i]; @@ -1743,7 +1743,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s continue; } - if (handle_revision_arg(arg, revs, flags, seen_dashdash)) { + + if (handle_revision_arg(arg, revs, flags, revarg_opt)) { int j; if (seen_dashdash || *arg == '^') die("bad revision '%s'", arg); -- cgit v1.2.1 From d5f6b1d756a29255efedee3cb6e8526aedcfeb00 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 2 Jul 2012 12:43:05 -0700 Subject: revision.c: the "log" family, except for "show", takes committish Add a field to setup_revision_opt structure and allow these callers to tell the setup_revisions command parsing machinery that short SHA1 it encounters are meant to name committish. This step does not go all the way to connect the setup_revisions() to sha1_name.c yet. Signed-off-by: Junio C Hamano --- revision.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'revision.c') diff --git a/revision.c b/revision.c index 929497f013..ec6f0c8936 100644 --- a/revision.c +++ b/revision.c @@ -1102,6 +1102,7 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi int local_flags; const char *arg = arg_; int cant_be_filename = revarg_opt & REVARG_CANNOT_BE_FILENAME; + unsigned get_sha1_flags = 0; dotdot = strstr(arg, ".."); if (dotdot) { @@ -1179,7 +1180,11 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi local_flags = UNINTERESTING; arg++; } - if (get_sha1_with_context(arg, 0, sha1, &oc)) + + if (revarg_opt & REVARG_COMMITTISH) + get_sha1_flags = GET_SHA1_COMMITTISH; + + if (get_sha1_with_context(arg, get_sha1_flags, sha1, &oc)) return revs->ignore_missing ? 0 : -1; if (!cant_be_filename) verify_non_filename(revs->prefix, arg); @@ -1707,7 +1712,9 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s /* Second, deal with arguments and options */ flags = 0; - revarg_opt = seen_dashdash ? REVARG_CANNOT_BE_FILENAME : 0; + revarg_opt = opt ? opt->revarg_opt : 0; + if (seen_dashdash) + revarg_opt |= REVARG_CANNOT_BE_FILENAME; read_from_stdin = 0; for (left = i = 1; i < argc; i++) { const char *arg = argv[i]; -- cgit v1.2.1