From: Aaron Schrab <aaron@schrab.com>
To: git@vger.kernel.org
Cc: junio@pobox.com, jrnieder@gmail.com
Subject: [PATCH v3 2/2] clone: Allow repo using gitfile as a reference
Date: Tue, 9 Apr 2013 18:22:00 -0400 [thread overview]
Message-ID: <1365546120-22048-3-git-send-email-aaron@schrab.com> (raw)
In-Reply-To: <1365546120-22048-1-git-send-email-aaron@schrab.com>
Try reading gitfile files when processing --reference options to clone.
This will allow, among other things, using a submodule checked out with
a recent version of git as a reference repository without requiring the
user to have internal knowledge of submodule layout.
Signed-off-by: Aaron Schrab <aaron@schrab.com>
diff --git a/builtin/clone.c b/builtin/clone.c
index 0a1e0bf..58fee98 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -232,11 +232,21 @@ static void strip_trailing_slashes(char *dir)
static int add_one_reference(struct string_list_item *item, void *cb_data)
{
char *ref_git;
+ const char *repo;
struct strbuf alternate = STRBUF_INIT;
- /* Beware: real_path() and mkpath() return static buffer */
+ /* Beware: read_gitfile(), real_path() and mkpath() return static buffer */
ref_git = xstrdup(real_path(item->string));
- if (is_directory(mkpath("%s/.git/objects", ref_git))) {
+
+ repo = read_gitfile(ref_git);
+ if (!repo)
+ repo = read_gitfile(mkpath("%s/.git", ref_git));
+ if (repo) {
+ free(ref_git);
+ ref_git = xstrdup(repo);
+ }
+
+ if (!repo && is_directory(mkpath("%s/.git/objects", ref_git))) {
char *ref_git_git = mkpathdup("%s/.git", ref_git);
free(ref_git);
ref_git = ref_git_git;
diff --git a/t/t5700-clone-reference.sh b/t/t5700-clone-reference.sh
index 2a7b78b..719d778 100755
--- a/t/t5700-clone-reference.sh
+++ b/t/t5700-clone-reference.sh
@@ -185,4 +185,17 @@ test_expect_success 'fetch with incomplete alternates' '
! grep " want $tag_object" "$U.K"
'
+test_expect_success 'clone using repo with gitfile as a reference' '
+ git clone --separate-git-dir=L A M &&
+ git clone --reference=M A N &&
+ echo "$base_dir/L/objects" >expected &&
+ test_cmp expected "$base_dir/N/.git/objects/info/alternates"
+'
+
+test_expect_success 'clone using repo pointed at by gitfile as reference' '
+ git clone --reference=M/.git A O &&
+ echo "$base_dir/L/objects" >expected &&
+ test_cmp expected "$base_dir/O/.git/objects/info/alternates"
+'
+
test_done
--
1.8.2.677.g9202ef0
next prev parent reply other threads:[~2013-04-09 22:23 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-07 23:17 [PATCH 1/2] clone: Fix error message for reference repository Aaron Schrab
2013-04-07 23:17 ` [PATCH 2/2] clone: Allow repo using gitfile as a reference Aaron Schrab
2013-04-07 23:51 ` Jonathan Nieder
2013-04-08 0:08 ` Aaron Schrab
2013-04-08 18:00 ` Junio C Hamano
2013-04-08 18:59 ` Aaron Schrab
2013-04-08 22:46 ` [PATCH v2 0/2] Using gitfile repository with clone --reference Aaron Schrab
2013-04-08 22:46 ` [PATCH 1/2] clone: Fix error message for reference repository Aaron Schrab
2013-04-09 0:18 ` Jonathan Nieder
2013-04-08 22:46 ` [PATCH 2/2] clone: Allow repo using gitfile as a reference Aaron Schrab
2013-04-09 0:24 ` Jonathan Nieder
2013-04-09 16:31 ` Aaron Schrab
2013-04-09 16:47 ` Junio C Hamano
2013-04-09 16:50 ` Aaron Schrab
2013-04-09 22:21 ` [PATCH v3 0/2] Using gitfile repository with clone --reference Aaron Schrab
2013-04-09 22:21 ` [PATCH v3 1/2] clone: Fix error message for reference repository Aaron Schrab
2013-04-09 22:22 ` Aaron Schrab [this message]
2013-04-09 22:41 ` [PATCH v3 0/2] Using gitfile repository with clone --reference Junio C Hamano
2013-04-07 23:48 ` [PATCH 1/2] clone: Fix error message for reference repository Jonathan Nieder
2013-04-08 0:06 ` Aaron Schrab
2013-04-08 1:11 ` Aaron Schrab
2013-04-08 13:58 ` Junio C Hamano
2013-04-08 14:57 ` Aaron Schrab
2013-04-08 15:30 ` Junio C Hamano
2013-04-08 16:17 ` Aaron Schrab
2013-04-08 17:57 ` Junio C Hamano
2013-04-08 18:58 ` Aaron Schrab
2013-04-08 19:10 ` Junio C Hamano
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=1365546120-22048-3-git-send-email-aaron@schrab.com \
--to=aaron@schrab.com \
--cc=git@vger.kernel.org \
--cc=jrnieder@gmail.com \
--cc=junio@pobox.com \
/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).