git-log: match rev-list --abbrev and --abbrev-commit
Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Apr 7, 2006 at 22:34 UTC
f0853837d6ee69dccfa59222a0e869de94bdddc6
1 file changed
+13
-2
git.c
+13
-2
@@ -283,6 +283,7 @@ static int cmd_log(int argc, const char **argv, char **envp)
283
char *buf = xmalloc(LOGSIZE);
284
static enum cmit_fmt commit_format = CMIT_FMT_DEFAULT;
285
int abbrev = DEFAULT_ABBREV;
286
+ int abbrev_commit = 0;
287
const char *commit_prefix = "commit ";
288
289
argc = setup_revisions(argc, argv, &rev, "HEAD");
@@ -296,6 +297,12 @@ static int cmd_log(int argc, const char **argv, char **envp)
297
else if (!strcmp(arg, "--no-abbrev")) {
298
abbrev = 0;
299
}
300
+ else if (!strcmp(arg, "--abbrev")) {
301
+ abbrev = DEFAULT_ABBREV;
302
+ }
303
+ else if (!strcmp(arg, "--abbrev-commit")) {
304
+ abbrev_commit = 1;
305
+ }
306
else if (!strncmp(arg, "--abbrev=", 9)) {
307
abbrev = strtoul(arg + 9, NULL, 10);
308
if (abbrev && abbrev < MINIMUM_ABBREV)
@@ -311,8 +318,12 @@ static int cmd_log(int argc, const char **argv, char **envp)
318
prepare_revision_walk(&rev);
319
setup_pager();
320
while ((commit = get_revision(&rev)) != NULL) {
314
- printf("%s%s", commit_prefix,
315
- sha1_to_hex(commit->object.sha1));
321
+ fputs(commit_prefix, stdout);
322
+ if (abbrev_commit && abbrev)
323
+ fputs(find_unique_abbrev(commit->object.sha1, abbrev),
324
+ stdout);
325
+ else
326
+ fputs(sha1_to_hex(commit->object.sha1), stdout);
327
if (rev.parents) {
328
struct commit_list *parents = commit->parents;
329
while (parents) {