Skip to content

Commit

Permalink
log/whatchanged/show - log formatting cleanup.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Apr 16, 2006
1 parent d4ed979 commit cb8f64b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
41 changes: 26 additions & 15 deletions git.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ static int cmd_log_wc(int argc, const char **argv, char **envp,

rev->abbrev = DEFAULT_ABBREV;
rev->commit_format = CMIT_FMT_DEFAULT;
rev->no_commit_id = 1;
argc = setup_revisions(argc, argv, rev, "HEAD");

if (argc > 1)
Expand All @@ -299,24 +298,29 @@ static int cmd_log_wc(int argc, const char **argv, char **envp,
prepare_revision_walk(rev);
setup_pager();
while ((commit = get_revision(rev)) != NULL) {
unsigned long ofs = 0;

if (shown && rev->diff &&
rev->commit_format != CMIT_FMT_ONELINE)
putchar('\n');
fputs(commit_prefix, stdout);

ofs = sprintf(buf, "%s", commit_prefix);
if (rev->abbrev_commit && rev->abbrev)
fputs(find_unique_abbrev(commit->object.sha1,
rev->abbrev),
stdout);
ofs += sprintf(buf + ofs, "%s",
find_unique_abbrev(commit->object.sha1,
rev->abbrev));
else
fputs(sha1_to_hex(commit->object.sha1), stdout);
ofs += sprintf(buf + ofs, "%s",
sha1_to_hex(commit->object.sha1));
if (rev->parents) {
struct commit_list *parents = commit->parents;
while (parents) {
struct object *o = &(parents->item->object);
parents = parents->next;
if (o->flags & TMP_MARK)
continue;
printf(" %s", sha1_to_hex(o->sha1));
ofs += sprintf(buf + ofs, " %s",
sha1_to_hex(o->sha1));
o->flags |= TMP_MARK;
}
/* TMP_MARK is a general purpose flag that can
Expand All @@ -328,17 +332,20 @@ static int cmd_log_wc(int argc, const char **argv, char **envp,
parents = parents->next)
parents->item->object.flags &= ~TMP_MARK;
}
if (rev->commit_format == CMIT_FMT_ONELINE)
putchar(' ');
else
putchar('\n');
pretty_print_commit(rev->commit_format, commit, ~0, buf,
LOGSIZE, rev->abbrev);
printf("%s\n", buf);
buf[ofs++] =
(rev->commit_format == CMIT_FMT_ONELINE) ? ' ' : '\n';
ofs += pretty_print_commit(rev->commit_format, commit, ~0,
buf + ofs,
LOGSIZE - ofs - 20,
rev->abbrev);

if (rev->diff) {
printf("---\n");
rev->use_precomputed_header = buf;
strcpy(buf + ofs, "\n---\n");
log_tree_commit(rev, commit);
}
else
printf("%s\n", buf);
shown = 1;
free(commit->buffer);
commit->buffer = NULL;
Expand Down Expand Up @@ -376,6 +383,10 @@ static int cmd_log(int argc, const char **argv, char **envp)
struct rev_info rev;

init_revisions(&rev);
rev.always_show_header = 1;
rev.diffopt.recursive = 1;
rev.combine_merges = 1;
rev.ignore_merges = 0;
return cmd_log_wc(argc, argv, envp, &rev);
}

Expand Down
3 changes: 3 additions & 0 deletions log-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ static const char *generate_header(struct rev_info *opt,
int abbrev = opt->diffopt.abbrev;
const char *msg = commit->buffer;

if (opt->use_precomputed_header)
return opt->use_precomputed_header;

if (!opt->verbose_header)
return sha1_to_hex(commit_sha1);

Expand Down
1 change: 1 addition & 0 deletions revision.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct rev_info {
enum cmit_fmt commit_format;
const char *header_prefix;
const char *header;
const char *use_precomputed_header;

/* special limits */
int max_count;
Expand Down

0 comments on commit cb8f64b

Please sign in to comment.