Skip to content

Commit 6b32ee2

Browse files
author
Junio C Hamano
committed
Merge branch 'jc/withraw' into next
* jc/withraw: diff-* --patch-with-raw Retire git-log.sh (take#2) Retire git-log.sh Retire diffcore-pathspec. Improve the git-diff-tree -c/-cc documentation
2 parents 910a591 + 86ff1d2 commit 6b32ee2

File tree

7 files changed

+95
-125
lines changed

7 files changed

+95
-125
lines changed

Documentation/git-diff-tree.txt

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ separated with a single space are given.
6060
-m::
6161
By default, "git-diff-tree --stdin" does not show
6262
differences for merge commits. With this flag, it shows
63-
differences to that commit from all of its parents.
63+
differences to that commit from all of its parents. See
64+
also '-c'.
6465

6566
-s::
6667
By default, "git-diff-tree --stdin" shows differences,
@@ -81,19 +82,25 @@ separated with a single space are given.
8182
git-diff-tree outputs a line with the commit ID when
8283
applicable. This flag suppressed the commit ID output.
8384

84-
-c,--cc::
85-
These flags change the way a merge commit is displayed
85+
-c::
86+
This flag changes the way a merge commit is displayed
8687
(which means it is useful only when the command is given
8788
one <tree-ish>, or '--stdin'). It shows the differences
88-
from each of the parents to the merge result
89-
simultaneously, instead of showing pairwise diff between
90-
a parent and the result one at a time, which '-m' option
91-
output does. '--cc' further compresses the output by
92-
omiting hunks that show differences from only one
89+
from each of the parents to the merge result simultaneously
90+
instead of showing pairwise diff between a parent and the
91+
result one at a time (which is what the '-m' option does).
92+
Furthermore, it lists only files which were modified
93+
from all parents.
94+
95+
-cc::
96+
This flag changes the way a merge commit patch is displayed,
97+
in a similar way to the '-c' option. It implies the '-c'
98+
and '-p' options and further compresses the patch output
99+
by omitting hunks that show differences from only one
93100
parent, or show the same change from all but one parent
94101
for an Octopus merge. When this optimization makes all
95102
hunks disappear, the commit itself and the commit log
96-
message is not shown, just like any other "empty diff" cases.
103+
message is not shown, just like in any other "empty diff" case.
97104

98105
--always::
99106
Show the commit itself and the commit log message even

Makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ SCRIPT_SH = \
116116
git-add.sh git-bisect.sh git-branch.sh git-checkout.sh \
117117
git-cherry.sh git-clean.sh git-clone.sh git-commit.sh \
118118
git-count-objects.sh git-diff.sh git-fetch.sh \
119-
git-format-patch.sh git-log.sh git-ls-remote.sh \
119+
git-format-patch.sh git-ls-remote.sh \
120120
git-merge-one-file.sh git-parse-remote.sh \
121121
git-prune.sh git-pull.sh git-push.sh git-rebase.sh \
122122
git-repack.sh git-request-pull.sh git-reset.sh \
@@ -167,8 +167,10 @@ PROGRAMS = \
167167
git-name-rev$X git-pack-redundant$X git-repo-config$X git-var$X \
168168
git-describe$X git-merge-tree$X git-blame$X git-imap-send$X
169169

170+
BUILT_INS = git-log$X
171+
170172
# what 'all' will build and 'install' will install, in gitexecdir
171-
ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS)
173+
ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(BUILT_INS) $(SCRIPTS)
172174

173175
# Backward compatibility -- to be removed after 1.0
174176
PROGRAMS += git-ssh-pull$X git-ssh-push$X
@@ -197,7 +199,7 @@ LIB_H = \
197199
tree-walk.h log-tree.h
198200

199201
DIFF_OBJS = \
200-
diff.o diffcore-break.o diffcore-order.o diffcore-pathspec.o \
202+
diff.o diffcore-break.o diffcore-order.o \
201203
diffcore-pickaxe.o diffcore-rename.o tree-diff.o combine-diff.o \
202204
diffcore-delta.o log-tree.o
203205

@@ -461,6 +463,9 @@ git$X: git.c common-cmds.h $(GITLIBS)
461463
$(ALL_CFLAGS) -o $@ $(filter %.c,$^) \
462464
$(ALL_LDFLAGS) $(LIBS)
463465

466+
$(BUILT_INS): git$X
467+
rm -f $@ && ln git$X $@
468+
464469
common-cmds.h: Documentation/git-*.txt
465470
./generate-cmdlist.sh > $@
466471

combine-diff.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,7 @@ const char *diff_tree_combined_merge(const unsigned char *sha1,
832832

833833
diffopts = *opt;
834834
diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
835+
diffopts.with_raw = 0;
835836
diffopts.recursive = 1;
836837

837838
/* count parents */
@@ -858,6 +859,16 @@ const char *diff_tree_combined_merge(const unsigned char *sha1,
858859
num_paths++;
859860
}
860861
if (num_paths) {
862+
if (opt->with_raw) {
863+
int saved_format = opt->output_format;
864+
opt->output_format = DIFF_FORMAT_RAW;
865+
for (p = paths; p; p = p->next) {
866+
if (show_combined_diff(p, num_parent, dense,
867+
header, opt))
868+
header = NULL;
869+
}
870+
opt->output_format = saved_format;
871+
}
861872
for (p = paths; p; p = p->next) {
862873
if (show_combined_diff(p, num_parent, dense,
863874
header, opt))

diff-stages.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ static const char diff_stages_usage[] =
1111
"git-diff-stages [<common diff options>] <stage1> <stage2> [<path>...]"
1212
COMMON_DIFF_OPTIONS_HELP;
1313

14-
static void diff_stages(int stage1, int stage2)
14+
static void diff_stages(int stage1, int stage2, const char **pathspec)
1515
{
1616
int i = 0;
1717
while (i < active_nr) {
1818
struct cache_entry *ce, *stages[4] = { NULL, };
1919
struct cache_entry *one, *two;
2020
const char *name;
21-
int len;
21+
int len, skip;
22+
2223
ce = active_cache[i];
24+
skip = !ce_path_match(ce, pathspec);
2325
len = ce_namelen(ce);
2426
name = ce->name;
2527
for (;;) {
@@ -34,7 +36,8 @@ static void diff_stages(int stage1, int stage2)
3436
}
3537
one = stages[stage1];
3638
two = stages[stage2];
37-
if (!one && !two)
39+
40+
if (skip || (!one && !two))
3841
continue;
3942
if (!one)
4043
diff_addremove(&diff_options, '+', ntohl(two->ce_mode),
@@ -54,8 +57,8 @@ static void diff_stages(int stage1, int stage2)
5457
int main(int ac, const char **av)
5558
{
5659
int stage1, stage2;
57-
58-
setup_git_directory();
60+
const char *prefix = setup_git_directory();
61+
const char **pathspec = NULL;
5962

6063
git_config(git_diff_config);
6164
read_cache();
@@ -89,12 +92,12 @@ int main(int ac, const char **av)
8992
usage(diff_stages_usage);
9093

9194
av += 3; /* The rest from av[0] are for paths restriction. */
92-
diff_options.paths = av;
95+
pathspec = get_pathspec(prefix, av);
9396

9497
if (diff_setup_done(&diff_options) < 0)
9598
usage(diff_stages_usage);
9699

97-
diff_stages(stage1, stage2);
100+
diff_stages(stage1, stage2, pathspec);
98101
diffcore_std(&diff_options);
99102
diff_flush(&diff_options);
100103
return 0;

diff.c

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
862862
const char *arg = av[0];
863863
if (!strcmp(arg, "-p") || !strcmp(arg, "-u"))
864864
options->output_format = DIFF_FORMAT_PATCH;
865+
else if (!strcmp(arg, "--patch-with-raw")) {
866+
options->output_format = DIFF_FORMAT_PATCH;
867+
options->with_raw = 1;
868+
}
865869
else if (!strcmp(arg, "-z"))
866870
options->line_termination = 0;
867871
else if (!strncmp(arg, "-l", 2))
@@ -1048,13 +1052,13 @@ const char *diff_unique_abbrev(const unsigned char *sha1, int len)
10481052
static void diff_flush_raw(struct diff_filepair *p,
10491053
int line_termination,
10501054
int inter_name_termination,
1051-
struct diff_options *options)
1055+
struct diff_options *options,
1056+
int output_format)
10521057
{
10531058
int two_paths;
10541059
char status[10];
10551060
int abbrev = options->abbrev;
10561061
const char *path_one, *path_two;
1057-
int output_format = options->output_format;
10581062

10591063
path_one = p->one->path;
10601064
path_two = p->two->path;
@@ -1270,46 +1274,58 @@ static void diff_resolve_rename_copy(void)
12701274
diff_debug_queue("resolve-rename-copy done", q);
12711275
}
12721276

1273-
void diff_flush(struct diff_options *options)
1277+
static void flush_one_pair(struct diff_filepair *p,
1278+
int diff_output_format,
1279+
struct diff_options *options)
12741280
{
1275-
struct diff_queue_struct *q = &diff_queued_diff;
1276-
int i;
12771281
int inter_name_termination = '\t';
1278-
int diff_output_format = options->output_format;
12791282
int line_termination = options->line_termination;
1280-
12811283
if (!line_termination)
12821284
inter_name_termination = 0;
12831285

1284-
for (i = 0; i < q->nr; i++) {
1285-
struct diff_filepair *p = q->queue[i];
1286-
1287-
switch (p->status) {
1288-
case DIFF_STATUS_UNKNOWN:
1286+
switch (p->status) {
1287+
case DIFF_STATUS_UNKNOWN:
1288+
break;
1289+
case 0:
1290+
die("internal error in diff-resolve-rename-copy");
1291+
break;
1292+
default:
1293+
switch (diff_output_format) {
1294+
case DIFF_FORMAT_PATCH:
1295+
diff_flush_patch(p, options);
12891296
break;
1290-
case 0:
1291-
die("internal error in diff-resolve-rename-copy");
1297+
case DIFF_FORMAT_RAW:
1298+
case DIFF_FORMAT_NAME_STATUS:
1299+
diff_flush_raw(p, line_termination,
1300+
inter_name_termination,
1301+
options, diff_output_format);
1302+
break;
1303+
case DIFF_FORMAT_NAME:
1304+
diff_flush_name(p,
1305+
inter_name_termination,
1306+
line_termination);
1307+
break;
1308+
case DIFF_FORMAT_NO_OUTPUT:
12921309
break;
1293-
default:
1294-
switch (diff_output_format) {
1295-
case DIFF_FORMAT_PATCH:
1296-
diff_flush_patch(p, options);
1297-
break;
1298-
case DIFF_FORMAT_RAW:
1299-
case DIFF_FORMAT_NAME_STATUS:
1300-
diff_flush_raw(p, line_termination,
1301-
inter_name_termination,
1302-
options);
1303-
break;
1304-
case DIFF_FORMAT_NAME:
1305-
diff_flush_name(p,
1306-
inter_name_termination,
1307-
line_termination);
1308-
break;
1309-
case DIFF_FORMAT_NO_OUTPUT:
1310-
break;
1311-
}
13121310
}
1311+
}
1312+
}
1313+
1314+
void diff_flush(struct diff_options *options)
1315+
{
1316+
struct diff_queue_struct *q = &diff_queued_diff;
1317+
int i;
1318+
int diff_output_format = options->output_format;
1319+
1320+
if (options->with_raw) {
1321+
for (i = 0; i < q->nr; i++) {
1322+
struct diff_filepair *p = q->queue[i];
1323+
flush_one_pair(p, DIFF_FORMAT_RAW, options);
1324+
}
1325+
}
1326+
for (i = 0; i < q->nr; i++) {
1327+
struct diff_filepair *p = q->queue[i];
1328+
flush_one_pair(p, diff_output_format, options);
13131329
diff_free_filepair(p);
13141330
}
13151331
free(q->queue);
@@ -1375,8 +1391,6 @@ static void diffcore_apply_filter(const char *filter)
13751391

13761392
void diffcore_std(struct diff_options *options)
13771393
{
1378-
if (options->paths && options->paths[0])
1379-
diffcore_pathspec(options->paths);
13801394
if (options->break_opt != -1)
13811395
diffcore_break(options->break_opt);
13821396
if (options->detect_rename)

diff.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ typedef void (*add_remove_fn_t)(struct diff_options *options,
2020
const char *base, const char *path);
2121

2222
struct diff_options {
23-
const char **paths;
2423
const char *filter;
2524
const char *orderfile;
2625
const char *pickaxe;
2726
unsigned recursive:1,
27+
with_raw:1,
2828
tree_in_recursive:1,
2929
full_index:1;
3030
int break_opt;

diffcore-pathspec.c

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)