@matheusbsbs / matheus-bagliano / commits / cb8f64b4e3
Fork 0

log/whatchanged/show - log formatting cleanup.

This moves the decision to print the log message, while diff options are in effect, to log-tree. It gives behaviour closer to the traditional one. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Apr 16, 2006 at 03:29 UTC cb8f64b4e3f263c113b7a2f156af74b810e969ff
3 files changed +30 -15
git.c
+26 -15
@@ -288,7 +288,6 @@ static int cmd_log_wc(int argc, const char **argv, char **envp,
288
289 rev->abbrev = DEFAULT_ABBREV;
290 rev->commit_format = CMIT_FMT_DEFAULT;
291 - rev->no_commit_id = 1;
291 argc = setup_revisions(argc, argv, rev, "HEAD");
292
293 if (argc > 1)
@@ -299,16 +298,20 @@ static int cmd_log_wc(int argc, const char **argv, char **envp,
298 prepare_revision_walk(rev);
299 setup_pager();
300 while ((commit = get_revision(rev)) != NULL) {
301 + unsigned long ofs = 0;
302 +
303 if (shown && rev->diff &&
304 rev->commit_format != CMIT_FMT_ONELINE)
305 putchar('\n');
305 - fputs(commit_prefix, stdout);
306 +
307 + ofs = sprintf(buf, "%s", commit_prefix);
308 if (rev->abbrev_commit && rev->abbrev)
307 - fputs(find_unique_abbrev(commit->object.sha1,
308 - rev->abbrev),
309 - stdout);
309 + ofs += sprintf(buf + ofs, "%s",
310 + find_unique_abbrev(commit->object.sha1,
311 + rev->abbrev));
312 else
311 - fputs(sha1_to_hex(commit->object.sha1), stdout);
313 + ofs += sprintf(buf + ofs, "%s",
314 + sha1_to_hex(commit->object.sha1));
315 if (rev->parents) {
316 struct commit_list *parents = commit->parents;
317 while (parents) {
@@ -316,7 +319,8 @@ static int cmd_log_wc(int argc, const char **argv, char **envp,
319 parents = parents->next;
320 if (o->flags & TMP_MARK)
321 continue;
319 - printf(" %s", sha1_to_hex(o->sha1));
322 + ofs += sprintf(buf + ofs, " %s",
323 + sha1_to_hex(o->sha1));
324 o->flags |= TMP_MARK;
325 }
326 /* TMP_MARK is a general purpose flag that can
@@ -328,17 +332,20 @@ static int cmd_log_wc(int argc, const char **argv, char **envp,
332 parents = parents->next)
333 parents->item->object.flags &= ~TMP_MARK;
334 }
331 - if (rev->commit_format == CMIT_FMT_ONELINE)
332 - putchar(' ');
333 - else
334 - putchar('\n');
335 - pretty_print_commit(rev->commit_format, commit, ~0, buf,
336 - LOGSIZE, rev->abbrev);
337 - printf("%s\n", buf);
335 + buf[ofs++] =
336 + (rev->commit_format == CMIT_FMT_ONELINE) ? ' ' : '\n';
337 + ofs += pretty_print_commit(rev->commit_format, commit, ~0,
338 + buf + ofs,
339 + LOGSIZE - ofs - 20,
340 + rev->abbrev);
341 +
342 if (rev->diff) {
339 - printf("---\n");
343 + rev->use_precomputed_header = buf;
344 + strcpy(buf + ofs, "\n---\n");
345 log_tree_commit(rev, commit);
346 }
347 + else
348 + printf("%s\n", buf);
349 shown = 1;
350 free(commit->buffer);
351 commit->buffer = NULL;
@@ -376,6 +383,10 @@ static int cmd_log(int argc, const char **argv, char **envp)
383 struct rev_info rev;
384
385 init_revisions(&rev);
386 + rev.always_show_header = 1;
387 + rev.diffopt.recursive = 1;
388 + rev.combine_merges = 1;
389 + rev.ignore_merges = 0;
390 return cmd_log_wc(argc, argv, envp, &rev);
391 }
392
log-tree.c
+3
@@ -54,6 +54,9 @@ static const char *generate_header(struct rev_info *opt,
54 int abbrev = opt->diffopt.abbrev;
55 const char *msg = commit->buffer;
56
57 + if (opt->use_precomputed_header)
58 + return opt->use_precomputed_header;
59 +
60 if (!opt->verbose_header)
61 return sha1_to_hex(commit_sha1);
62
revision.h
+1
@@ -56,6 +56,7 @@ struct rev_info {
56 enum cmit_fmt commit_format;
57 const char *header_prefix;
58 const char *header;
59 + const char *use_precomputed_header;
60
61 /* special limits */
62 int max_count;