Built-in git-whatchanged
Now "git log" is in reusable shape, add "git whatchanged" which essentially is a synonym with different default for people whose fingers are already trained. There is a subtle difference from the shell-script version; the first line of each entry is now "commit <object name>", instead of "diff-tree <object name> (from <object name>)." I suspect that showing the parent name that way is useful, so this may be something we would want to fix (the user can say --pretty=raw to get that information but that is a bit ugly). Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Apr 15, 2006 at 04:15 UTC
1fc70b60bfda67205253595ad9dc040019c2efe5
1 file changed
+32
-13
git.c
+32
-13
@@ -278,21 +278,19 @@ static int cmd_help(int argc, const char **argv, char **envp)
278
279
#define LOGSIZE (65536)
280
281
-static int cmd_log(int argc, const char **argv, char **envp)
281
+static int cmd_log_wc(int argc, const char **argv, char **envp,
282
+ struct whatchanged_opt *wcopt)
283
{
283
- struct whatchanged_opt wcopt;
284
struct commit *commit;
285
char *buf = xmalloc(LOGSIZE);
286
const char *commit_prefix = "commit ";
287
int shown = 0;
288
- struct rev_info *rev = &wcopt.revopt;
289
- struct log_tree_opt *opt = &wcopt.logopt;
288
+ struct rev_info *rev = &wcopt->revopt;
289
+ struct log_tree_opt *opt = &wcopt->logopt;
290
291
- memset(&wcopt, 0, sizeof(wcopt));
292
- init_log_tree_opt(&wcopt.logopt);
291
opt->commit_format = CMIT_FMT_DEFAULT;
294
- wcopt.abbrev = DEFAULT_ABBREV;
295
- argc = parse_whatchanged_opt(argc, argv, &wcopt);
292
+ wcopt->abbrev = DEFAULT_ABBREV;
293
+ argc = parse_whatchanged_opt(argc, argv, wcopt);
294
295
if (opt->commit_format == CMIT_FMT_ONELINE)
296
commit_prefix = "";
@@ -300,12 +298,12 @@ static int cmd_log(int argc, const char **argv, char **envp)
298
prepare_revision_walk(rev);
299
setup_pager();
300
while ((commit = get_revision(rev)) != NULL) {
303
- if (shown && wcopt.do_diff &&
301
+ if (shown && wcopt->do_diff &&
302
opt->commit_format != CMIT_FMT_ONELINE)
303
putchar('\n');
304
fputs(commit_prefix, stdout);
307
- if (wcopt.abbrev_commit && wcopt.abbrev)
308
- fputs(find_unique_abbrev(commit->object.sha1, wcopt.abbrev),
305
+ if (wcopt->abbrev_commit && wcopt->abbrev)
306
+ fputs(find_unique_abbrev(commit->object.sha1, wcopt->abbrev),
307
stdout);
308
else
309
fputs(sha1_to_hex(commit->object.sha1), stdout);
@@ -333,9 +331,9 @@ static int cmd_log(int argc, const char **argv, char **envp)
331
else
332
putchar('\n');
333
pretty_print_commit(opt->commit_format, commit, ~0, buf,
336
- LOGSIZE, wcopt.abbrev);
334
+ LOGSIZE, wcopt->abbrev);
335
printf("%s\n", buf);
338
- if (wcopt.do_diff)
336
+ if (wcopt->do_diff)
337
log_tree_commit(opt, commit);
338
shown = 1;
339
free(commit->buffer);
@@ -345,6 +343,26 @@ static int cmd_log(int argc, const char **argv, char **envp)
343
return 0;
344
}
345
346
+static int cmd_log(int ac, const char **av, char **ep)
347
+{
348
+ struct whatchanged_opt wcopt;
349
+
350
+ memset(&wcopt, 0, sizeof(wcopt));
351
+ init_log_tree_opt(&wcopt.logopt);
352
+ return cmd_log_wc(ac, av, ep, &wcopt);
353
+}
354
+
355
+static int cmd_whatchanged(int ac, const char **av, char **ep)
356
+{
357
+ struct whatchanged_opt wcopt;
358
+
359
+ memset(&wcopt, 0, sizeof(wcopt));
360
+ wcopt.do_diff = 1;
361
+ init_log_tree_opt(&wcopt.logopt);
362
+ wcopt.logopt.diffopt.recursive = 1;
363
+ return cmd_log_wc(ac, av, ep, &wcopt);
364
+}
365
+
366
static void handle_internal_command(int argc, const char **argv, char **envp)
367
{
368
const char *cmd = argv[0];
@@ -355,6 +373,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
373
{ "version", cmd_version },
374
{ "help", cmd_help },
375
{ "log", cmd_log },
376
+ { "whatchanged", cmd_whatchanged },
377
};
378
int i;
379