@matheusbsbs / matheus-bagliano / commits / 77882f60d9
Fork 0

Retire diffcore-pathspec.

Nobody except diff-stages used it -- the callers instead filtered the input to diffcore themselves. Make diff-stages do that as well and retire diffcore-pathspec. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Apr 10, 2006 at 15:57 UTC 77882f60d9df2fd410ba7d732b01738315643c05
5 files changed +11 -81
Makefile
+1 -1
@@ -197,7 +197,7 @@ LIB_H = \
197 tree-walk.h
198
199 DIFF_OBJS = \
200 - diff.o diffcore-break.o diffcore-order.o diffcore-pathspec.o \
200 + diff.o diffcore-break.o diffcore-order.o \
201 diffcore-pickaxe.o diffcore-rename.o tree-diff.o combine-diff.o \
202 diffcore-delta.o
203
diff-stages.c
+10 -7
@@ -11,15 +11,17 @@ static const char diff_stages_usage[] =
11 "git-diff-stages [<common diff options>] <stage1> <stage2> [<path>...]"
12 COMMON_DIFF_OPTIONS_HELP;
13
14 -static void diff_stages(int stage1, int stage2)
14 +static void diff_stages(int stage1, int stage2, const char **pathspec)
15 {
16 int i = 0;
17 while (i < active_nr) {
18 struct cache_entry *ce, *stages[4] = { NULL, };
19 struct cache_entry *one, *two;
20 const char *name;
21 - int len;
21 + int len, skip;
22 +
23 ce = active_cache[i];
24 + skip = !ce_path_match(ce, pathspec);
25 len = ce_namelen(ce);
26 name = ce->name;
27 for (;;) {
@@ -34,7 +36,8 @@ static void diff_stages(int stage1, int stage2)
36 }
37 one = stages[stage1];
38 two = stages[stage2];
37 - if (!one && !two)
39 +
40 + if (skip || (!one && !two))
41 continue;
42 if (!one)
43 diff_addremove(&diff_options, '+', ntohl(two->ce_mode),
@@ -54,8 +57,8 @@ static void diff_stages(int stage1, int stage2)
57 int main(int ac, const char **av)
58 {
59 int stage1, stage2;
57 -
58 - setup_git_directory();
60 + const char *prefix = setup_git_directory();
61 + const char **pathspec = NULL;
62
63 git_config(git_diff_config);
64 read_cache();
@@ -89,12 +92,12 @@ int main(int ac, const char **av)
92 usage(diff_stages_usage);
93
94 av += 3; /* The rest from av[0] are for paths restriction. */
92 - diff_options.paths = av;
95 + pathspec = get_pathspec(prefix, av);
96
97 if (diff_setup_done(&diff_options) < 0)
98 usage(diff_stages_usage);
99
97 - diff_stages(stage1, stage2);
100 + diff_stages(stage1, stage2, pathspec);
101 diffcore_std(&diff_options);
102 diff_flush(&diff_options);
103 return 0;
diff.c
-2
@@ -1375,8 +1375,6 @@ static void diffcore_apply_filter(const char *filter)
1375
1376 void diffcore_std(struct diff_options *options)
1377 {
1378 - if (options->paths && options->paths[0])
1379 - diffcore_pathspec(options->paths);
1378 if (options->break_opt != -1)
1379 diffcore_break(options->break_opt);
1380 if (options->detect_rename)
diff.h
-1
@@ -20,7 +20,6 @@ typedef void (*add_remove_fn_t)(struct diff_options *options,
20 const char *base, const char *path);
21
22 struct diff_options {
23 - const char **paths;
23 const char *filter;
24 const char *orderfile;
25 const char *pickaxe;
diffcore-pathspec.c deleted
-70
@@ -1,70 +0,0 @@
1 -/*
2 - * Copyright (C) 2005 Junio C Hamano
3 - */
4 -#include "cache.h"
5 -#include "diff.h"
6 -#include "diffcore.h"
7 -
8 -struct path_spec {
9 - const char *spec;
10 - int len;
11 -};
12 -
13 -static int matches_pathspec(const char *name, struct path_spec *s, int cnt)
14 -{
15 - int i;
16 - int namelen;
17 -
18 - if (cnt == 0)
19 - return 1;
20 -
21 - namelen = strlen(name);
22 - for (i = 0; i < cnt; i++) {
23 - int len = s[i].len;
24 - if (namelen < len)
25 - continue;
26 - if (memcmp(s[i].spec, name, len))
27 - continue;
28 - if (s[i].spec[len-1] == '/' ||
29 - name[len] == 0 ||
30 - name[len] == '/')
31 - return 1;
32 - if (!len)
33 - return 1;
34 - }
35 - return 0;
36 -}
37 -
38 -void diffcore_pathspec(const char **pathspec)
39 -{
40 - struct diff_queue_struct *q = &diff_queued_diff;
41 - int i, speccnt;
42 - struct diff_queue_struct outq;
43 - struct path_spec *spec;
44 -
45 - outq.queue = NULL;
46 - outq.nr = outq.alloc = 0;
47 -
48 - for (i = 0; pathspec[i]; i++)
49 - ;
50 - speccnt = i;
51 - if (!speccnt)
52 - return;
53 -
54 - spec = xmalloc(sizeof(*spec) * speccnt);
55 - for (i = 0; pathspec[i]; i++) {
56 - spec[i].spec = pathspec[i];
57 - spec[i].len = strlen(pathspec[i]);
58 - }
59 -
60 - for (i = 0; i < q->nr; i++) {
61 - struct diff_filepair *p = q->queue[i];
62 - if (matches_pathspec(p->two->path, spec, speccnt))
63 - diff_q(&outq, p);
64 - else
65 - diff_free_filepair(p);
66 - }
67 - free(q->queue);
68 - *q = outq;
69 - return;
70 -}