Skip to content

Commit c4e05b1

Browse files
author
Junio C Hamano
committed
blame and friends: adjust to multiple pathspec change.
This makes things that include revision.h build again. Blame is also built, but I am not sure how well it works (or how well it worked to begin with) -- it was relying on tree-diff to be using whatever pathspec was used the last time, which smells a bit suspicious. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 477f2b4 commit c4e05b1

File tree

6 files changed

+34
-23
lines changed

6 files changed

+34
-23
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

git.c

Lines changed: 1 addition & 1 deletion
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

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, &diff_opt);
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);

0 commit comments

Comments
 (0)