Skip to content

Commit 4da8cbc

Browse files
author
Junio C Hamano
committed
Merge branch 'jc/diff' into next
* jc/diff: blame and friends: adjust to multiple pathspec change. git log --full-diff tree-diff: do not assume we use only one pathspec
2 parents b5b1442 + c4e05b1 commit 4da8cbc

File tree

9 files changed

+77
-47
lines changed

9 files changed

+77
-47
lines changed

blame.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -508,25 +508,33 @@ static void process_commits(struct rev_info *rev, const char *path,
508508
static int compare_tree_path(struct rev_info* revs,
509509
struct commit* c1, struct commit* c2)
510510
{
511+
int ret;
511512
const char* paths[2];
512513
struct util_info* util = c2->object.util;
513514
paths[0] = util->pathname;
514515
paths[1] = NULL;
515516

516-
diff_tree_setup_paths(get_pathspec(revs->prefix, paths));
517-
return rev_compare_tree(c1->tree, c2->tree);
517+
diff_tree_setup_paths(get_pathspec(revs->prefix, paths),
518+
&revs->diffopt);
519+
ret = rev_compare_tree(revs, c1->tree, c2->tree);
520+
diff_tree_release_paths(&revs->diffopt);
521+
return ret;
518522
}
519523

520524

521525
static int same_tree_as_empty_path(struct rev_info *revs, struct tree* t1,
522526
const char* path)
523527
{
528+
int ret;
524529
const char* paths[2];
525530
paths[0] = path;
526531
paths[1] = NULL;
527532

528-
diff_tree_setup_paths(get_pathspec(revs->prefix, paths));
529-
return rev_same_tree_as_empty(t1);
533+
diff_tree_setup_paths(get_pathspec(revs->prefix, paths),
534+
&revs->diffopt);
535+
ret = rev_same_tree_as_empty(revs, t1);
536+
diff_tree_release_paths(&revs->diffopt);
537+
return ret;
530538
}
531539

532540
static const char* find_rename(struct commit* commit, struct commit* parent)
@@ -546,7 +554,7 @@ static const char* find_rename(struct commit* commit, struct commit* parent)
546554
diff_opts.recursive = 1;
547555
diff_opts.detect_rename = DIFF_DETECT_RENAME;
548556
paths[0] = NULL;
549-
diff_tree_setup_paths(paths);
557+
diff_tree_setup_paths(paths, &diff_opts);
550558
if (diff_setup_done(&diff_opts) < 0)
551559
die("diff_setup_done failed");
552560

@@ -826,7 +834,7 @@ int main(int argc, const char **argv)
826834

827835
args[0] = filename;
828836
args[1] = NULL;
829-
diff_tree_setup_paths(args);
837+
diff_tree_setup_paths(args, &rev.diffopt);
830838
prepare_revision_walk(&rev);
831839
process_commits(&rev, filename, &initial);
832840

diff-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ int main(int argc, const char **argv)
120120
if (opt->diffopt.output_format == DIFF_FORMAT_PATCH)
121121
opt->diffopt.recursive = 1;
122122

123-
diff_tree_setup_paths(get_pathspec(prefix, argv));
123+
diff_tree_setup_paths(get_pathspec(prefix, argv), opt);
124124
diff_setup_done(&opt->diffopt);
125125

126126
switch (nr_sha1) {

diff.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@ struct diff_options {
3939
int setup;
4040
int abbrev;
4141

42+
int nr_paths;
43+
const char **paths;
44+
int *pathlens;
4245
change_fn_t change;
4346
add_remove_fn_t add_remove;
4447
};
4548

46-
extern void diff_tree_setup_paths(const char **paths);
49+
extern void diff_tree_setup_paths(const char **paths, struct diff_options *);
50+
extern void diff_tree_release_paths(struct diff_options *);
4751
extern int diff_tree(struct tree_desc *t1, struct tree_desc *t2,
4852
const char *base, struct diff_options *opt);
4953
extern int diff_tree_sha1(const unsigned char *old, const unsigned char *new,

git.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
#include "cache.h"
1717
#include "commit.h"
18-
#include "revision.h"
1918
#include "diff.h"
19+
#include "revision.h"
2020
#include "log-tree.h"
2121

2222
#ifndef PATH_MAX
@@ -288,7 +288,9 @@ static int cmd_log(int argc, const char **argv, char **envp)
288288
int abbrev_commit = 0;
289289
const char *commit_prefix = "commit ";
290290
struct log_tree_opt opt;
291+
int shown = 0;
291292
int do_diff = 0;
293+
int full_diff = 0;
292294

293295
init_log_tree_opt(&opt);
294296
argc = setup_revisions(argc, argv, &rev, "HEAD");
@@ -315,6 +317,10 @@ static int cmd_log(int argc, const char **argv, char **envp)
315317
else if (40 < abbrev)
316318
abbrev = 40;
317319
}
320+
else if (!strcmp(arg, "--full-diff")) {
321+
do_diff = 1;
322+
full_diff = 1;
323+
}
318324
else {
319325
int cnt = log_tree_opt_parse(&opt, argv+1, argc-1);
320326
if (0 < cnt) {
@@ -328,6 +334,7 @@ static int cmd_log(int argc, const char **argv, char **envp)
328334

329335
argc--; argv++;
330336
}
337+
331338
if (do_diff) {
332339
opt.diffopt.abbrev = abbrev;
333340
opt.verbose_header = 0;
@@ -339,12 +346,16 @@ static int cmd_log(int argc, const char **argv, char **envp)
339346
opt.diffopt.output_format = DIFF_FORMAT_PATCH;
340347
if (opt.diffopt.output_format == DIFF_FORMAT_PATCH)
341348
opt.diffopt.recursive = 1;
349+
if (!full_diff && rev.prune_data)
350+
diff_tree_setup_paths(rev.prune_data, &opt.diffopt);
342351
diff_setup_done(&opt.diffopt);
343352
}
344353

345354
prepare_revision_walk(&rev);
346355
setup_pager();
347356
while ((commit = get_revision(&rev)) != NULL) {
357+
if (commit_format != CMIT_FMT_ONELINE && shown)
358+
putchar('\n');
348359
fputs(commit_prefix, stdout);
349360
if (abbrev_commit && abbrev)
350361
fputs(find_unique_abbrev(commit->object.sha1, abbrev),
@@ -377,9 +388,9 @@ static int cmd_log(int argc, const char **argv, char **envp)
377388
pretty_print_commit(commit_format, commit, ~0, buf,
378389
LOGSIZE, abbrev);
379390
printf("%s\n", buf);
380-
381391
if (do_diff)
382392
log_tree_commit(&opt, commit);
393+
shown = 1;
383394
}
384395
free(buf);
385396
return 0;

http-push.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "blob.h"
77
#include "http.h"
88
#include "refs.h"
9+
#include "diff.h"
910
#include "revision.h"
1011
#include "exec_cmd.h"
1112

rev-list.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "tree.h"
66
#include "blob.h"
77
#include "tree-walk.h"
8+
#include "diff.h"
89
#include "revision.h"
910

1011
/* bits #0-6 in revision.h */

revision.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -233,25 +233,20 @@ static void file_change(struct diff_options *options,
233233
tree_difference = REV_TREE_DIFFERENT;
234234
}
235235

236-
static struct diff_options diff_opt = {
237-
.recursive = 1,
238-
.add_remove = file_add_remove,
239-
.change = file_change,
240-
};
241-
242-
int rev_compare_tree(struct tree *t1, struct tree *t2)
236+
int rev_compare_tree(struct rev_info *revs, struct tree *t1, struct tree *t2)
243237
{
244238
if (!t1)
245239
return REV_TREE_NEW;
246240
if (!t2)
247241
return REV_TREE_DIFFERENT;
248242
tree_difference = REV_TREE_SAME;
249-
if (diff_tree_sha1(t1->object.sha1, t2->object.sha1, "", &diff_opt) < 0)
243+
if (diff_tree_sha1(t1->object.sha1, t2->object.sha1, "",
244+
&revs->diffopt) < 0)
250245
return REV_TREE_DIFFERENT;
251246
return tree_difference;
252247
}
253248

254-
int rev_same_tree_as_empty(struct tree *t1)
249+
int rev_same_tree_as_empty(struct rev_info *revs, struct tree *t1)
255250
{
256251
int retval;
257252
void *tree;
@@ -269,7 +264,7 @@ int rev_same_tree_as_empty(struct tree *t1)
269264
empty.size = 0;
270265

271266
tree_difference = 0;
272-
retval = diff_tree(&empty, &real, "", &diff_opt);
267+
retval = diff_tree(&empty, &real, "", &revs->diffopt);
273268
free(tree);
274269

275270
return retval >= 0 && !tree_difference;
@@ -284,7 +279,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
284279
return;
285280

286281
if (!commit->parents) {
287-
if (!rev_same_tree_as_empty(commit->tree))
282+
if (!rev_same_tree_as_empty(revs, commit->tree))
288283
commit->object.flags |= TREECHANGE;
289284
return;
290285
}
@@ -294,7 +289,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
294289
struct commit *p = parent->item;
295290

296291
parse_commit(p);
297-
switch (rev_compare_tree(p->tree, commit->tree)) {
292+
switch (rev_compare_tree(revs, p->tree, commit->tree)) {
298293
case REV_TREE_SAME:
299294
if (p->object.flags & UNINTERESTING) {
300295
/* Even if a merge with an uninteresting
@@ -312,7 +307,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
312307

313308
case REV_TREE_NEW:
314309
if (revs->remove_empty_trees &&
315-
rev_same_tree_as_empty(p->tree)) {
310+
rev_same_tree_as_empty(revs, p->tree)) {
316311
/* We are adding all the specified
317312
* paths from this parent, so the
318313
* history beyond this parent is not
@@ -484,6 +479,9 @@ static void handle_all(struct rev_info *revs, unsigned flags)
484479
void init_revisions(struct rev_info *revs)
485480
{
486481
memset(revs, 0, sizeof(*revs));
482+
revs->diffopt.recursive = 1;
483+
revs->diffopt.add_remove = file_add_remove;
484+
revs->diffopt.change = file_change;
487485
revs->lifo = 1;
488486
revs->dense = 1;
489487
revs->prefix = setup_git_directory();
@@ -707,7 +705,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
707705
revs->limited = 1;
708706

709707
if (revs->prune_data) {
710-
diff_tree_setup_paths(revs->prune_data);
708+
diff_tree_setup_paths(revs->prune_data, &revs->diffopt);
711709
revs->prune_fn = try_to_simplify_commit;
712710
}
713711

revision.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ struct rev_info {
4343
unsigned long max_age;
4444
unsigned long min_age;
4545

46+
/* paths limiting */
47+
struct diff_options diffopt;
48+
4649
topo_sort_set_fn_t topo_setter;
4750
topo_sort_get_fn_t topo_getter;
4851
};
@@ -52,8 +55,8 @@ struct rev_info {
5255
#define REV_TREE_DIFFERENT 2
5356

5457
/* revision.c */
55-
extern int rev_same_tree_as_empty(struct tree *t1);
56-
extern int rev_compare_tree(struct tree *t1, struct tree *t2);
58+
extern int rev_same_tree_as_empty(struct rev_info *, struct tree *t1);
59+
extern int rev_compare_tree(struct rev_info *, struct tree *t1, struct tree *t2);
5760

5861
extern void init_revisions(struct rev_info *revs);
5962
extern int setup_revisions(int argc, const char **argv, struct rev_info *revs, const char *def);

tree-diff.c

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
#include "diff.h"
66
#include "tree.h"
77

8-
// What paths are we interested in?
9-
static int nr_paths = 0;
10-
static const char **paths = NULL;
11-
static int *pathlens = NULL;
12-
138
static char *malloc_base(const char *base, const char *path, int pathlen)
149
{
1510
int baselen = strlen(base);
@@ -72,24 +67,24 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, const
7267
return 0;
7368
}
7469

75-
static int interesting(struct tree_desc *desc, const char *base)
70+
static int interesting(struct tree_desc *desc, const char *base, struct diff_options *opt)
7671
{
7772
const char *path;
7873
unsigned mode;
7974
int i;
8075
int baselen, pathlen;
8176

82-
if (!nr_paths)
77+
if (!opt->nr_paths)
8378
return 1;
8479

8580
(void)tree_entry_extract(desc, &path, &mode);
8681

8782
pathlen = strlen(path);
8883
baselen = strlen(base);
8984

90-
for (i=0; i < nr_paths; i++) {
91-
const char *match = paths[i];
92-
int matchlen = pathlens[i];
85+
for (i=0; i < opt->nr_paths; i++) {
86+
const char *match = opt->paths[i];
87+
int matchlen = opt->pathlens[i];
9388

9489
if (baselen >= matchlen) {
9590
/* If it doesn't match, move along... */
@@ -129,7 +124,7 @@ static int interesting(struct tree_desc *desc, const char *base)
129124
static void show_tree(struct diff_options *opt, const char *prefix, struct tree_desc *desc, const char *base)
130125
{
131126
while (desc->size) {
132-
if (interesting(desc, base))
127+
if (interesting(desc, base, opt))
133128
show_entry(opt, prefix, desc, base);
134129
update_tree_entry(desc);
135130
}
@@ -167,11 +162,11 @@ static int show_entry(struct diff_options *opt, const char *prefix, struct tree_
167162
int diff_tree(struct tree_desc *t1, struct tree_desc *t2, const char *base, struct diff_options *opt)
168163
{
169164
while (t1->size | t2->size) {
170-
if (nr_paths && t1->size && !interesting(t1, base)) {
165+
if (opt->nr_paths && t1->size && !interesting(t1, base, opt)) {
171166
update_tree_entry(t1);
172167
continue;
173168
}
174-
if (nr_paths && t2->size && !interesting(t2, base)) {
169+
if (opt->nr_paths && t2->size && !interesting(t2, base, opt)) {
175170
update_tree_entry(t2);
176171
continue;
177172
}
@@ -229,19 +224,28 @@ static int count_paths(const char **paths)
229224
return i;
230225
}
231226

232-
void diff_tree_setup_paths(const char **p)
227+
void diff_tree_release_paths(struct diff_options *opt)
233228
{
229+
free(opt->pathlens);
230+
}
231+
232+
void diff_tree_setup_paths(const char **p, struct diff_options *opt)
233+
{
234+
opt->nr_paths = 0;
235+
opt->pathlens = NULL;
236+
opt->paths = NULL;
237+
234238
if (p) {
235239
int i;
236240

237-
paths = p;
238-
nr_paths = count_paths(paths);
239-
if (nr_paths == 0) {
240-
pathlens = NULL;
241+
opt->paths = p;
242+
opt->nr_paths = count_paths(p);
243+
if (opt->nr_paths == 0) {
244+
opt->pathlens = NULL;
241245
return;
242246
}
243-
pathlens = xmalloc(nr_paths * sizeof(int));
244-
for (i=0; i<nr_paths; i++)
245-
pathlens[i] = strlen(paths[i]);
247+
opt->pathlens = xmalloc(opt->nr_paths * sizeof(int));
248+
for (i=0; i < opt->nr_paths; i++)
249+
opt->pathlens[i] = strlen(p[i]);
246250
}
247251
}

0 commit comments

Comments
 (0)