Skip to content

Commit fb423da

Browse files
René Scharfegitster
authored andcommitted
describe: load refnames before calling describe()
Get rid of the static variable that was used to prevent loading all the refnames multiple times by moving that code out of describe(), simply making sure it is only run once that way. Also change the error message that is shown in case no refnames are found to not include a hash any more, as the error condition is not specific to any particular revision. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bcc9b74 commit fb423da

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

builtin-describe.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ static void describe(const char *arg, int last_one)
180180
unsigned char sha1[20];
181181
struct commit *cmit, *gave_up_on = NULL;
182182
struct commit_list *list;
183-
static int initialized = 0;
184183
struct commit_name *n;
185184
struct possible_tag all_matches[MAX_TAGS];
186185
unsigned int match_cnt = 0, annotated_cnt = 0, cur_match;
@@ -192,14 +191,6 @@ static void describe(const char *arg, int last_one)
192191
if (!cmit)
193192
die("%s is not a valid '%s' object", arg, commit_type);
194193

195-
if (!initialized) {
196-
initialized = 1;
197-
for_each_ref(get_name, NULL);
198-
}
199-
200-
if (!found_names)
201-
die("cannot describe '%s'", sha1_to_hex(sha1));
202-
203194
n = cmit->util;
204195
if (n) {
205196
/*
@@ -359,6 +350,10 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
359350
return cmd_name_rev(i + argc, args, prefix);
360351
}
361352

353+
for_each_ref(get_name, NULL);
354+
if (!found_names)
355+
die("No names found, cannot describe anything.");
356+
362357
if (argc == 0) {
363358
describe("HEAD", 1);
364359
} else {

0 commit comments

Comments
 (0)