@matheusbsbs / matheus-bagliano / commits / c4e05b1a22
Fork 0

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>

Junio C Hamano committed Apr 10, 2006 at 18:14 UTC c4e05b1a2290c605e68e6dac5e2a580e6d4080b7
6 files changed +34 -23
blame.c
+14 -6
@@ -508,25 +508,33 @@ static void process_commits(struct rev_info *rev, const char *path,
508 static int compare_tree_path(struct rev_info* revs,
509 struct commit* c1, struct commit* c2)
510 {
511 + int ret;
512 const char* paths[2];
513 struct util_info* util = c2->object.util;
514 paths[0] = util->pathname;
515 paths[1] = NULL;
516
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;
522 }
523
524
525 static int same_tree_as_empty_path(struct rev_info *revs, struct tree* t1,
526 const char* path)
527 {
528 + int ret;
529 const char* paths[2];
530 paths[0] = path;
531 paths[1] = NULL;
532
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;
538 }
539
540 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)
554 diff_opts.recursive = 1;
555 diff_opts.detect_rename = DIFF_DETECT_RENAME;
556 paths[0] = NULL;
549 - diff_tree_setup_paths(paths);
557 + diff_tree_setup_paths(paths, &diff_opts);
558 if (diff_setup_done(&diff_opts) < 0)
559 die("diff_setup_done failed");
560
@@ -826,7 +834,7 @@ int main(int argc, const char **argv)
834
835 args[0] = filename;
836 args[1] = NULL;
829 - diff_tree_setup_paths(args);
837 + diff_tree_setup_paths(args, &rev.diffopt);
838 prepare_revision_walk(&rev);
839 process_commits(&rev, filename, &initial);
840
git.c
+1 -1
@@ -15,8 +15,8 @@
15
16 #include "cache.h"
17 #include "commit.h"
18 -#include "revision.h"
18 #include "diff.h"
19 +#include "revision.h"
20 #include "log-tree.h"
21
22 #ifndef PATH_MAX
http-push.c
+1
@@ -6,6 +6,7 @@
6 #include "blob.h"
7 #include "http.h"
8 #include "refs.h"
9 +#include "diff.h"
10 #include "revision.h"
11 #include "exec_cmd.h"
12
rev-list.c
+1
@@ -5,6 +5,7 @@
5 #include "tree.h"
6 #include "blob.h"
7 #include "tree-walk.h"
8 +#include "diff.h"
9 #include "revision.h"
10
11 /* bits #0-6 in revision.h */
revision.c
+12 -14
@@ -233,25 +233,20 @@ static void file_change(struct diff_options *options,
233 tree_difference = REV_TREE_DIFFERENT;
234 }
235
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)
237 {
238 if (!t1)
239 return REV_TREE_NEW;
240 if (!t2)
241 return REV_TREE_DIFFERENT;
242 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)
245 return REV_TREE_DIFFERENT;
246 return tree_difference;
247 }
248
254 -int rev_same_tree_as_empty(struct tree *t1)
249 +int rev_same_tree_as_empty(struct rev_info *revs, struct tree *t1)
250 {
251 int retval;
252 void *tree;
@@ -269,7 +264,7 @@ int rev_same_tree_as_empty(struct tree *t1)
264 empty.size = 0;
265
266 tree_difference = 0;
272 - retval = diff_tree(&empty, &real, "", &diff_opt);
267 + retval = diff_tree(&empty, &real, "", &revs->diffopt);
268 free(tree);
269
270 return retval >= 0 && !tree_difference;
@@ -284,7 +279,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
279 return;
280
281 if (!commit->parents) {
287 - if (!rev_same_tree_as_empty(commit->tree))
282 + if (!rev_same_tree_as_empty(revs, commit->tree))
283 commit->object.flags |= TREECHANGE;
284 return;
285 }
@@ -294,7 +289,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
289 struct commit *p = parent->item;
290
291 parse_commit(p);
297 - switch (rev_compare_tree(p->tree, commit->tree)) {
292 + switch (rev_compare_tree(revs, p->tree, commit->tree)) {
293 case REV_TREE_SAME:
294 if (p->object.flags & UNINTERESTING) {
295 /* Even if a merge with an uninteresting
@@ -312,7 +307,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
307
308 case REV_TREE_NEW:
309 if (revs->remove_empty_trees &&
315 - rev_same_tree_as_empty(p->tree)) {
310 + rev_same_tree_as_empty(revs, p->tree)) {
311 /* We are adding all the specified
312 * paths from this parent, so the
313 * history beyond this parent is not
@@ -484,6 +479,9 @@ static void handle_all(struct rev_info *revs, unsigned flags)
479 void init_revisions(struct rev_info *revs)
480 {
481 memset(revs, 0, sizeof(*revs));
482 + revs->diffopt.recursive = 1;
483 + revs->diffopt.add_remove = file_add_remove;
484 + revs->diffopt.change = file_change;
485 revs->lifo = 1;
486 revs->dense = 1;
487 revs->prefix = setup_git_directory();
@@ -707,7 +705,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
705 revs->limited = 1;
706
707 if (revs->prune_data) {
710 - diff_tree_setup_paths(revs->prune_data, &diff_opt);
708 + diff_tree_setup_paths(revs->prune_data, &revs->diffopt);
709 revs->prune_fn = try_to_simplify_commit;
710 }
711
revision.h
+5 -2
@@ -43,6 +43,9 @@ struct rev_info {
43 unsigned long max_age;
44 unsigned long min_age;
45
46 + /* paths limiting */
47 + struct diff_options diffopt;
48 +
49 topo_sort_set_fn_t topo_setter;
50 topo_sort_get_fn_t topo_getter;
51 };
@@ -52,8 +55,8 @@ struct rev_info {
55 #define REV_TREE_DIFFERENT 2
56
57 /* 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);
60
61 extern void init_revisions(struct rev_info *revs);
62 extern int setup_revisions(int argc, const char **argv, struct rev_info *revs, const char *def);