Skip to content

Commit 52b70d5

Browse files
author
Junio C Hamano
committed
git log [diff-tree options]...
And this makes "git log" to take common diff-tree options, so that it can be used as "git whatchanged". The recent revision walker updates by Linus to make path limiting low-latency helps this quite a bit. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 5f1c3f0 commit 52b70d5

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

git.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "cache.h"
1717
#include "commit.h"
1818
#include "revision.h"
19+
#include "diff.h"
20+
#include "log-tree.h"
1921

2022
#ifndef PATH_MAX
2123
# define PATH_MAX 4096
@@ -285,7 +287,10 @@ static int cmd_log(int argc, const char **argv, char **envp)
285287
int abbrev = DEFAULT_ABBREV;
286288
int abbrev_commit = 0;
287289
const char *commit_prefix = "commit ";
290+
struct log_tree_opt opt;
291+
int do_diff = 0;
288292

293+
init_log_tree_opt(&opt);
289294
argc = setup_revisions(argc, argv, &rev, "HEAD");
290295
while (1 < argc) {
291296
const char *arg = argv[1];
@@ -310,10 +315,32 @@ static int cmd_log(int argc, const char **argv, char **envp)
310315
else if (40 < abbrev)
311316
abbrev = 40;
312317
}
313-
else
318+
else {
319+
int cnt = log_tree_opt_parse(&opt, argv+1, argc-1);
320+
if (0 < cnt) {
321+
do_diff = 1;
322+
argv += cnt;
323+
argc -= cnt;
324+
continue;
325+
}
314326
die("unrecognized argument: %s", arg);
327+
}
328+
315329
argc--; argv++;
316330
}
331+
if (do_diff) {
332+
opt.diffopt.abbrev = abbrev;
333+
opt.verbose_header = 0;
334+
opt.always_show_header = 0;
335+
opt.no_commit_id = 1;
336+
if (opt.combine_merges)
337+
opt.ignore_merges = 0;
338+
if (opt.dense_combined_merges)
339+
opt.diffopt.output_format = DIFF_FORMAT_PATCH;
340+
if (opt.diffopt.output_format == DIFF_FORMAT_PATCH)
341+
opt.diffopt.recursive = 1;
342+
diff_setup_done(&opt.diffopt);
343+
}
317344

318345
prepare_revision_walk(&rev);
319346
setup_pager();
@@ -350,6 +377,9 @@ static int cmd_log(int argc, const char **argv, char **envp)
350377
pretty_print_commit(commit_format, commit, ~0, buf,
351378
LOGSIZE, abbrev);
352379
printf("%s\n", buf);
380+
381+
if (do_diff)
382+
log_tree_commit(&opt, commit);
353383
}
354384
free(buf);
355385
return 0;

0 commit comments

Comments
 (0)