Skip to content

Commit 6d46a23

Browse files
author
Junio C Hamano
committed
Merge branch 'master' into jc/diff
* master: Make "--parents" logs also be incremental Retire diffcore-pathspec. Improve the git-diff-tree -c/-cc documentation
2 parents 52b70d5 + 5910e99 commit 6d46a23

File tree

10 files changed

+45
-108
lines changed

10 files changed

+45
-108
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ LIB_H = \
197197
tree-walk.h log-tree.h
198198

199199
DIFF_OBJS = \
200-
diff.o diffcore-break.o diffcore-order.o diffcore-pathspec.o \
200+
diff.o diffcore-break.o diffcore-order.o \
201201
diffcore-pickaxe.o diffcore-rename.o tree-diff.o combine-diff.o \
202202
diffcore-delta.o log-tree.o
203203

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: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,8 +1375,6 @@ static void diffcore_apply_filter(const char *filter)
13751375

13761376
void diffcore_std(struct diff_options *options)
13771377
{
1378-
if (options->paths && options->paths[0])
1379-
diffcore_pathspec(options->paths);
13801378
if (options->break_opt != -1)
13811379
diffcore_break(options->break_opt);
13821380
if (options->detect_rename)

diff.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ 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;

diffcore-pathspec.c

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

http-push.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ enum XML_Status {
5959
#define LOCK_TIME 600
6060
#define LOCK_REFRESH 30
6161

62-
/* bits #0-4 in revision.h */
62+
/* bits #0-6 in revision.h */
6363

64-
#define LOCAL (1u << 5)
65-
#define REMOTE (1u << 6)
66-
#define FETCHING (1u << 7)
67-
#define PUSHING (1u << 8)
64+
#define LOCAL (1u << 7)
65+
#define REMOTE (1u << 8)
66+
#define FETCHING (1u << 9)
67+
#define PUSHING (1u << 10)
6868

6969
/* We allow "recursive" symbolic refs. Only within reason, though */
7070
#define MAXDEPTH 5

rev-list.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
#include "tree-walk.h"
88
#include "revision.h"
99

10-
/* bits #0-5 in revision.h */
10+
/* bits #0-6 in revision.h */
1111

12-
#define COUNTED (1u<<6)
12+
#define COUNTED (1u<<7)
1313

1414
static const char rev_list_usage[] =
1515
"git-rev-list [OPTION] <commit-id>... [ -- paths... ]\n"

revision.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,10 @@ static void add_parents_to_list(struct rev_info *revs, struct commit *commit, st
340340
{
341341
struct commit_list *parent = commit->parents;
342342

343+
if (commit->object.flags & ADDED)
344+
return;
345+
commit->object.flags |= ADDED;
346+
343347
/*
344348
* If the commit is uninteresting, don't try to
345349
* prune parents - we want the maximal uninteresting
@@ -705,13 +709,6 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
705709
if (revs->prune_data) {
706710
diff_tree_setup_paths(revs->prune_data);
707711
revs->prune_fn = try_to_simplify_commit;
708-
709-
/*
710-
* If we fix up parent data, we currently cannot
711-
* do that on-the-fly.
712-
*/
713-
if (revs->parents)
714-
revs->limited = 1;
715712
}
716713

717714
return left;
@@ -728,10 +725,12 @@ void prepare_revision_walk(struct rev_info *revs)
728725
revs->topo_getter);
729726
}
730727

731-
static int rewrite_one(struct commit **pp)
728+
static int rewrite_one(struct rev_info *revs, struct commit **pp)
732729
{
733730
for (;;) {
734731
struct commit *p = *pp;
732+
if (!revs->limited)
733+
add_parents_to_list(revs, p, &revs->commits);
735734
if (p->object.flags & (TREECHANGE | UNINTERESTING))
736735
return 0;
737736
if (!p->parents)
@@ -740,12 +739,12 @@ static int rewrite_one(struct commit **pp)
740739
}
741740
}
742741

743-
static void rewrite_parents(struct commit *commit)
742+
static void rewrite_parents(struct rev_info *revs, struct commit *commit)
744743
{
745744
struct commit_list **pp = &commit->parents;
746745
while (*pp) {
747746
struct commit_list *parent = *pp;
748-
if (rewrite_one(&parent->item) < 0) {
747+
if (rewrite_one(revs, &parent->item) < 0) {
749748
*pp = parent->next;
750749
continue;
751750
}
@@ -802,7 +801,7 @@ struct commit *get_revision(struct rev_info *revs)
802801
if (!(commit->object.flags & TREECHANGE))
803802
continue;
804803
if (revs->parents)
805-
rewrite_parents(commit);
804+
rewrite_parents(revs, commit);
806805
}
807806
commit->object.flags |= SHOWN;
808807
return commit;

revision.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define SHOWN (1u<<3)
88
#define TMP_MARK (1u<<4) /* for isolated cases; clean after use */
99
#define BOUNDARY (1u<<5)
10+
#define ADDED (1u<<6) /* Parents already parsed and added? */
1011

1112
struct rev_info;
1213

0 commit comments

Comments
 (0)