Skip to content

Commit

Permalink
Merge branch 'th/diff'
Browse files Browse the repository at this point in the history
* th/diff:
  builtin-diff: turn recursive on when defaulting to --patch format.
  t4013: note improvements brought by the new output code.
  t4013: add format-patch tests.
  format-patch: fix diff format option implementation
  combine-diff.c: type sanity.
  t4013 test updates for new output code.
  Fix some more diff options changes.
  Fix diff-tree -s
  log --raw: Don't descend into subdirectories by default
  diff-tree: Use ---\n as a message separator
  Print empty line between raw, stat, summary and patch
  t4013: add more tests around -c and --cc
  whatchanged: Default to DIFF_FORMAT_RAW
  Don't xcalloc() struct diffstat_t
  Add msg_sep to diff_options
  DIFF_FORMAT_RAW is not default anymore
  Set default diff output format after parsing command line
  Make --raw option available for all diff commands
  Merge with_raw, with_stat and summary variables to output_format
  t4013: add tests for diff/log family output options.
  • Loading branch information
Junio C Hamano committed Jul 5, 2006
2 parents 169c2e9 + 047fbe9 commit 0c926a3
Show file tree
Hide file tree
Showing 110 changed files with 4,722 additions and 205 deletions.
3 changes: 3 additions & 0 deletions builtin-diff-files.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ int cmd_diff_files(int argc, const char **argv, char **envp)
usage(diff_files_usage);
argv++; argc--;
}
if (!rev.diffopt.output_format)
rev.diffopt.output_format = DIFF_FORMAT_RAW;

/*
* Make sure there are NO revision (i.e. pending object) parameter,
* rev.max_count is reasonable (0 <= n <= 3),
Expand Down
3 changes: 3 additions & 0 deletions builtin-diff-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ int cmd_diff_index(int argc, const char **argv, char **envp)
else
usage(diff_cache_usage);
}
if (!rev.diffopt.output_format)
rev.diffopt.output_format = DIFF_FORMAT_RAW;

/*
* Make sure there is one revision (i.e. pending object),
* and there is no revision filtering parameters.
Expand Down
3 changes: 3 additions & 0 deletions builtin-diff-stages.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ int cmd_diff_stages(int ac, const char **av, char **envp)
ac--; av++;
}

if (!diff_options.output_format)
diff_options.output_format = DIFF_FORMAT_RAW;

if (ac < 3 ||
sscanf(av[1], "%d", &stage1) != 1 ||
! (0 <= stage1 && stage1 <= 3) ||
Expand Down
3 changes: 3 additions & 0 deletions builtin-diff-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ int cmd_diff_tree(int argc, const char **argv, char **envp)
usage(diff_tree_usage);
}

if (!opt->diffopt.output_format)
opt->diffopt.output_format = DIFF_FORMAT_RAW;

/*
* NOTE! We expect "a ^b" to be equal to "a..b", so we
* reverse the order of the objects if the second one
Expand Down
56 changes: 18 additions & 38 deletions builtin-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ static int builtin_diff_files(struct rev_info *revs,
revs->max_count = 3;
else if (!strcmp(arg, "-q"))
silent = 1;
else if (!strcmp(arg, "--raw"))
revs->diffopt.output_format = DIFF_FORMAT_RAW;
else
usage(builtin_diff_usage);
argv++; argc--;
Expand All @@ -56,7 +54,7 @@ static int builtin_diff_files(struct rev_info *revs,
3 < revs->max_count)
usage(builtin_diff_usage);
if (revs->max_count < 0 &&
(revs->diffopt.output_format == DIFF_FORMAT_PATCH))
(revs->diffopt.output_format & DIFF_FORMAT_PATCH))
revs->combine_merges = revs->dense_combined_merges = 1;
/*
* Backward compatibility wart - "diff-files -s" used to
Expand Down Expand Up @@ -107,14 +105,9 @@ static int builtin_diff_b_f(struct rev_info *revs,
/* Blob vs file in the working tree*/
struct stat st;

while (1 < argc) {
const char *arg = argv[1];
if (!strcmp(arg, "--raw"))
revs->diffopt.output_format = DIFF_FORMAT_RAW;
else
usage(builtin_diff_usage);
argv++; argc--;
}
if (argc > 1)
usage(builtin_diff_usage);

if (lstat(path, &st))
die("'%s': %s", path, strerror(errno));
if (!(S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)))
Expand All @@ -137,14 +130,9 @@ static int builtin_diff_blobs(struct rev_info *revs,
*/
unsigned mode = canon_mode(S_IFREG | 0644);

while (1 < argc) {
const char *arg = argv[1];
if (!strcmp(arg, "--raw"))
revs->diffopt.output_format = DIFF_FORMAT_RAW;
else
usage(builtin_diff_usage);
argv++; argc--;
}
if (argc > 1)
usage(builtin_diff_usage);

stuff_change(&revs->diffopt,
mode, mode,
blob[1].sha1, blob[0].sha1,
Expand All @@ -162,8 +150,6 @@ static int builtin_diff_index(struct rev_info *revs,
const char *arg = argv[1];
if (!strcmp(arg, "--cached"))
cached = 1;
else if (!strcmp(arg, "--raw"))
revs->diffopt.output_format = DIFF_FORMAT_RAW;
else
usage(builtin_diff_usage);
argv++; argc--;
Expand All @@ -185,14 +171,9 @@ static int builtin_diff_tree(struct rev_info *revs,
{
const unsigned char *(sha1[2]);
int swap = 0;
while (1 < argc) {
const char *arg = argv[1];
if (!strcmp(arg, "--raw"))
revs->diffopt.output_format = DIFF_FORMAT_RAW;
else
usage(builtin_diff_usage);
argv++; argc--;
}

if (argc > 1)
usage(builtin_diff_usage);

/* We saw two trees, ent[0] and ent[1].
* if ent[1] is unintesting, they are swapped
Expand All @@ -214,14 +195,9 @@ static int builtin_diff_combined(struct rev_info *revs,
const unsigned char (*parent)[20];
int i;

while (1 < argc) {
const char *arg = argv[1];
if (!strcmp(arg, "--raw"))
revs->diffopt.output_format = DIFF_FORMAT_RAW;
else
usage(builtin_diff_usage);
argv++; argc--;
}
if (argc > 1)
usage(builtin_diff_usage);

if (!revs->dense_combined_merges && !revs->combine_merges)
revs->dense_combined_merges = revs->combine_merges = 1;
parent = xmalloc(ents * sizeof(*parent));
Expand Down Expand Up @@ -276,9 +252,13 @@ int cmd_diff(int argc, const char **argv, char **envp)

git_config(git_diff_config);
init_revisions(&rev);
rev.diffopt.output_format = DIFF_FORMAT_PATCH;

argc = setup_revisions(argc, argv, &rev, NULL);
if (!rev.diffopt.output_format) {
rev.diffopt.output_format = DIFF_FORMAT_PATCH;
diff_setup_done(&rev.diffopt);
}

/* Do we have --cached and not have a pending object, then
* default to HEAD by hand. Eek.
*/
Expand Down
39 changes: 21 additions & 18 deletions builtin-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,22 @@
/* this is in builtin-diff.c */
void add_head(struct rev_info *revs);

static int cmd_log_wc(int argc, const char **argv, char **envp,
static void cmd_log_init(int argc, const char **argv, char **envp,
struct rev_info *rev)
{
struct commit *commit;

rev->abbrev = DEFAULT_ABBREV;
rev->commit_format = CMIT_FMT_DEFAULT;
rev->verbose_header = 1;
argc = setup_revisions(argc, argv, rev, "HEAD");
if (rev->always_show_header) {
if (rev->diffopt.pickaxe || rev->diffopt.filter) {
rev->always_show_header = 0;
if (rev->diffopt.output_format == DIFF_FORMAT_RAW)
rev->diffopt.output_format = DIFF_FORMAT_NO_OUTPUT;
}
}

if (rev->diffopt.pickaxe || rev->diffopt.filter)
rev->always_show_header = 0;
if (argc > 1)
die("unrecognized argument: %s", argv[1]);
}

static int cmd_log_walk(struct rev_info *rev)
{
struct commit *commit;

prepare_revision_walk(rev);
setup_pager();
Expand All @@ -54,7 +51,10 @@ int cmd_whatchanged(int argc, const char **argv, char **envp)
rev.diff = 1;
rev.diffopt.recursive = 1;
rev.simplify_history = 0;
return cmd_log_wc(argc, argv, envp, &rev);
cmd_log_init(argc, argv, envp, &rev);
if (!rev.diffopt.output_format)
rev.diffopt.output_format = DIFF_FORMAT_RAW;
return cmd_log_walk(&rev);
}

int cmd_show(int argc, const char **argv, char **envp)
Expand All @@ -69,7 +69,8 @@ int cmd_show(int argc, const char **argv, char **envp)
rev.always_show_header = 1;
rev.ignore_merges = 0;
rev.no_walk = 1;
return cmd_log_wc(argc, argv, envp, &rev);
cmd_log_init(argc, argv, envp, &rev);
return cmd_log_walk(&rev);
}

int cmd_log(int argc, const char **argv, char **envp)
Expand All @@ -78,8 +79,8 @@ int cmd_log(int argc, const char **argv, char **envp)

init_revisions(&rev);
rev.always_show_header = 1;
rev.diffopt.recursive = 1;
return cmd_log_wc(argc, argv, envp, &rev);
cmd_log_init(argc, argv, envp, &rev);
return cmd_log_walk(&rev);
}

static int istitlechar(char c)
Expand Down Expand Up @@ -237,11 +238,10 @@ int cmd_format_patch(int argc, const char **argv, char **envp)
rev.commit_format = CMIT_FMT_EMAIL;
rev.verbose_header = 1;
rev.diff = 1;
rev.diffopt.with_raw = 0;
rev.diffopt.with_stat = 1;
rev.combine_merges = 0;
rev.ignore_merges = 1;
rev.diffopt.output_format = DIFF_FORMAT_PATCH;
rev.diffopt.msg_sep = "";
rev.diffopt.recursive = 1;

git_config(git_format_config);
rev.extra_headers = extra_headers;
Expand Down Expand Up @@ -312,6 +312,9 @@ int cmd_format_patch(int argc, const char **argv, char **envp)
if (argc > 1)
die ("unrecognized argument: %s", argv[1]);

if (!rev.diffopt.output_format)
rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH;

if (output_directory) {
if (use_stdout)
die("standard output, or directory, which one?");
Expand Down
68 changes: 34 additions & 34 deletions combine-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
const char *abb;

if (rev->loginfo)
show_log(rev, rev->loginfo, "\n");
show_log(rev, opt->msg_sep);
dump_quoted_path(dense ? "diff --cc " : "diff --combined ", elem->path);
printf("index ");
for (i = 0; i < num_parent; i++) {
Expand Down Expand Up @@ -770,9 +770,9 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re
inter_name_termination = 0;

if (rev->loginfo)
show_log(rev, rev->loginfo, "\n");
show_log(rev, opt->msg_sep);

if (opt->output_format == DIFF_FORMAT_RAW) {
if (opt->output_format & DIFF_FORMAT_RAW) {
offset = strlen(COLONS) - num_parent;
if (offset < 0)
offset = 0;
Expand All @@ -792,8 +792,7 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re
printf(" %s ", diff_unique_abbrev(p->sha1, opt->abbrev));
}

if (opt->output_format == DIFF_FORMAT_RAW ||
opt->output_format == DIFF_FORMAT_NAME_STATUS) {
if (opt->output_format & (DIFF_FORMAT_RAW | DIFF_FORMAT_NAME_STATUS)) {
for (i = 0; i < num_parent; i++)
putchar(p->parent[i].status);
putchar(inter_name_termination);
Expand All @@ -819,17 +818,12 @@ void show_combined_diff(struct combine_diff_path *p,
struct diff_options *opt = &rev->diffopt;
if (!p->len)
return;
switch (opt->output_format) {
case DIFF_FORMAT_RAW:
case DIFF_FORMAT_NAME_STATUS:
case DIFF_FORMAT_NAME:
if (opt->output_format & (DIFF_FORMAT_RAW |
DIFF_FORMAT_NAME |
DIFF_FORMAT_NAME_STATUS)) {
show_raw_diff(p, num_parent, rev);
return;
case DIFF_FORMAT_PATCH:
} else if (opt->output_format & DIFF_FORMAT_PATCH) {
show_patch_diff(p, num_parent, dense, rev);
return;
default:
return;
}
}

Expand All @@ -842,35 +836,33 @@ void diff_tree_combined(const unsigned char *sha1,
struct diff_options *opt = &rev->diffopt;
struct diff_options diffopts;
struct combine_diff_path *p, *paths = NULL;
int i, num_paths;
int do_diffstat;
int i, num_paths, needsep, show_log_first;

do_diffstat = (opt->output_format == DIFF_FORMAT_DIFFSTAT ||
opt->with_stat);
diffopts = *opt;
diffopts.with_raw = 0;
diffopts.with_stat = 0;
diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
diffopts.recursive = 1;

show_log_first = !!rev->loginfo;
needsep = 0;
/* find set of paths that everybody touches */
for (i = 0; i < num_parent; i++) {
/* show stat against the first parent even
* when doing combined diff.
*/
if (i == 0 && do_diffstat)
if (i == 0 && opt->output_format & DIFF_FORMAT_DIFFSTAT)
diffopts.output_format = DIFF_FORMAT_DIFFSTAT;
else
diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
diff_tree_sha1(parent[i], sha1, "", &diffopts);
diffcore_std(&diffopts);
paths = intersect_paths(paths, i, num_parent);

if (do_diffstat && rev->loginfo)
show_log(rev, rev->loginfo,
opt->with_stat ? "---\n" : "\n");
if (show_log_first && i == 0) {
show_log(rev, opt->msg_sep);
if (rev->verbose_header && opt->output_format)
putchar(opt->line_termination);
}
diff_flush(&diffopts);
if (opt->with_stat)
putchar('\n');
}

/* find out surviving paths */
Expand All @@ -879,17 +871,25 @@ void diff_tree_combined(const unsigned char *sha1,
num_paths++;
}
if (num_paths) {
if (opt->with_raw) {
int saved_format = opt->output_format;
opt->output_format = DIFF_FORMAT_RAW;
if (opt->output_format & (DIFF_FORMAT_RAW |
DIFF_FORMAT_NAME |
DIFF_FORMAT_NAME_STATUS)) {
for (p = paths; p; p = p->next) {
show_combined_diff(p, num_parent, dense, rev);
if (p->len)
show_raw_diff(p, num_parent, rev);
}
opt->output_format = saved_format;
putchar(opt->line_termination);
needsep = 1;
}
for (p = paths; p; p = p->next) {
show_combined_diff(p, num_parent, dense, rev);
else if (opt->output_format & DIFF_FORMAT_DIFFSTAT)
needsep = 1;
if (opt->output_format & DIFF_FORMAT_PATCH) {
if (needsep)
putchar(opt->line_termination);
for (p = paths; p; p = p->next) {
if (p->len)
show_patch_diff(p, num_parent, dense,
rev);
}
}
}

Expand Down
Loading

0 comments on commit 0c926a3

Please sign in to comment.