1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-11-17 22:44:49 +01:00

Merge branch 'lt/logopt' into next

* lt/logopt:
  combine-diff: show diffstat with the first parent.
  git.c: LOGSIZE is unused after log printing cleanup.
  Log message printout cleanups (#3): fix --pretty=oneline
  Log message printout cleanups (#2)
  Log message printout cleanups
  rev-list --header: output format fix
This commit is contained in:
Junio C Hamano 2006-04-17 23:15:41 -07:00
commit 80608a61f0
11 changed files with 197 additions and 197 deletions

View file

@ -5,6 +5,7 @@
#include "diffcore.h" #include "diffcore.h"
#include "quote.h" #include "quote.h"
#include "xdiff-interface.h" #include "xdiff-interface.h"
#include "log-tree.h"
static int uninteresting(struct diff_filepair *p) static int uninteresting(struct diff_filepair *p)
{ {
@ -584,10 +585,20 @@ static void reuse_combine_diff(struct sline *sline, unsigned long cnt,
sline->p_lno[i] = sline->p_lno[j]; sline->p_lno[i] = sline->p_lno[j];
} }
static int show_patch_diff(struct combine_diff_path *elem, int num_parent, static void dump_quoted_path(const char *prefix, const char *path)
int dense, const char *header,
struct diff_options *opt)
{ {
fputs(prefix, stdout);
if (quote_c_style(path, NULL, NULL, 0))
quote_c_style(path, NULL, stdout, 0);
else
printf("%s", path);
putchar('\n');
}
static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
int dense, struct rev_info *rev)
{
struct diff_options *opt = &rev->diffopt;
unsigned long result_size, cnt, lno; unsigned long result_size, cnt, lno;
char *result, *cp; char *result, *cp;
struct sline *sline; /* survived lines */ struct sline *sline; /* survived lines */
@ -688,16 +699,9 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
if (show_hunks || mode_differs || working_tree_file) { if (show_hunks || mode_differs || working_tree_file) {
const char *abb; const char *abb;
if (header) { if (rev->loginfo)
shown_header++; show_log(rev, rev->loginfo, "\n");
printf("%s%c", header, opt->line_termination); dump_quoted_path(dense ? "diff --cc " : "diff --combined ", elem->path);
}
printf("diff --%s ", dense ? "cc" : "combined");
if (quote_c_style(elem->path, NULL, NULL, 0))
quote_c_style(elem->path, NULL, stdout, 0);
else
printf("%s", elem->path);
putchar('\n');
printf("index "); printf("index ");
for (i = 0; i < num_parent; i++) { for (i = 0; i < num_parent; i++) {
abb = find_unique_abbrev(elem->parent[i].sha1, abb = find_unique_abbrev(elem->parent[i].sha1,
@ -728,6 +732,8 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
} }
putchar('\n'); putchar('\n');
} }
dump_quoted_path("--- a/", elem->path);
dump_quoted_path("+++ b/", elem->path);
dump_sline(sline, cnt, num_parent); dump_sline(sline, cnt, num_parent);
} }
free(result); free(result);
@ -749,8 +755,9 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
#define COLONS "::::::::::::::::::::::::::::::::" #define COLONS "::::::::::::::::::::::::::::::::"
static void show_raw_diff(struct combine_diff_path *p, int num_parent, const char *header, struct diff_options *opt) static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct rev_info *rev)
{ {
struct diff_options *opt = &rev->diffopt;
int i, offset; int i, offset;
const char *prefix; const char *prefix;
int line_termination, inter_name_termination; int line_termination, inter_name_termination;
@ -760,8 +767,8 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, const cha
if (!line_termination) if (!line_termination)
inter_name_termination = 0; inter_name_termination = 0;
if (header) if (rev->loginfo)
printf("%s%c", header, line_termination); show_log(rev, rev->loginfo, "\n");
if (opt->output_format == DIFF_FORMAT_RAW) { if (opt->output_format == DIFF_FORMAT_RAW) {
offset = strlen(COLONS) - num_parent; offset = strlen(COLONS) - num_parent;
@ -802,40 +809,44 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, const cha
} }
} }
int show_combined_diff(struct combine_diff_path *p, void show_combined_diff(struct combine_diff_path *p,
int num_parent, int num_parent,
int dense, int dense,
const char *header, struct rev_info *rev)
struct diff_options *opt)
{ {
struct diff_options *opt = &rev->diffopt;
if (!p->len) if (!p->len)
return 0; return;
switch (opt->output_format) { switch (opt->output_format) {
case DIFF_FORMAT_RAW: case DIFF_FORMAT_RAW:
case DIFF_FORMAT_NAME_STATUS: case DIFF_FORMAT_NAME_STATUS:
case DIFF_FORMAT_NAME: case DIFF_FORMAT_NAME:
show_raw_diff(p, num_parent, header, opt); show_raw_diff(p, num_parent, rev);
return 1; return;
default:
case DIFF_FORMAT_PATCH: case DIFF_FORMAT_PATCH:
return show_patch_diff(p, num_parent, dense, header, opt); show_patch_diff(p, num_parent, dense, rev);
return;
default:
return;
} }
} }
const char *diff_tree_combined_merge(const unsigned char *sha1, void diff_tree_combined_merge(const unsigned char *sha1,
const char *header, int dense, int dense, struct rev_info *rev)
struct diff_options *opt)
{ {
struct diff_options *opt = &rev->diffopt;
struct commit *commit = lookup_commit(sha1); struct commit *commit = lookup_commit(sha1);
struct diff_options diffopts; struct diff_options diffopts;
struct commit_list *parents; struct commit_list *parents;
struct combine_diff_path *p, *paths = NULL; struct combine_diff_path *p, *paths = NULL;
int num_parent, i, num_paths; int num_parent, i, num_paths;
int do_diffstat;
do_diffstat = (opt->output_format == DIFF_FORMAT_DIFFSTAT ||
opt->with_stat);
diffopts = *opt; diffopts = *opt;
diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
diffopts.with_raw = 0; diffopts.with_raw = 0;
diffopts.with_stat = 0;
diffopts.recursive = 1; diffopts.recursive = 1;
/* count parents */ /* count parents */
@ -849,11 +860,24 @@ const char *diff_tree_combined_merge(const unsigned char *sha1,
parents; parents;
parents = parents->next, i++) { parents = parents->next, i++) {
struct commit *parent = parents->item; struct commit *parent = parents->item;
/* show stat against the first parent even
* when doing combined diff.
*/
if (i == 0 && do_diffstat)
diffopts.output_format = DIFF_FORMAT_DIFFSTAT;
else
diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
diff_tree_sha1(parent->object.sha1, commit->object.sha1, "", diff_tree_sha1(parent->object.sha1, commit->object.sha1, "",
&diffopts); &diffopts);
diffcore_std(&diffopts); diffcore_std(&diffopts);
paths = intersect_paths(paths, i, num_parent); paths = intersect_paths(paths, i, num_parent);
if (do_diffstat && rev->loginfo)
show_log(rev, rev->loginfo,
opt->with_stat ? "---\n" : "\n");
diff_flush(&diffopts); diff_flush(&diffopts);
if (opt->with_stat)
putchar('\n');
} }
/* find out surviving paths */ /* find out surviving paths */
@ -866,17 +890,13 @@ const char *diff_tree_combined_merge(const unsigned char *sha1,
int saved_format = opt->output_format; int saved_format = opt->output_format;
opt->output_format = DIFF_FORMAT_RAW; opt->output_format = DIFF_FORMAT_RAW;
for (p = paths; p; p = p->next) { for (p = paths; p; p = p->next) {
if (show_combined_diff(p, num_parent, dense, show_combined_diff(p, num_parent, dense, rev);
header, opt))
header = NULL;
} }
opt->output_format = saved_format; opt->output_format = saved_format;
putchar(opt->line_termination); putchar(opt->line_termination);
} }
for (p = paths; p; p = p->next) { for (p = paths; p; p = p->next) {
if (show_combined_diff(p, num_parent, dense, show_combined_diff(p, num_parent, dense, rev);
header, opt))
header = NULL;
} }
} }
@ -886,5 +906,4 @@ const char *diff_tree_combined_merge(const unsigned char *sha1,
paths = paths->next; paths = paths->next;
free(tmp); free(tmp);
} }
return header;
} }

View file

@ -5,12 +5,14 @@
*/ */
#include "cache.h" #include "cache.h"
#include "diff.h" #include "diff.h"
#include "commit.h"
#include "revision.h"
static const char diff_files_usage[] = static const char diff_files_usage[] =
"git-diff-files [-q] [-0/-1/2/3 |-c|--cc] [<common diff options>] [<path>...]" "git-diff-files [-q] [-0/-1/2/3 |-c|--cc] [<common diff options>] [<path>...]"
COMMON_DIFF_OPTIONS_HELP; COMMON_DIFF_OPTIONS_HELP;
static struct diff_options diff_options; static struct rev_info rev;
static int silent = 0; static int silent = 0;
static int diff_unmerged_stage = 2; static int diff_unmerged_stage = 2;
static int combine_merges = 0; static int combine_merges = 0;
@ -18,12 +20,12 @@ static int dense_combined_merges = 0;
static void show_unmerge(const char *path) static void show_unmerge(const char *path)
{ {
diff_unmerge(&diff_options, path); diff_unmerge(&rev.diffopt, path);
} }
static void show_file(int pfx, struct cache_entry *ce) static void show_file(int pfx, struct cache_entry *ce)
{ {
diff_addremove(&diff_options, pfx, ntohl(ce->ce_mode), diff_addremove(&rev.diffopt, pfx, ntohl(ce->ce_mode),
ce->sha1, ce->name, NULL); ce->sha1, ce->name, NULL);
} }
@ -31,7 +33,7 @@ static void show_modified(int oldmode, int mode,
const unsigned char *old_sha1, const unsigned char *sha1, const unsigned char *old_sha1, const unsigned char *sha1,
char *path) char *path)
{ {
diff_change(&diff_options, oldmode, mode, old_sha1, sha1, path, NULL); diff_change(&rev.diffopt, oldmode, mode, old_sha1, sha1, path, NULL);
} }
int main(int argc, const char **argv) int main(int argc, const char **argv)
@ -41,7 +43,7 @@ int main(int argc, const char **argv)
int entries, i; int entries, i;
git_config(git_diff_config); git_config(git_diff_config);
diff_setup(&diff_options); diff_setup(&rev.diffopt);
while (1 < argc && argv[1][0] == '-') { while (1 < argc && argv[1][0] == '-') {
if (!strcmp(argv[1], "--")) { if (!strcmp(argv[1], "--")) {
argv++; argv++;
@ -74,7 +76,7 @@ int main(int argc, const char **argv)
dense_combined_merges = combine_merges = 1; dense_combined_merges = combine_merges = 1;
else { else {
int diff_opt_cnt; int diff_opt_cnt;
diff_opt_cnt = diff_opt_parse(&diff_options, diff_opt_cnt = diff_opt_parse(&rev.diffopt,
argv+1, argc-1); argv+1, argc-1);
if (diff_opt_cnt < 0) if (diff_opt_cnt < 0)
usage(diff_files_usage); usage(diff_files_usage);
@ -89,13 +91,13 @@ int main(int argc, const char **argv)
argv++; argc--; argv++; argc--;
} }
if (dense_combined_merges) if (dense_combined_merges)
diff_options.output_format = DIFF_FORMAT_PATCH; rev.diffopt.output_format = DIFF_FORMAT_PATCH;
/* Find the directory, and set up the pathspec */ /* Find the directory, and set up the pathspec */
pathspec = get_pathspec(prefix, argv + 1); pathspec = get_pathspec(prefix, argv + 1);
entries = read_cache(); entries = read_cache();
if (diff_setup_done(&diff_options) < 0) if (diff_setup_done(&rev.diffopt) < 0)
usage(diff_files_usage); usage(diff_files_usage);
/* At this point, if argc == 1, then we are doing everything. /* At this point, if argc == 1, then we are doing everything.
@ -167,8 +169,7 @@ int main(int argc, const char **argv)
if (combine_merges && num_compare_stages == 2) { if (combine_merges && num_compare_stages == 2) {
show_combined_diff(&combine.p, 2, show_combined_diff(&combine.p, 2,
dense_combined_merges, dense_combined_merges,
NULL, &rev);
&diff_options);
free(combine.p.path); free(combine.p.path);
continue; continue;
} }
@ -194,7 +195,7 @@ int main(int argc, const char **argv)
continue; continue;
} }
changed = ce_match_stat(ce, &st, 0); changed = ce_match_stat(ce, &st, 0);
if (!changed && !diff_options.find_copies_harder) if (!changed && !rev.diffopt.find_copies_harder)
continue; continue;
oldmode = ntohl(ce->ce_mode); oldmode = ntohl(ce->ce_mode);
@ -207,7 +208,7 @@ int main(int argc, const char **argv)
ce->sha1, (changed ? null_sha1 : ce->sha1), ce->sha1, (changed ? null_sha1 : ce->sha1),
ce->name); ce->name);
} }
diffcore_std(&diff_options); diffcore_std(&rev.diffopt);
diff_flush(&diff_options); diff_flush(&rev.diffopt);
return 0; return 0;
} }

View file

@ -71,6 +71,7 @@ int main(int argc, const char **argv)
nr_sha1 = 0; nr_sha1 = 0;
init_revisions(opt); init_revisions(opt);
opt->abbrev = 0; opt->abbrev = 0;
opt->diff = 1;
argc = setup_revisions(argc, argv, opt, NULL); argc = setup_revisions(argc, argv, opt, NULL);
while (--argc > 0) { while (--argc > 0) {

8
diff.h
View file

@ -6,6 +6,7 @@
#include "tree-walk.h" #include "tree-walk.h"
struct rev_info;
struct diff_options; struct diff_options;
typedef void (*change_fn_t)(struct diff_options *options, typedef void (*change_fn_t)(struct diff_options *options,
@ -70,11 +71,10 @@ struct combine_diff_path {
(sizeof(struct combine_diff_path) + \ (sizeof(struct combine_diff_path) + \
sizeof(struct combine_diff_parent) * (n) + (l) + 1) sizeof(struct combine_diff_parent) * (n) + (l) + 1)
extern int show_combined_diff(struct combine_diff_path *elem, int num_parent, extern void show_combined_diff(struct combine_diff_path *elem, int num_parent,
int dense, const char *header, int dense, struct rev_info *);
struct diff_options *);
extern const char *diff_tree_combined_merge(const unsigned char *sha1, const char *, int, struct diff_options *opt); extern void diff_tree_combined_merge(const unsigned char *sha1, int, struct rev_info *);
extern void diff_addremove(struct diff_options *, extern void diff_addremove(struct diff_options *,
int addremove, int addremove,

59
git.c
View file

@ -276,81 +276,26 @@ static int cmd_help(int argc, const char **argv, char **envp)
return 0; return 0;
} }
#define LOGSIZE (65536)
static int cmd_log_wc(int argc, const char **argv, char **envp, static int cmd_log_wc(int argc, const char **argv, char **envp,
struct rev_info *rev) struct rev_info *rev)
{ {
struct commit *commit; struct commit *commit;
char *buf = xmalloc(LOGSIZE);
const char *commit_prefix = "commit ";
int shown = 0;
rev->abbrev = DEFAULT_ABBREV; rev->abbrev = DEFAULT_ABBREV;
rev->commit_format = CMIT_FMT_DEFAULT; rev->commit_format = CMIT_FMT_DEFAULT;
rev->verbose_header = 1;
argc = setup_revisions(argc, argv, rev, "HEAD"); argc = setup_revisions(argc, argv, rev, "HEAD");
if (argc > 1) if (argc > 1)
die("unrecognized argument: %s", argv[1]); die("unrecognized argument: %s", argv[1]);
if (rev->commit_format == CMIT_FMT_ONELINE)
commit_prefix = "";
prepare_revision_walk(rev); prepare_revision_walk(rev);
setup_pager(); setup_pager();
while ((commit = get_revision(rev)) != NULL) { while ((commit = get_revision(rev)) != NULL) {
unsigned long ofs = 0; log_tree_commit(rev, commit);
if (shown && rev->diff &&
rev->commit_format != CMIT_FMT_ONELINE)
putchar('\n');
ofs = sprintf(buf, "%s", commit_prefix);
if (rev->abbrev_commit && rev->abbrev)
ofs += sprintf(buf + ofs, "%s",
find_unique_abbrev(commit->object.sha1,
rev->abbrev));
else
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;
ofs += sprintf(buf + ofs, " %s",
sha1_to_hex(o->sha1));
o->flags |= TMP_MARK;
}
/* TMP_MARK is a general purpose flag that can
* be used locally, but the user should clean
* things up after it is done with them.
*/
for (parents = commit->parents;
parents;
parents = parents->next)
parents->item->object.flags &= ~TMP_MARK;
}
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) {
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); free(commit->buffer);
commit->buffer = NULL; commit->buffer = NULL;
} }
free(buf);
return 0; return 0;
} }

View file

@ -3,9 +3,58 @@
#include "commit.h" #include "commit.h"
#include "log-tree.h" #include "log-tree.h"
void show_log(struct rev_info *opt, struct log_info *log, const char *sep)
{
static char this_header[16384];
struct commit *commit = log->commit, *parent = log->parent;
int abbrev = opt->diffopt.abbrev;
int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;
const char *extra;
int len;
opt->loginfo = NULL;
if (!opt->verbose_header) {
puts(sha1_to_hex(commit->object.sha1));
return;
}
/*
* The "oneline" format has several special cases:
* - The pretty-printed commit lacks a newline at the end
* of the buffer, but we do want to make sure that we
* have a newline there. If the separator isn't already
* a newline, add an extra one.
* - unlike other log messages, the one-line format does
* not have an empty line between entries.
*/
extra = "";
if (*sep != '\n' && opt->commit_format == CMIT_FMT_ONELINE)
extra = "\n";
if (opt->shown_one && opt->commit_format != CMIT_FMT_ONELINE)
putchar('\n');
opt->shown_one = 1;
/*
* Print header line of header..
*/
printf("%s%s",
opt->commit_format == CMIT_FMT_ONELINE ? "" : "commit ",
diff_unique_abbrev(commit->object.sha1, abbrev_commit));
if (parent)
printf(" (from %s)", diff_unique_abbrev(parent->object.sha1, abbrev_commit));
putchar(opt->commit_format == CMIT_FMT_ONELINE ? ' ' : '\n');
/*
* And then the pretty-printed message itself
*/
len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev);
printf("%s%s%s", this_header, extra, sep);
}
int log_tree_diff_flush(struct rev_info *opt) int log_tree_diff_flush(struct rev_info *opt)
{ {
diffcore_std(&opt->diffopt); diffcore_std(&opt->diffopt);
if (diff_queue_is_empty()) { if (diff_queue_is_empty()) {
int saved_fmt = opt->diffopt.output_format; int saved_fmt = opt->diffopt.output_format;
opt->diffopt.output_format = DIFF_FORMAT_NO_OUTPUT; opt->diffopt.output_format = DIFF_FORMAT_NO_OUTPUT;
@ -13,12 +62,9 @@ int log_tree_diff_flush(struct rev_info *opt)
opt->diffopt.output_format = saved_fmt; opt->diffopt.output_format = saved_fmt;
return 0; return 0;
} }
if (opt->header) {
if (!opt->no_commit_id) if (opt->loginfo && !opt->no_commit_id)
printf("%s%c", opt->header, show_log(opt, opt->loginfo, opt->diffopt.with_stat ? "---\n" : "\n");
opt->diffopt.line_termination);
opt->header = NULL;
}
diff_flush(&opt->diffopt); diff_flush(&opt->diffopt);
return 1; return 1;
} }
@ -43,96 +89,78 @@ static int diff_root_tree(struct rev_info *opt,
return retval; return retval;
} }
static const char *get_header(struct rev_info *opt,
const unsigned char *commit_sha1,
const unsigned char *parent_sha1,
const struct commit *commit)
{
static char this_header[16384];
int offset;
unsigned long len;
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);
len = strlen(msg);
offset = sprintf(this_header, "%s%s ",
opt->header_prefix,
diff_unique_abbrev(commit_sha1, abbrev));
if (commit_sha1 != parent_sha1)
offset += sprintf(this_header + offset, "(from %s)\n",
parent_sha1
? diff_unique_abbrev(parent_sha1, abbrev)
: "root");
else
offset += sprintf(this_header + offset, "(from parents)\n");
offset += pretty_print_commit(opt->commit_format, commit, len,
this_header + offset,
sizeof(this_header) - offset, abbrev);
return this_header;
}
static const char *generate_header(struct rev_info *opt,
const unsigned char *commit_sha1,
const unsigned char *parent_sha1,
const struct commit *commit)
{
const char *header = get_header(opt, commit_sha1, parent_sha1, commit);
if (opt->always_show_header) {
puts(header);
header = NULL;
}
return header;
}
static int do_diff_combined(struct rev_info *opt, struct commit *commit) static int do_diff_combined(struct rev_info *opt, struct commit *commit)
{ {
unsigned const char *sha1 = commit->object.sha1; unsigned const char *sha1 = commit->object.sha1;
opt->header = generate_header(opt, sha1, sha1, commit); diff_tree_combined_merge(sha1, opt->dense_combined_merges, opt);
opt->header = diff_tree_combined_merge(sha1, opt->header, return !opt->loginfo;
opt->dense_combined_merges,
&opt->diffopt);
if (!opt->header && opt->verbose_header)
opt->header_prefix = "\ndiff-tree ";
return 0;
} }
int log_tree_commit(struct rev_info *opt, struct commit *commit) /*
* Show the diff of a commit.
*
* Return true if we printed any log info messages
*/
static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log_info *log)
{ {
int showed_log;
struct commit_list *parents; struct commit_list *parents;
unsigned const char *sha1 = commit->object.sha1; unsigned const char *sha1 = commit->object.sha1;
if (!opt->diff)
return 0;
/* Root commit? */ /* Root commit? */
if (opt->show_root_diff && !commit->parents) { parents = commit->parents;
opt->header = generate_header(opt, sha1, NULL, commit); if (!parents) {
diff_root_tree(opt, sha1, ""); if (opt->show_root_diff)
diff_root_tree(opt, sha1, "");
return !opt->loginfo;
} }
/* More than one parent? */ /* More than one parent? */
if (commit->parents && commit->parents->next) { if (parents && parents->next) {
if (opt->ignore_merges) if (opt->ignore_merges)
return 0; return 0;
else if (opt->combine_merges) else if (opt->combine_merges)
return do_diff_combined(opt, commit); return do_diff_combined(opt, commit);
/* If we show individual diffs, show the parent info */
log->parent = parents->item;
} }
for (parents = commit->parents; parents; parents = parents->next) { showed_log = 0;
for (;;) {
struct commit *parent = parents->item; struct commit *parent = parents->item;
unsigned const char *psha1 = parent->object.sha1;
opt->header = generate_header(opt, sha1, psha1, commit);
diff_tree_sha1(psha1, sha1, "", &opt->diffopt);
log_tree_diff_flush(opt);
if (!opt->header && opt->verbose_header) diff_tree_sha1(parent->object.sha1, sha1, "", &opt->diffopt);
opt->header_prefix = "\ndiff-tree "; log_tree_diff_flush(opt);
showed_log |= !opt->loginfo;
/* Set up the log info for the next parent, if any.. */
parents = parents->next;
if (!parents)
break;
log->parent = parents->item;
opt->loginfo = log;
} }
return showed_log;
}
int log_tree_commit(struct rev_info *opt, struct commit *commit)
{
struct log_info log;
log.commit = commit;
log.parent = NULL;
opt->loginfo = &log;
if (!log_tree_diff(opt, commit, &log) && opt->loginfo && opt->always_show_header) {
log.parent = NULL;
show_log(opt, opt->loginfo, "");
}
opt->loginfo = NULL;
return 0; return 0;
} }

View file

@ -3,9 +3,14 @@
#include "revision.h" #include "revision.h"
struct log_info {
struct commit *commit, *parent;
};
void init_log_tree_opt(struct rev_info *); void init_log_tree_opt(struct rev_info *);
int log_tree_diff_flush(struct rev_info *); int log_tree_diff_flush(struct rev_info *);
int log_tree_commit(struct rev_info *, struct commit *); int log_tree_commit(struct rev_info *, struct commit *);
int log_tree_opt_parse(struct rev_info *, const char **, int); int log_tree_opt_parse(struct rev_info *, const char **, int);
void show_log(struct rev_info *opt, struct log_info *log, const char *sep);
#endif #endif

View file

@ -41,13 +41,14 @@ struct rev_info revs;
static int bisect_list = 0; static int bisect_list = 0;
static int show_timestamp = 0; static int show_timestamp = 0;
static int hdr_termination = 0; static int hdr_termination = 0;
static const char *header_prefix;
static void show_commit(struct commit *commit) static void show_commit(struct commit *commit)
{ {
if (show_timestamp) if (show_timestamp)
printf("%lu ", commit->date); printf("%lu ", commit->date);
if (*revs.header_prefix) if (header_prefix)
fputs(revs.header_prefix, stdout); fputs(header_prefix, stdout);
if (commit->object.flags & BOUNDARY) if (commit->object.flags & BOUNDARY)
putchar('-'); putchar('-');
if (revs.abbrev_commit && revs.abbrev) if (revs.abbrev_commit && revs.abbrev)
@ -322,10 +323,13 @@ int main(int argc, const char **argv)
/* The command line has a --pretty */ /* The command line has a --pretty */
hdr_termination = '\n'; hdr_termination = '\n';
if (revs.commit_format == CMIT_FMT_ONELINE) if (revs.commit_format == CMIT_FMT_ONELINE)
revs.header_prefix = ""; header_prefix = "";
else else
revs.header_prefix = "commit "; header_prefix = "commit ";
} }
else if (revs.verbose_header)
/* Only --header was specified */
revs.commit_format = CMIT_FMT_RAW;
list = revs.commits; list = revs.commits;

View file

@ -498,7 +498,6 @@ void init_revisions(struct rev_info *revs)
revs->topo_setter = topo_sort_default_setter; revs->topo_setter = topo_sort_default_setter;
revs->topo_getter = topo_sort_default_getter; revs->topo_getter = topo_sort_default_getter;
revs->header_prefix = "";
revs->commit_format = CMIT_FMT_DEFAULT; revs->commit_format = CMIT_FMT_DEFAULT;
diff_setup(&revs->diffopt); diff_setup(&revs->diffopt);
@ -675,12 +674,10 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
} }
if (!strcmp(arg, "-v")) { if (!strcmp(arg, "-v")) {
revs->verbose_header = 1; revs->verbose_header = 1;
revs->header_prefix = "diff-tree ";
continue; continue;
} }
if (!strncmp(arg, "--pretty", 8)) { if (!strncmp(arg, "--pretty", 8)) {
revs->verbose_header = 1; revs->verbose_header = 1;
revs->header_prefix = "diff-tree ";
revs->commit_format = get_commit_format(arg+8); revs->commit_format = get_commit_format(arg+8);
continue; continue;
} }

View file

@ -11,6 +11,7 @@
#define ADDED (1u<<7) /* Parents already parsed and added? */ #define ADDED (1u<<7) /* Parents already parsed and added? */
struct rev_info; struct rev_info;
struct log_info;
typedef void (prune_fn_t)(struct rev_info *revs, struct commit *commit); typedef void (prune_fn_t)(struct rev_info *revs, struct commit *commit);
@ -52,12 +53,11 @@ struct rev_info {
always_show_header:1; always_show_header:1;
/* Format info */ /* Format info */
unsigned int abbrev_commit:1; unsigned int shown_one:1,
abbrev_commit:1;
unsigned int abbrev; unsigned int abbrev;
enum cmit_fmt commit_format; enum cmit_fmt commit_format;
const char *header_prefix; struct log_info *loginfo;
const char *header;
const char *use_precomputed_header;
/* special limits */ /* special limits */
int max_count; int max_count;

View file

@ -49,7 +49,7 @@ test_expect_success 'git diff HEAD' 'cmp diff.expect diff.output'
#test_expect_success 'git-read-tree --reset HEAD' "git-read-tree --reset HEAD ; test \"hello: needs update\" = \"$(git-update-index --refresh)\"" #test_expect_success 'git-read-tree --reset HEAD' "git-read-tree --reset HEAD ; test \"hello: needs update\" = \"$(git-update-index --refresh)\""
cat > whatchanged.expect << EOF cat > whatchanged.expect << EOF
diff-tree VARIABLE (from root) commit VARIABLE
Author: VARIABLE Author: VARIABLE
Date: VARIABLE Date: VARIABLE
@ -72,7 +72,7 @@ index 0000000..557db03
EOF EOF
git-whatchanged -p --root | \ git-whatchanged -p --root | \
sed -e "1s/^\(.\{10\}\).\{40\}/\1VARIABLE/" \ sed -e "1s/^\(.\{7\}\).\{40\}/\1VARIABLE/" \
-e "2,3s/^\(.\{8\}\).*$/\1VARIABLE/" \ -e "2,3s/^\(.\{8\}\).*$/\1VARIABLE/" \
> whatchanged.output > whatchanged.output
test_expect_success 'git-whatchanged -p --root' 'cmp whatchanged.expect whatchanged.output' test_expect_success 'git-whatchanged -p --root' 'cmp whatchanged.expect whatchanged.output'