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>
This commit is contained in:
parent
621f1b4bcf
commit
d3bee161fe
@ -132,7 +132,7 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
|
|||||||
err = write_entry(args, sha1, path.buf, path.len, mode, NULL, 0);
|
err = write_entry(args, sha1, path.buf, path.len, mode, NULL, 0);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
return READ_TREE_RECURSIVE;
|
return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = sha1_file_to_archive(path_without_prefix, sha1, mode,
|
buffer = sha1_file_to_archive(path_without_prefix, sha1, mode,
|
||||||
|
@ -68,13 +68,8 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen,
|
|||||||
*
|
*
|
||||||
* Something similar to this incomplete example:
|
* Something similar to this incomplete example:
|
||||||
*
|
*
|
||||||
if (show_subprojects(base, baselen, pathname)) {
|
if (show_subprojects(base, baselen, pathname))
|
||||||
struct child_process ls_tree;
|
retval = READ_TREE_RECURSIVE;
|
||||||
|
|
||||||
ls_tree.dir = base;
|
|
||||||
ls_tree.argv = ls-tree;
|
|
||||||
start_command(&ls_tree);
|
|
||||||
}
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
type = commit_type;
|
type = commit_type;
|
||||||
|
@ -237,7 +237,7 @@ static int save_files_dirs(const unsigned char *sha1,
|
|||||||
string_list_insert(newpath, &o->current_file_set);
|
string_list_insert(newpath, &o->current_file_set);
|
||||||
free(newpath);
|
free(newpath);
|
||||||
|
|
||||||
return READ_TREE_RECURSIVE;
|
return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_files_dirs(struct merge_options *o, struct tree *tree)
|
static int get_files_dirs(struct merge_options *o, struct tree *tree)
|
||||||
|
28
tree.c
28
tree.c
@ -131,6 +131,34 @@ int read_tree_recursive(struct tree *tree,
|
|||||||
if (retval)
|
if (retval)
|
||||||
return -1;
|
return -1;
|
||||||
continue;
|
continue;
|
||||||
|
} else if (S_ISGITLINK(entry.mode)) {
|
||||||
|
int retval;
|
||||||
|
struct strbuf path;
|
||||||
|
unsigned int entrylen;
|
||||||
|
struct commit *commit;
|
||||||
|
|
||||||
|
entrylen = tree_entry_len(entry.path, entry.sha1);
|
||||||
|
strbuf_init(&path, baselen + entrylen + 1);
|
||||||
|
strbuf_add(&path, base, baselen);
|
||||||
|
strbuf_add(&path, entry.path, entrylen);
|
||||||
|
strbuf_addch(&path, '/');
|
||||||
|
|
||||||
|
commit = lookup_commit(entry.sha1);
|
||||||
|
if (!commit)
|
||||||
|
die("Commit %s in submodule path %s not found",
|
||||||
|
sha1_to_hex(entry.sha1), path.buf);
|
||||||
|
|
||||||
|
if (parse_commit(commit))
|
||||||
|
die("Invalid commit %s in submodule path %s",
|
||||||
|
sha1_to_hex(entry.sha1), path.buf);
|
||||||
|
|
||||||
|
retval = read_tree_recursive(commit->tree,
|
||||||
|
path.buf, path.len,
|
||||||
|
stage, match, fn, context);
|
||||||
|
strbuf_release(&path);
|
||||||
|
if (retval)
|
||||||
|
return -1;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user