From: Lars Hjemli <hjemli@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
"René Scharfe" <rene.scharfe@lsrfire.ath.cx>
Subject: [RFC/PATCH v3 1/3] tree.c: teach read_tree_recursive how to traverse gitlink entries
Date: Thu, 22 Jan 2009 22:17:49 +0100 [thread overview]
Message-ID: <1232659071-14401-2-git-send-email-hjemli@gmail.com> (raw)
In-Reply-To: <1232659071-14401-1-git-send-email-hjemli@gmail.com>
When the callback function invoked from read_tree_recursive() returns
`READ_TREE_RECURSIVE` for a gitlink entry, the traversal will now
continue into the tree connected to the gitlinked commit. It is the
responsibility of the callback function to somehow make the gitlinked
commit (and corresponding tree/blob) objects available, possibly by
inserting the submodule object database as an alternate odb.
Also, all existing callback function has been updated to only return
READ_TREE_RECURSIVE for directory entries, so this patch should not
introduce any changes to current behavior.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
archive.c | 2 +-
builtin-ls-tree.c | 9 ++-------
merge-recursive.c | 2 +-
tree.c | 28 ++++++++++++++++++++++++++++
4 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/archive.c b/archive.c
index 9ac455d..e6de039 100644
--- a/archive.c
+++ b/archive.c
@@ -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);
if (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,
diff --git a/builtin-ls-tree.c b/builtin-ls-tree.c
index 5b63e6e..fca4631 100644
--- a/builtin-ls-tree.c
+++ b/builtin-ls-tree.c
@@ -68,13 +68,8 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen,
*
* Something similar to this incomplete example:
*
- if (show_subprojects(base, baselen, pathname)) {
- struct child_process ls_tree;
-
- ls_tree.dir = base;
- ls_tree.argv = ls-tree;
- start_command(&ls_tree);
- }
+ if (show_subprojects(base, baselen, pathname))
+ retval = READ_TREE_RECURSIVE;
*
*/
type = commit_type;
diff --git a/merge-recursive.c b/merge-recursive.c
index b97026b..ee853b9 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -237,7 +237,7 @@ static int save_files_dirs(const unsigned char *sha1,
string_list_insert(newpath, &o->current_file_set);
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)
diff --git a/tree.c b/tree.c
index 03e782a..dfe4d5f 100644
--- a/tree.c
+++ b/tree.c
@@ -131,6 +131,34 @@ int read_tree_recursive(struct tree *tree,
if (retval)
return -1;
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;
--
1.6.1.150.g5e733b
next prev parent reply other threads:[~2009-01-22 21:20 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-22 21:17 [RFC/PATCH v3 0/3] Add support for `git archive --submodules` Lars Hjemli
2009-01-22 21:17 ` Lars Hjemli [this message]
2009-01-22 21:17 ` [RFC/PATCH v3 2/3] sha1_file: prepare for adding alternates on demand Lars Hjemli
2009-01-22 21:17 ` [RFC/PATCH v3 3/3] archive.c: add basic support for submodules Lars Hjemli
2009-01-22 23:44 ` Johannes Schindelin
2009-01-23 18:40 ` Lars Hjemli
2009-01-23 19:23 ` Junio C Hamano
2009-01-23 20:15 ` Lars Hjemli
2009-01-23 20:50 ` Junio C Hamano
2009-01-23 21:15 ` Lars Hjemli
2009-01-23 19:57 ` Johannes Schindelin
2009-01-24 8:44 ` Lars Hjemli
2009-01-24 13:51 ` Johannes Schindelin
2009-01-24 19:26 ` Lars Hjemli
2009-01-24 19:52 ` Johannes Schindelin
2009-01-24 20:02 ` Lars Hjemli
2009-01-22 23:43 ` [RFC/PATCH v3 2/3] sha1_file: prepare for adding alternates on demand Johannes Schindelin
2009-01-23 18:35 ` Lars Hjemli
2009-01-23 19:54 ` Johannes Schindelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1232659071-14401-2-git-send-email-hjemli@gmail.com \
--to=hjemli@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=rene.scharfe@lsrfire.ath.cx \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).