@matheusbsbs / matheus-bagliano / commits / 4c34a2c555
Fork 0

git-describe: default to HEAD

This is based on the patch by Andreas Ericsson, but done slightly differently, preferring to have separate loops -- one for options and then arguments. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Jan 11, 2006 at 13:57 UTC 4c34a2c555f8064d45e655e45fd40d7e2b203d6e
1 file changed +22 -16
describe.c
+22 -16
@@ -98,12 +98,20 @@ static int compare_names(const void *_a, const void *_b)
98 return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
99 }
100
101 -static void describe(struct commit *cmit)
101 +static void describe(char *arg)
102 {
103 + unsigned char sha1[20];
104 + struct commit *cmit;
105 struct commit_list *list;
106 static int initialized = 0;
107 struct commit_name *n;
108
109 + if (get_sha1(arg, sha1) < 0)
110 + usage(describe_usage);
111 + cmit = lookup_commit_reference(sha1);
112 + if (!cmit)
113 + usage(describe_usage);
114 +
115 if (!initialized) {
116 initialized = 1;
117 for_each_ref(get_name);
@@ -136,29 +144,27 @@ int main(int argc, char **argv)
144
145 for (i = 1; i < argc; i++) {
146 const char *arg = argv[i];
139 - unsigned char sha1[20];
140 - struct commit *cmit;
147
142 - if (!strcmp(arg, "--all")) {
148 + if (*arg != '-')
149 + break;
150 + else if (!strcmp(arg, "--all"))
151 all = 1;
144 - continue;
145 - }
146 - if (!strcmp(arg, "--tags")) {
152 + else if (!strcmp(arg, "--tags"))
153 tags = 1;
148 - continue;
149 - }
150 - if (!strncmp(arg, "--abbrev=", 9)) {
154 + else if (!strncmp(arg, "--abbrev=", 9)) {
155 abbrev = strtoul(arg + 9, NULL, 10);
156 if (abbrev < 4 || 40 <= abbrev)
157 abbrev = DEFAULT_ABBREV;
154 - continue;
158 }
156 - if (get_sha1(arg, sha1) < 0)
157 - usage(describe_usage);
158 - cmit = lookup_commit_reference(sha1);
159 - if (!cmit)
159 + else
160 usage(describe_usage);
161 - describe(cmit);
161 }
162 +
163 + if (i == argc)
164 + describe("HEAD");
165 + else
166 + while (i < argc)
167 + describe(argv[i++]);
168 +
169 return 0;
170 }