summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3453300)
raw | patch | inline | side by side (parent: 3453300)
author | René Scharfe <rene.scharfe@lsrfire.ath.cx> | |
Mon, 14 Jul 2008 19:22:12 +0000 (21:22 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 15 Jul 2008 14:17:59 +0000 (07:17 -0700) |
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>
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>
archive-tar.c | patch | blob | history | |
archive-zip.c | patch | blob | history | |
builtin-checkout.c | patch | blob | history | |
builtin-log.c | patch | blob | history | |
builtin-ls-tree.c | patch | blob | history | |
builtin-merge-recursive.c | patch | blob | history | |
tree.c | patch | blob | history | |
tree.h | patch | blob | history |
diff --git a/archive-tar.c b/archive-tar.c
index 99db58f1cf21ee30f150c54acd6ffefbb14b6f57..6eaf59eb01d7bb180d8cc0a8c099fe8a533d28f6 100644 (file)
--- a/archive-tar.c
+++ b/archive-tar.c
return git_default_config(var, value, cb);
}
-static int write_tar_entry(const unsigned char *sha1,
- const char *base, int baselen,
- const char *filename, unsigned mode, int stage)
+static int write_tar_entry(const unsigned char *sha1, const char *base,
+ int baselen, const char *filename, unsigned mode, int stage,
+ void *context)
{
static struct strbuf path = STRBUF_INIT;
void *buffer;
while (baselen > 0 && base[baselen - 1] == '/')
base[--baselen] = '\0';
- write_tar_entry(args->tree->object.sha1, "", 0, base, 040777, 0);
+ write_tar_entry(args->tree->object.sha1, "", 0, base, 040777,
+ 0, NULL);
free(base);
}
read_tree_recursive(args->tree, args->base, plen, 0,
- args->pathspec, write_tar_entry);
+ args->pathspec, write_tar_entry, NULL);
write_trailer();
return 0;
diff --git a/archive-zip.c b/archive-zip.c
index 5742762ac30c92e796255b74d2ed1ea087f3fba0..0d24f3fe379417c43f3a48ba7cffc606c90aa9ad 100644 (file)
--- a/archive-zip.c
+++ b/archive-zip.c
return path;
}
-static int write_zip_entry(const unsigned char *sha1,
- const char *base, int baselen,
- const char *filename, unsigned mode, int stage)
+static int write_zip_entry(const unsigned char *sha1, const char *base,
+ int baselen, const char *filename, unsigned mode, int stage,
+ void *context)
{
struct zip_local_header header;
struct zip_dir_header dirent;
while (baselen > 0 && base[baselen - 1] == '/')
base[--baselen] = '\0';
- write_zip_entry(args->tree->object.sha1, "", 0, base, 040777, 0);
+ write_zip_entry(args->tree->object.sha1, "", 0, base, 040777,
+ 0, NULL);
free(base);
}
read_tree_recursive(args->tree, args->base, plen, 0,
- args->pathspec, write_zip_entry);
+ args->pathspec, write_zip_entry, NULL);
write_zip_trailer(args->commit_sha1);
free(zip_dir);
diff --git a/builtin-checkout.c b/builtin-checkout.c
index d6641c2c562c6b35bfed1cd3053945b460472581..fbd5105a8302a6c00e191ef49f3dfef1fc979c53 100644 (file)
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
}
static int update_some(const unsigned char *sha1, const char *base, int baselen,
- const char *pathname, unsigned mode, int stage)
+ const char *pathname, unsigned mode, int stage, void *context)
{
int len;
struct cache_entry *ce;
static int read_tree_some(struct tree *tree, const char **pathspec)
{
- read_tree_recursive(tree, "", 0, 0, pathspec, update_some);
+ read_tree_recursive(tree, "", 0, 0, pathspec, update_some, NULL);
/* update the index with the given tree's info
* for all args, expanding wildcards, and exit
diff --git a/builtin-log.c b/builtin-log.c
index 430d87661e37a4b08963de1ee5c31b8143ebc373..617aa67f2b2d1fd82c34eea62fd73145ff646ae0 100644 (file)
--- a/builtin-log.c
+++ b/builtin-log.c
static int show_tree_object(const unsigned char *sha1,
const char *base, int baselen,
- const char *pathname, unsigned mode, int stage)
+ const char *pathname, unsigned mode, int stage, void *context)
{
printf("%s%s\n", pathname, S_ISDIR(mode) ? "/" : "");
return 0;
name,
diff_get_color_opt(&rev.diffopt, DIFF_RESET));
read_tree_recursive((struct tree *)o, "", 0, 0, NULL,
- show_tree_object);
+ show_tree_object, NULL);
break;
case OBJ_COMMIT:
rev.pending.nr = rev.pending.alloc = 0;
diff --git a/builtin-ls-tree.c b/builtin-ls-tree.c
index f4a75ddbc3fecb9c1690a94d39ce230e82fefd8d..0da047c3bd40f4a7db43f70e2e00c0adcf673188 100644 (file)
--- a/builtin-ls-tree.c
+++ b/builtin-ls-tree.c
}
static int show_tree(const unsigned char *sha1, const char *base, int baselen,
- const char *pathname, unsigned mode, int stage)
+ const char *pathname, unsigned mode, int stage, void *context)
{
int retval = 0;
const char *type = blob_type;
tree = parse_tree_indirect(sha1);
if (!tree)
die("not a tree object");
- read_tree_recursive(tree, "", 0, 0, pathspec, show_tree);
+ read_tree_recursive(tree, "", 0, 0, pathspec, show_tree, NULL);
return 0;
}
index 43bf6aa45eeacbb67490c809070f40023ce4e434..385e742eefb6f62b58705dfb98a977bdc76ea4d2 100644 (file)
static int save_files_dirs(const unsigned char *sha1,
const char *base, int baselen, const char *path,
- unsigned int mode, int stage)
+ unsigned int mode, int stage, void *context)
{
int len = strlen(path);
char *newpath = xmalloc(baselen + len + 1);
static int get_files_dirs(struct tree *tree)
{
int n;
- if (read_tree_recursive(tree, "", 0, 0, NULL, save_files_dirs) != 0)
+ if (read_tree_recursive(tree, "", 0, 0, NULL, save_files_dirs, NULL))
return 0;
n = current_file_set.nr + current_directory_set.nr;
return n;
index 4b1825c2adac94ad806d729862c90cf8dfa37e9a..03e782a9cabc0a12ed5baec0ef59c99f19dbc843 100644 (file)
--- a/tree.c
+++ b/tree.c
return add_cache_entry(ce, opt);
}
-static int read_one_entry(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage)
+static int read_one_entry(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage, void *context)
{
return read_one_entry_opt(sha1, base, baselen, pathname, mode, stage,
ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK);
* This is used when the caller knows there is no existing entries at
* the stage that will conflict with the entry being added.
*/
-static int read_one_entry_quick(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage)
+static int read_one_entry_quick(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage, void *context)
{
return read_one_entry_opt(sha1, base, baselen, pathname, mode, stage,
ADD_CACHE_JUST_APPEND);
int read_tree_recursive(struct tree *tree,
const char *base, int baselen,
int stage, const char **match,
- read_tree_fn_t fn)
+ read_tree_fn_t fn, void *context)
{
struct tree_desc desc;
struct name_entry entry;
if (!match_tree_entry(base, baselen, entry.path, entry.mode, match))
continue;
- switch (fn(entry.sha1, base, baselen, entry.path, entry.mode, stage)) {
+ switch (fn(entry.sha1, base, baselen, entry.path, entry.mode, stage, context)) {
case 0:
continue;
case READ_TREE_RECURSIVE:
retval = read_tree_recursive(lookup_tree(entry.sha1),
newbase,
baselen + pathlen + 1,
- stage, match, fn);
+ stage, match, fn, context);
free(newbase);
if (retval)
return -1;
if (!fn)
fn = read_one_entry_quick;
- err = read_tree_recursive(tree, "", 0, stage, match, fn);
+ err = read_tree_recursive(tree, "", 0, stage, match, fn, NULL);
if (fn == read_one_entry || err)
return err;
index dd25c539efbb0ab018caa4cda2d133285634e9b5..2ff01a4f839ecc2206fcc1c13fee9d5d202b1128 100644 (file)
--- a/tree.h
+++ b/tree.h
struct tree *parse_tree_indirect(const unsigned char *sha1);
#define READ_TREE_RECURSIVE 1
-typedef int (*read_tree_fn_t)(const unsigned char *, const char *, int, const char *, unsigned int, int);
+typedef int (*read_tree_fn_t)(const unsigned char *, const char *, int, const char *, unsigned int, int, void *);
extern int read_tree_recursive(struct tree *tree,
const char *base, int baselen,
int stage, const char **match,
- read_tree_fn_t fn);
+ read_tree_fn_t fn, void *context);
extern int read_tree(struct tree *tree, int stage, const char **paths);