add context pointer to read_tree_recursive()
Add a pointer parameter to read_tree_recursive(), which is passed to the callback function. This allows callers of read_tree_recursive() to share data with the callback without resorting to global variables. All current callers pass NULL. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Jul 14, 2008 at 21:22 UTC
671f0707212c929533dc6ec9e032faee328e4602
8 files changed
+28
-26
archive-tar.c
+6
-5
@@ -234,9 +234,9 @@ static int git_tar_config(const char *var, const char *value, void *cb)
234
return git_default_config(var, value, cb);
235
}
236
237
-static int write_tar_entry(const unsigned char *sha1,
238
- const char *base, int baselen,
239
- const char *filename, unsigned mode, int stage)
237
+static int write_tar_entry(const unsigned char *sha1, const char *base,
238
+ int baselen, const char *filename, unsigned mode, int stage,
239
+ void *context)
240
{
241
static struct strbuf path = STRBUF_INIT;
242
void *buffer;
@@ -286,11 +286,12 @@ int write_tar_archive(struct archiver_args *args)
286
287
while (baselen > 0 && base[baselen - 1] == '/')
288
base[--baselen] = '\0';
289
- write_tar_entry(args->tree->object.sha1, "", 0, base, 040777, 0);
289
+ write_tar_entry(args->tree->object.sha1, "", 0, base, 040777,
290
+ 0, NULL);
291
free(base);
292
}
293
read_tree_recursive(args->tree, args->base, plen, 0,
293
- args->pathspec, write_tar_entry);
294
+ args->pathspec, write_tar_entry, NULL);
295
write_trailer();
296
297
return 0;
archive-zip.c
+6
-5
@@ -152,9 +152,9 @@ static char *construct_path(const char *base, int baselen,
152
return path;
153
}
154
155
-static int write_zip_entry(const unsigned char *sha1,
156
- const char *base, int baselen,
157
- const char *filename, unsigned mode, int stage)
155
+static int write_zip_entry(const unsigned char *sha1, const char *base,
156
+ int baselen, const char *filename, unsigned mode, int stage,
157
+ void *context)
158
{
159
struct zip_local_header header;
160
struct zip_dir_header dirent;
@@ -332,11 +332,12 @@ int write_zip_archive(struct archiver_args *args)
332
333
while (baselen > 0 && base[baselen - 1] == '/')
334
base[--baselen] = '\0';
335
- write_zip_entry(args->tree->object.sha1, "", 0, base, 040777, 0);
335
+ write_zip_entry(args->tree->object.sha1, "", 0, base, 040777,
336
+ 0, NULL);
337
free(base);
338
}
339
read_tree_recursive(args->tree, args->base, plen, 0,
339
- args->pathspec, write_zip_entry);
340
+ args->pathspec, write_zip_entry, NULL);
341
write_zip_trailer(args->commit_sha1);
342
343
free(zip_dir);
builtin-checkout.c
+2
-2
@@ -43,7 +43,7 @@ static int post_checkout_hook(struct commit *old, struct commit *new,
43
}
44
45
static int update_some(const unsigned char *sha1, const char *base, int baselen,
46
- const char *pathname, unsigned mode, int stage)
46
+ const char *pathname, unsigned mode, int stage, void *context)
47
{
48
int len;
49
struct cache_entry *ce;
@@ -67,7 +67,7 @@ static int update_some(const unsigned char *sha1, const char *base, int baselen,
67
68
static int read_tree_some(struct tree *tree, const char **pathspec)
69
{
70
- read_tree_recursive(tree, "", 0, 0, pathspec, update_some);
70
+ read_tree_recursive(tree, "", 0, 0, pathspec, update_some, NULL);
71
72
/* update the index with the given tree's info
73
* for all args, expanding wildcards, and exit
builtin-log.c
+2
-2
@@ -313,7 +313,7 @@ static int show_object(const unsigned char *sha1, int show_tag_object,
313
314
static int show_tree_object(const unsigned char *sha1,
315
const char *base, int baselen,
316
- const char *pathname, unsigned mode, int stage)
316
+ const char *pathname, unsigned mode, int stage, void *context)
317
{
318
printf("%s%s\n", pathname, S_ISDIR(mode) ? "/" : "");
319
return 0;
@@ -366,7 +366,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
366
name,
367
diff_get_color_opt(&rev.diffopt, DIFF_RESET));
368
read_tree_recursive((struct tree *)o, "", 0, 0, NULL,
369
- show_tree_object);
369
+ show_tree_object, NULL);
370
break;
371
case OBJ_COMMIT:
372
rev.pending.nr = rev.pending.alloc = 0;
builtin-ls-tree.c
+2
-2
@@ -56,7 +56,7 @@ static int show_recursive(const char *base, int baselen, const char *pathname)
56
}
57
58
static int show_tree(const unsigned char *sha1, const char *base, int baselen,
59
- const char *pathname, unsigned mode, int stage)
59
+ const char *pathname, unsigned mode, int stage, void *context)
60
{
61
int retval = 0;
62
const char *type = blob_type;
@@ -189,7 +189,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
189
tree = parse_tree_indirect(sha1);
190
if (!tree)
191
die("not a tree object");
192
- read_tree_recursive(tree, "", 0, 0, pathspec, show_tree);
192
+ read_tree_recursive(tree, "", 0, 0, pathspec, show_tree, NULL);
193
194
return 0;
195
}
builtin-merge-recursive.c
+2
-2
@@ -256,7 +256,7 @@ struct tree *write_tree_from_memory(void)
256
257
static int save_files_dirs(const unsigned char *sha1,
258
const char *base, int baselen, const char *path,
259
- unsigned int mode, int stage)
259
+ unsigned int mode, int stage, void *context)
260
{
261
int len = strlen(path);
262
char *newpath = xmalloc(baselen + len + 1);
@@ -276,7 +276,7 @@ static int save_files_dirs(const unsigned char *sha1,
276
static int get_files_dirs(struct tree *tree)
277
{
278
int n;
279
- if (read_tree_recursive(tree, "", 0, 0, NULL, save_files_dirs) != 0)
279
+ if (read_tree_recursive(tree, "", 0, 0, NULL, save_files_dirs, NULL))
280
return 0;
281
n = current_file_set.nr + current_directory_set.nr;
282
return n;
tree.c
+6
-6
@@ -29,7 +29,7 @@ static int read_one_entry_opt(const unsigned char *sha1, const char *base, int b
29
return add_cache_entry(ce, opt);
30
}
31
32
-static int read_one_entry(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage)
32
+static int read_one_entry(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage, void *context)
33
{
34
return read_one_entry_opt(sha1, base, baselen, pathname, mode, stage,
35
ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK);
@@ -39,7 +39,7 @@ static int read_one_entry(const unsigned char *sha1, const char *base, int basel
39
* This is used when the caller knows there is no existing entries at
40
* the stage that will conflict with the entry being added.
41
*/
42
-static int read_one_entry_quick(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage)
42
+static int read_one_entry_quick(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage, void *context)
43
{
44
return read_one_entry_opt(sha1, base, baselen, pathname, mode, stage,
45
ADD_CACHE_JUST_APPEND);
@@ -92,7 +92,7 @@ static int match_tree_entry(const char *base, int baselen, const char *path, uns
92
int read_tree_recursive(struct tree *tree,
93
const char *base, int baselen,
94
int stage, const char **match,
95
- read_tree_fn_t fn)
95
+ read_tree_fn_t fn, void *context)
96
{
97
struct tree_desc desc;
98
struct name_entry entry;
@@ -106,7 +106,7 @@ int read_tree_recursive(struct tree *tree,
106
if (!match_tree_entry(base, baselen, entry.path, entry.mode, match))
107
continue;
108
109
- switch (fn(entry.sha1, base, baselen, entry.path, entry.mode, stage)) {
109
+ switch (fn(entry.sha1, base, baselen, entry.path, entry.mode, stage, context)) {
110
case 0:
111
continue;
112
case READ_TREE_RECURSIVE:
@@ -126,7 +126,7 @@ int read_tree_recursive(struct tree *tree,
126
retval = read_tree_recursive(lookup_tree(entry.sha1),
127
newbase,
128
baselen + pathlen + 1,
129
- stage, match, fn);
129
+ stage, match, fn, context);
130
free(newbase);
131
if (retval)
132
return -1;
@@ -174,7 +174,7 @@ int read_tree(struct tree *tree, int stage, const char **match)
174
175
if (!fn)
176
fn = read_one_entry_quick;
177
- err = read_tree_recursive(tree, "", 0, stage, match, fn);
177
+ err = read_tree_recursive(tree, "", 0, stage, match, fn, NULL);
178
if (fn == read_one_entry || err)
179
return err;
180
tree.h
+2
-2
@@ -21,12 +21,12 @@ int parse_tree(struct tree *tree);
21
struct tree *parse_tree_indirect(const unsigned char *sha1);
22
23
#define READ_TREE_RECURSIVE 1
24
-typedef int (*read_tree_fn_t)(const unsigned char *, const char *, int, const char *, unsigned int, int);
24
+typedef int (*read_tree_fn_t)(const unsigned char *, const char *, int, const char *, unsigned int, int, void *);
25
26
extern int read_tree_recursive(struct tree *tree,
27
const char *base, int baselen,
28
int stage, const char **match,
29
- read_tree_fn_t fn);
29
+ read_tree_fn_t fn, void *context);
30
31
extern int read_tree(struct tree *tree, int stage, const char **paths);
32