@matheusbsbs / matheus-bagliano / commits / a6d97d49e2
Fork 0

git-rev-parse --symbolic-full-name

The plumbing level can understand that the user meant "refs/heads/master" when the user says "master" or "heads/master", but there is no easy way for the scripts to figure it out without duplicating the dwim_ref() logic. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jan 5, 2008 at 12:09 UTC a6d97d49e23382027efff8a8e90e69e0572620c6
2 files changed +41 -3
Documentation/git-rev-parse.txt
+7
@@ -70,6 +70,13 @@ OPTIONS
70 possible '{caret}' prefix); this option makes them output in a
71 form as close to the original input as possible.
72
73 +--symbolic-full-name::
74 + This is similar to \--symbolic, but it omits input that
75 + are not refs (i.e. branch or tag names; or more
76 + explicitly disambiguating "heads/master" form, when you
77 + want to name the "master" branch when there is an
78 + unfortunately named tag "master"), and show them as full
79 + refnames (e.g. "refs/heads/master").
80
81 --all::
82 Show all refs found in `$GIT_DIR/refs`.
builtin-rev-parse.c
+34 -3
@@ -21,6 +21,9 @@ static const char *def;
21 #define NORMAL 0
22 #define REVERSED 1
23 static int show_type = NORMAL;
24 +
25 +#define SHOW_SYMBOLIC_ASIS 1
26 +#define SHOW_SYMBOLIC_FULL 2
27 static int symbolic;
28 static int abbrev;
29 static int output_sq;
@@ -103,8 +106,32 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)
106
107 if (type != show_type)
108 putchar('^');
106 - if (symbolic && name)
107 - show(name);
109 + if (symbolic && name) {
110 + if (symbolic == SHOW_SYMBOLIC_FULL) {
111 + unsigned char discard[20];
112 + char *full;
113 +
114 + switch (dwim_ref(name, strlen(name), discard, &full)) {
115 + case 0:
116 + /*
117 + * Not found -- not a ref. We could
118 + * emit "name" here, but symbolic-full
119 + * users are interested in finding the
120 + * refs spelled in full, and they would
121 + * need to filter non-refs if we did so.
122 + */
123 + break;
124 + case 1: /* happy */
125 + show(full);
126 + break;
127 + default: /* ambiguous */
128 + error("refname '%s' is ambiguous", name);
129 + break;
130 + }
131 + } else {
132 + show(name);
133 + }
134 + }
135 else if (abbrev)
136 show(find_unique_abbrev(sha1, abbrev));
137 else
@@ -421,7 +448,11 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
448 continue;
449 }
450 if (!strcmp(arg, "--symbolic")) {
424 - symbolic = 1;
451 + symbolic = SHOW_SYMBOLIC_ASIS;
452 + continue;
453 + }
454 + if (!strcmp(arg, "--symbolic-full-name")) {
455 + symbolic = SHOW_SYMBOLIC_FULL;
456 continue;
457 }
458 if (!strcmp(arg, "--all")) {