tree.c: allow read_tree_recursive() to traverse gitlink entries
When the callback function invoked from read_tree_recursive() returns the value `READ_TREE_RECURSIVE` for a gitlink entry, the traversal will now continue into the tree connected to the gitlinked commit. This functionality can be used to allow inter-repository operations, but since the current users of read_tree_recursive() does not yet support such operations, they have been modified where necessary to make sure that they never return READ_TREE_RECURSIVE for gitlink entries (hence no change in behaviour should be introduces by this patch alone). Signed-off-by: Lars Hjemli <hjemli@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Lars Hjemli committed
Jan 25, 2009 at 01:52 UTC
d3bee161fef7820e83b44b899c531228a5546e87
4 files changed
+32
-9
archive.c
+1
-1
@@ -132,7 +132,7 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
132
err = write_entry(args, sha1, path.buf, path.len, mode, NULL, 0);
133
if (err)
134
return err;
135
- return READ_TREE_RECURSIVE;
135
+ return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0);
136
}
137
138
buffer = sha1_file_to_archive(path_without_prefix, sha1, mode,
builtin-ls-tree.c
+2
-7
@@ -68,13 +68,8 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen,
68
*
69
* Something similar to this incomplete example:
70
*
71
- if (show_subprojects(base, baselen, pathname)) {
72
- struct child_process ls_tree;
73
-
74
- ls_tree.dir = base;
75
- ls_tree.argv = ls-tree;
76
- start_command(&ls_tree);
77
- }
71
+ if (show_subprojects(base, baselen, pathname))
72
+ retval = READ_TREE_RECURSIVE;
73
*
74
*/
75
type = commit_type;
merge-recursive.c
+1
-1
@@ -237,7 +237,7 @@ static int save_files_dirs(const unsigned char *sha1,
237
string_list_insert(newpath, &o->current_file_set);
238
free(newpath);
239
240
- return READ_TREE_RECURSIVE;
240
+ return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0);
241
}
242
243
static int get_files_dirs(struct merge_options *o, struct tree *tree)
tree.c
+28
@@ -131,6 +131,34 @@ int read_tree_recursive(struct tree *tree,
131
if (retval)
132
return -1;
133
continue;
134
+ } else if (S_ISGITLINK(entry.mode)) {
135
+ int retval;
136
+ struct strbuf path;
137
+ unsigned int entrylen;
138
+ struct commit *commit;
139
+
140
+ entrylen = tree_entry_len(entry.path, entry.sha1);
141
+ strbuf_init(&path, baselen + entrylen + 1);
142
+ strbuf_add(&path, base, baselen);
143
+ strbuf_add(&path, entry.path, entrylen);
144
+ strbuf_addch(&path, '/');
145
+
146
+ commit = lookup_commit(entry.sha1);
147
+ if (!commit)
148
+ die("Commit %s in submodule path %s not found",
149
+ sha1_to_hex(entry.sha1), path.buf);
150
+
151
+ if (parse_commit(commit))
152
+ die("Invalid commit %s in submodule path %s",
153
+ sha1_to_hex(entry.sha1), path.buf);
154
+
155
+ retval = read_tree_recursive(commit->tree,
156
+ path.buf, path.len,
157
+ stage, match, fn, context);
158
+ strbuf_release(&path);
159
+ if (retval)
160
+ return -1;
161
+ continue;
162
}
163
}
164
return 0;