* [PATCH v2 0/1] git-clone: fix relative path problem in the alternates
@ 2011-08-22 9:05 Hui Wang
2011-08-22 9:05 ` [PATCH v2 1/1] clone: replace relative paths " Hui Wang
2011-08-22 19:10 ` [PATCH v2 0/1] git-clone: fix relative path problem " Junio C Hamano
0 siblings, 2 replies; 10+ messages in thread
From: Hui Wang @ 2011-08-22 9:05 UTC (permalink / raw)
To: gitster, git
Hi Junio,
In the V2 version, i use strbuf_xxxx() to help to parse alternates file
and change relative paths to absolute paths according to your suggestion,
now the strbuf operations are safer.
When updating new content to the lockfile, i choose to write whole content at
one time instead of update it line by line. The reason is:
1. we will conditionally update the lockfile, if original alternates doesn't
include relative path, we don't need to update the lockfile. This logic can't
easily be handled line by line.
2. current git system only provides add_to_alternates_file()in the sha1_file.c
to update lockfile, this function can add a line to lockfile but can't empty
and write lockfile, we need to add a similar function to empty and write to
lockfile, and we must guarantee the first line update will call this function,
then remaining update line call add_to_alternates_file(), this logic is a
little complicated comparing to update whole content at one time.
3. current existing add_to_alternates_file() will unconditionally append
"/objects" at each new added line, that need us to parse and remove
"/objects" from each line read out from source alternates, this is a little
bit complicated.
If we choose update lockfile at one time, we can add a new function to
implement this requirement and overcome all above complexity.
Hui Wang (1):
clone: replace relative paths in the alternates
builtin/clone.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
cache.h | 1 +
sha1_file.c | 11 +++++++++++
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 1/1] clone: replace relative paths in the alternates
2011-08-22 9:05 [PATCH v2 0/1] git-clone: fix relative path problem in the alternates Hui Wang
@ 2011-08-22 9:05 ` Hui Wang
2011-08-22 19:10 ` [PATCH v2 0/1] git-clone: fix relative path problem " Junio C Hamano
1 sibling, 0 replies; 10+ messages in thread
From: Hui Wang @ 2011-08-22 9:05 UTC (permalink / raw)
To: gitster, git
When we clone a local source repository to a new local destination
repository without "--shared" option, if source repository has
relative path in the alternates, the clone will fail.
The root cause is when cloning local source repository to local
destination repository, the alternates of the source repository
will be copied to the destination repository, the relative path in
the alternates is source repository to base repository rather than
destination repository to base repository, so the destination
repository get a wrong relative path in the alternates, this will
cause errors when refer to base repository in the destination
repository.
To fix it, adding a function update_alt_rel_path() to replace all
relative paths to absolute paths in the alternates of the destination
repository before destination repository use those paths to look for
the base repository.
Signed-off-by: Hui Wang <jason77.wang@gmail.com>
---
builtin/clone.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
cache.h | 1 +
sha1_file.c | 11 +++++++++++
3 files changed, 58 insertions(+), 1 deletions(-)
diff --git a/builtin/clone.c b/builtin/clone.c
index 7663bc2..7b5e603 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -286,6 +286,50 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest)
closedir(dir);
}
+/*
+ * This function is called by clone_local() of clone.c
+ * If alternates in the src_repo (source repository) has relative path,
+ * call this function will replace the relative path to absolute path
+ * in the des_repo (destination repository) alternates.
+ */
+static void update_alt_rel_path(const char *src_repo)
+{
+ int need_update = 0;
+ FILE *ifp;
+ struct strbuf istr = STRBUF_INIT;
+ struct strbuf ostr = STRBUF_INIT;
+
+ ifp = fopen(git_path("objects/info/alternates"), "r");
+ if (!ifp)
+ return;
+
+ while (strbuf_getline(&istr, ifp, '\n') != EOF) {
+ /* comment line, empty line or absolute path line */
+ if (istr.buf[0] == '#' || istr.len == 0 || is_absolute_path(istr.buf)) {
+ strbuf_add(&ostr, istr.buf, istr.len);
+ strbuf_add(&ostr, "\n", 1);
+ } else {
+ char *abs_path, abs_buf[PATH_MAX];
+ int len;
+
+ abs_path = mkpath("%s/objects/%s", src_repo, istr.buf);
+ normalize_path_copy(abs_buf, abs_path);
+ len = strlen(abs_buf);
+ strbuf_add(&ostr, abs_buf, len);
+ strbuf_add(&ostr, "\n", 1);
+ need_update = 1;
+ }
+ }
+
+ fclose(ifp);
+
+ if (need_update)
+ update_alternates_file_content(ostr.buf);
+
+ strbuf_release(&istr);
+ strbuf_release(&ostr);
+}
+
static const struct ref *clone_local(const char *src_repo,
const char *dest_repo)
{
@@ -303,8 +347,9 @@ static const struct ref *clone_local(const char *src_repo,
copy_or_link_directory(&src, &dest);
strbuf_release(&src);
strbuf_release(&dest);
- }
+ update_alt_rel_path(src_repo);
+ }
remote = remote_get(src_repo);
transport = transport_get(remote, src_repo);
ret = transport_get_remote_refs(transport);
diff --git a/cache.h b/cache.h
index fcf4501..d81c0f0 100644
--- a/cache.h
+++ b/cache.h
@@ -913,6 +913,7 @@ extern struct alternate_object_database {
} *alt_odb_list;
extern void prepare_alt_odb(void);
extern void add_to_alternates_file(const char *reference);
+extern void update_alternates_file_content(const char *content);
typedef int alt_odb_fn(struct alternate_object_database *, void *);
extern void foreach_alt_odb(alt_odb_fn, void*);
diff --git a/sha1_file.c b/sha1_file.c
index d5616dc..dae7bf6 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -388,6 +388,17 @@ void add_to_alternates_file(const char *reference)
link_alt_odb_entries(alt, alt + strlen(alt), '\n', NULL, 0);
}
+void update_alternates_file_content(const char *content)
+{
+ struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
+ int fd = hold_lock_file_for_update(lock, git_path("objects/info/alternates"), LOCK_DIE_ON_ERROR);
+ write_or_die(fd, content, strlen(content));
+ if (commit_lock_file(lock))
+ die("could not close alternates file");
+ if (alt_odb_tail)
+ link_alt_odb_entries(content, content + strlen(content), '\n', NULL, 0);
+}
+
void foreach_alt_odb(alt_odb_fn fn, void *cb)
{
struct alternate_object_database *ent;
--
1.7.6
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v2 0/1] git-clone: fix relative path problem in the alternates
2011-08-22 9:05 [PATCH v2 0/1] git-clone: fix relative path problem in the alternates Hui Wang
2011-08-22 9:05 ` [PATCH v2 1/1] clone: replace relative paths " Hui Wang
@ 2011-08-22 19:10 ` Junio C Hamano
2011-08-22 20:38 ` Junio C Hamano
1 sibling, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2011-08-22 19:10 UTC (permalink / raw)
To: Hui Wang; +Cc: git
Hui Wang <jason77.wang@gmail.com> writes:
> 2. current git system only provides add_to_alternates_file()in the sha1_file.c
> to update lockfile, this function can add a line to lockfile but can't empty
> and write lockfile,
I do not see the need for "empty and write" in the first place. You are
spending cycles to go through all the lines in the input, inspecting and
holding the replacement somewhere, it is a one-time cost for cloning, and
the alternates file wouldn't be humongous anyway, so I do not see the need
for "we don't touch if there is no relative path in the file" if it makes
the code more complex than a stupid "one line at a time" approach.
> 3. current existing add_to_alternates_file() will unconditionally append
> "/objects" at each new added line, that need us to parse and remove
> "/objects" from each line read out from source alternates, this is a little
> bit complicated.
Clone with --reference is the only other caller of that function; I would
say it is perfectly fine to make it the caller's responsibility to append
"/objects" if that makes the resulting code easier to maintain.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 0/1] git-clone: fix relative path problem in the alternates
2011-08-22 19:10 ` [PATCH v2 0/1] git-clone: fix relative path problem " Junio C Hamano
@ 2011-08-22 20:38 ` Junio C Hamano
2011-08-22 21:57 ` Junio C Hamano
0 siblings, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2011-08-22 20:38 UTC (permalink / raw)
To: Hui Wang; +Cc: git
Junio C Hamano <gitster@pobox.com> writes:
>> 3. current existing add_to_alternates_file() will unconditionally append
>> "/objects" at each new added line, that need us to parse and remove
>> "/objects" from each line read out from source alternates, this is a little
>> bit complicated.
>
> Clone with --reference is the only other caller of that function; I would
> say it is perfectly fine to make it the caller's responsibility to append
> "/objects" if that makes the resulting code easier to maintain.
I would further suggest moving add_to_alternates_file() from sha1_file.c
to builtin/clone.c and make it file-scope static function, and change the
way it should be used.
- The caller should first obtain a lock file to info/alternates. If it
truncates first or opens the file for appending is up to the caller.
- When adding an alternate (either from --reference or your new
codepath), the caller should give the lockfile instance it obtained
earlier, and a path to the object store it wants to borrow objects from
(not the repository, i.e. the caller should add "/objects" at the end
if needed before calling the function), to add_to_alternates_file()
function;
- The function should just write the path to the locked info/alternates
file, and link it to alt_odb list. Do not commit the alternates file,
to allow multiple calls to the function be made without opening and
closing the file number of times.
- The caller should commit the updated alternates file once it is done.
While at it, we may probably want to update the command option handling so
that you can give more than one --reference= parameters.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 0/1] git-clone: fix relative path problem in the alternates
2011-08-22 20:38 ` Junio C Hamano
@ 2011-08-22 21:57 ` Junio C Hamano
2011-08-23 1:05 ` [PATCH 0/2] clone-local fixup Junio C Hamano
0 siblings, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2011-08-22 21:57 UTC (permalink / raw)
To: Hui Wang; +Cc: git
Junio C Hamano <gitster@pobox.com> writes:
> While at it, we may probably want to update the command option handling so
> that you can give more than one --reference= parameters.
Geez. There appear to be more bugs in the existing code.
If you
- specify --reference;
- the source of the clone is a local directory;
- you do not specify --shared; and
- the source of the clone has its own alternates
we end up exercising this call flow:
init_db();
setup_reference();
-> add_to_alternates_file();
This writes objects/info/alternates in the new repository
clone_local();
-> copy_or_link_directory(src/objects, dst/objects);
-> copy_or_link_directory(src/objects/info, dst/objects/info);
-> unlink(dst/objects/info/alternates);
link(src/objects/info/alternates, dst/objects/info/alternates);
and lose the --reference given from the command line.
The problem you are trying to address is a valid one, but it needs to be
fixed by teaching copy-or-link-directory that objects/info/alternates is
special. We need a more proper fix than "just let the recursive copy do a
possibly wrong thing and then patch it up if it is wrong", which is the
approach taken by your patch.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 0/2] clone-local fixup
2011-08-22 21:57 ` Junio C Hamano
@ 2011-08-23 1:05 ` Junio C Hamano
2011-08-23 1:05 ` [PATCH 1/2] clone: allow more than one --reference Junio C Hamano
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Junio C Hamano @ 2011-08-23 1:05 UTC (permalink / raw)
To: git; +Cc: Hui Wang
So I ended up tackling this myself. I didn't bother moving the
add_to_alternates_file(), though.
Junio C Hamano (2):
clone: allow more than one --reference
clone: clone from a repository with relative alternates
builtin/clone.c | 82 +++++++++++++++++++++++++++++++++++++++++------------
sha1_file.c | 2 +-
t/t5601-clone.sh | 23 +++++++++++++++
3 files changed, 87 insertions(+), 20 deletions(-)
--
1.7.6.557.gcee42
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/2] clone: allow more than one --reference
2011-08-23 1:05 ` [PATCH 0/2] clone-local fixup Junio C Hamano
@ 2011-08-23 1:05 ` Junio C Hamano
2011-08-23 1:05 ` [PATCH 2/2] clone: clone from a repository with relative alternates Junio C Hamano
2011-08-23 3:43 ` [PATCH 0/2] clone-local fixup Hui Wang
2 siblings, 0 replies; 10+ messages in thread
From: Junio C Hamano @ 2011-08-23 1:05 UTC (permalink / raw)
To: git; +Cc: Hui Wang
Also add a test to expose a long-standing bug that is triggered when
cloning with --reference option from a local repository that has its own
alternates. The alternate object stores specified on the command line
are lost, and only alternates copied from the source repository remain.
The bug will be fixed in the next patch.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
builtin/clone.c | 32 ++++++++++++++++++++++++--------
t/t5601-clone.sh | 15 +++++++++++++++
2 files changed, 39 insertions(+), 8 deletions(-)
diff --git a/builtin/clone.c b/builtin/clone.c
index f579794..ee5d651 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -39,13 +39,23 @@ static const char * const builtin_clone_usage[] = {
static int option_no_checkout, option_bare, option_mirror;
static int option_local, option_no_hardlinks, option_shared, option_recursive;
-static char *option_template, *option_reference, *option_depth;
+static char *option_template, *option_depth;
static char *option_origin = NULL;
static char *option_branch = NULL;
static const char *real_git_dir;
static char *option_upload_pack = "git-upload-pack";
static int option_verbosity;
static int option_progress;
+static struct string_list option_reference;
+
+static int opt_parse_reference(const struct option *opt, const char *arg, int unset)
+{
+ struct string_list *option_reference = opt->value;
+ if (!arg)
+ return -1;
+ string_list_append(option_reference, arg);
+ return 0;
+}
static struct option builtin_clone_options[] = {
OPT__VERBOSITY(&option_verbosity),
@@ -71,8 +81,8 @@ static struct option builtin_clone_options[] = {
"initialize submodules in the clone"),
OPT_STRING(0, "template", &option_template, "template-directory",
"directory from which templates will be used"),
- OPT_STRING(0, "reference", &option_reference, "repo",
- "reference repository"),
+ OPT_CALLBACK(0 , "reference", &option_reference, "repo",
+ "reference repository", &opt_parse_reference),
OPT_STRING('o', "origin", &option_origin, "branch",
"use <branch> instead of 'origin' to track upstream"),
OPT_STRING('b', "branch", &option_branch, "branch",
@@ -197,7 +207,7 @@ static void strip_trailing_slashes(char *dir)
*end = '\0';
}
-static void setup_reference(const char *repo)
+static int add_one_reference(struct string_list_item *item, void *cb_data)
{
const char *ref_git;
char *ref_git_copy;
@@ -206,13 +216,13 @@ static void setup_reference(const char *repo)
struct transport *transport;
const struct ref *extra;
- ref_git = real_path(option_reference);
+ ref_git = real_path(item->string);
if (is_directory(mkpath("%s/.git/objects", ref_git)))
ref_git = mkpath("%s/.git", ref_git);
else if (!is_directory(mkpath("%s/objects", ref_git)))
die(_("reference repository '%s' is not a local directory."),
- option_reference);
+ item->string);
ref_git_copy = xstrdup(ref_git);
@@ -227,6 +237,12 @@ static void setup_reference(const char *repo)
transport_disconnect(transport);
free(ref_git_copy);
+ return 0;
+}
+
+static void setup_reference(void)
+{
+ for_each_string_list(&option_reference, add_one_reference, NULL);
}
static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest)
@@ -521,8 +537,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
git_config_set(key.buf, repo);
strbuf_reset(&key);
- if (option_reference)
- setup_reference(git_dir);
+ if (option_reference.nr)
+ setup_reference();
fetch_pattern = value.buf;
refspec = parse_fetch_refspec(1, &fetch_pattern);
diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh
index 151ea53..0163ad1 100755
--- a/t/t5601-clone.sh
+++ b/t/t5601-clone.sh
@@ -207,4 +207,19 @@ test_expect_success 'clone separate gitdir where target already exists' '
test_must_fail git clone --separate-git-dir realgitdir src dst
'
+test_expect_failure 'clone --reference from original' '
+ git clone --shared --bare src src-1 &&
+ git clone --bare src src-2 &&
+ git clone --reference=src-2 --bare src-1 target-8 &&
+ grep /src-2/ target-8/objects/info/alternates
+'
+
+test_expect_success 'clone with more than one --reference' '
+ git clone --bare src src-3 &&
+ git clone --bare src src-4 &&
+ git clone --reference=src-3 --reference=src-4 src target-9 &&
+ grep /src-3/ target-9/.git/objects/info/alternates &&
+ grep /src-4/ target-9/.git/objects/info/alternates
+'
+
test_done
--
1.7.6.557.gcee42
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/2] clone: clone from a repository with relative alternates
2011-08-23 1:05 ` [PATCH 0/2] clone-local fixup Junio C Hamano
2011-08-23 1:05 ` [PATCH 1/2] clone: allow more than one --reference Junio C Hamano
@ 2011-08-23 1:05 ` Junio C Hamano
2011-08-23 3:43 ` [PATCH 0/2] clone-local fixup Hui Wang
2 siblings, 0 replies; 10+ messages in thread
From: Junio C Hamano @ 2011-08-23 1:05 UTC (permalink / raw)
To: git; +Cc: Hui Wang
Cloning from a local repository blindly copies or hardlinks all the files
under objects/ hierarchy. This results in two issues:
- If the repository cloned has an "objects/info/alternates" file, and the
command line of clone specifies --reference, the ones specified on the
command line get overwritten by the copy from the original repository.
- An entry in a "objects/info/alternates" file can specify the object
stores it borrows objects from as a path relative to the "objects/"
directory. When cloning a repository with such an alternates file, if
the new repository is not sitting next to the original repository, such
relative paths needs to be adjusted so that they can be used in the new
repository.
This updates add_to_alternates_file() to take the path to the alternate
object store, including the "/objects" part at the end (earlier, it was
taking the path to $GIT_DIR and was adding "/objects" itself), as it is
technically possible to specify in objects/info/alternates file the path
of a directory whose name does not end with "/objects".
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
builtin/clone.c | 52 ++++++++++++++++++++++++++++++++++++++++------------
sha1_file.c | 2 +-
t/t5601-clone.sh | 10 +++++++++-
3 files changed, 50 insertions(+), 14 deletions(-)
diff --git a/builtin/clone.c b/builtin/clone.c
index ee5d651..2842707 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -210,8 +210,7 @@ static void strip_trailing_slashes(char *dir)
static int add_one_reference(struct string_list_item *item, void *cb_data)
{
const char *ref_git;
- char *ref_git_copy;
-
+ struct strbuf alternate = STRBUF_INIT;
struct remote *remote;
struct transport *transport;
const struct ref *extra;
@@ -224,19 +223,17 @@ static int add_one_reference(struct string_list_item *item, void *cb_data)
die(_("reference repository '%s' is not a local directory."),
item->string);
- ref_git_copy = xstrdup(ref_git);
-
- add_to_alternates_file(ref_git_copy);
+ strbuf_addf(&alternate, "%s/objects", ref_git);
+ add_to_alternates_file(alternate.buf);
+ strbuf_release(&alternate);
- remote = remote_get(ref_git_copy);
- transport = transport_get(remote, ref_git_copy);
+ remote = remote_get(ref_git);
+ transport = transport_get(remote, ref_git);
for (extra = transport_get_remote_refs(transport); extra;
extra = extra->next)
add_extra_ref(extra->name, extra->old_sha1, 0);
transport_disconnect(transport);
-
- free(ref_git_copy);
return 0;
}
@@ -245,7 +242,32 @@ static void setup_reference(void)
for_each_string_list(&option_reference, add_one_reference, NULL);
}
-static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest)
+static void copy_alternates(struct strbuf *src, struct strbuf *dst,
+ const char *src_repo)
+{
+ /*
+ * Read from the source objects/info/alternates file
+ * and copy the entries to corresponding file in the
+ * destination repository with add_to_alternates_file().
+ * Both src and dst have "$path/objects/info/alternates".
+ */
+ FILE *in = fopen(src->buf, "r");
+ struct strbuf line = STRBUF_INIT;
+
+ while (strbuf_getline(&line, in, '\n') != EOF) {
+ char *abs_path, abs_buf[PATH_MAX];
+ if (!line.len || line.buf[0] == '#')
+ continue;
+ abs_path = mkpath("%s/objects/%s", src_repo, line.buf);
+ normalize_path_copy(abs_buf, abs_path);
+ add_to_alternates_file(abs_buf);
+ }
+ strbuf_release(&line);
+ fclose(in);
+}
+
+static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest,
+ const char *src_repo, int src_baselen)
{
struct dirent *de;
struct stat buf;
@@ -281,7 +303,13 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest)
}
if (S_ISDIR(buf.st_mode)) {
if (de->d_name[0] != '.')
- copy_or_link_directory(src, dest);
+ copy_or_link_directory(src, dest,
+ src_repo, src_baselen);
+ continue;
+ }
+
+ if (!strcmp(src->buf + src_baselen, "/info/alternates")) {
+ copy_alternates(src, dest, src_repo);
continue;
}
@@ -314,7 +342,7 @@ static const struct ref *clone_local(const char *src_repo,
else {
strbuf_addf(&src, "%s/objects", src_repo);
strbuf_addf(&dest, "%s/objects", dest_repo);
- copy_or_link_directory(&src, &dest);
+ copy_or_link_directory(&src, &dest, src_repo, src.len);
strbuf_release(&src);
strbuf_release(&dest);
}
diff --git a/sha1_file.c b/sha1_file.c
index 064a330..f7c3408 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -380,7 +380,7 @@ void add_to_alternates_file(const char *reference)
{
struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
int fd = hold_lock_file_for_append(lock, git_path("objects/info/alternates"), LOCK_DIE_ON_ERROR);
- char *alt = mkpath("%s/objects\n", reference);
+ char *alt = mkpath("%s\n", reference);
write_or_die(fd, alt, strlen(alt));
if (commit_lock_file(lock))
die("could not close alternates file");
diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh
index 0163ad1..d87214c 100755
--- a/t/t5601-clone.sh
+++ b/t/t5601-clone.sh
@@ -207,7 +207,7 @@ test_expect_success 'clone separate gitdir where target already exists' '
test_must_fail git clone --separate-git-dir realgitdir src dst
'
-test_expect_failure 'clone --reference from original' '
+test_expect_success 'clone --reference from original' '
git clone --shared --bare src src-1 &&
git clone --bare src src-2 &&
git clone --reference=src-2 --bare src-1 target-8 &&
@@ -222,4 +222,12 @@ test_expect_success 'clone with more than one --reference' '
grep /src-4/ target-9/.git/objects/info/alternates
'
+test_expect_success 'clone from original with relative alternate' '
+ mkdir nest &&
+ git clone --bare src nest/src-5 &&
+ echo ../../../src/.git/objects >nest/src-5/objects/info/alternates &&
+ git clone --bare nest/src-5 target-10 &&
+ grep /src/\\.git/objects target-10/objects/info/alternates
+'
+
test_done
--
1.7.6.557.gcee42
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 0/2] clone-local fixup
2011-08-23 1:05 ` [PATCH 0/2] clone-local fixup Junio C Hamano
2011-08-23 1:05 ` [PATCH 1/2] clone: allow more than one --reference Junio C Hamano
2011-08-23 1:05 ` [PATCH 2/2] clone: clone from a repository with relative alternates Junio C Hamano
@ 2011-08-23 3:43 ` Hui Wang
2011-08-23 16:26 ` Junio C Hamano
2 siblings, 1 reply; 10+ messages in thread
From: Hui Wang @ 2011-08-23 3:43 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Hui Wang
This patch series solved the problem from the root cause. :-)
But there is a little problem in the second patch, i provide an
incremental patch basing on your second patch, if it is fine to you, it
is OK to squash this patch to your second patch.
commit 47e890818fdac5f6493cd0bbaf9da350785a2bca
Author: Hui Wang <jason77.wang@gmail.com>
Date: Tue Aug 23 11:32:26 2011 +0800
clone: don't change absolute path in the copy_alternates
The source alternates may include empty lines, comment lines, relative
paths and absolute paths. Absolute paths don't need to be changed
before added to the destination alternates.
Signed-off-by: Hui Wang <jason77.wang@gmail.com>
diff --git a/builtin/clone.c b/builtin/clone.c
index 2842707..284e325 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -258,6 +258,10 @@ static void copy_alternates(struct strbuf *src,
struct strbuf *dst,
char *abs_path, abs_buf[PATH_MAX];
if (!line.len || line.buf[0] == '#')
continue;
+ if (is_absolute_path(line.buf)) {
+ add_to_alternates_file(line.buf);
+ continue;
+ }
abs_path = mkpath("%s/objects/%s", src_repo, line.buf);
normalize_path_copy(abs_buf, abs_path);
add_to_alternates_file(abs_buf);
Regards,
Hui.
Junio C Hamano wrote:
> So I ended up tackling this myself. I didn't bother moving the
> add_to_alternates_file(), though.
>
> Junio C Hamano (2):
> clone: allow more than one --reference
> clone: clone from a repository with relative alternates
>
> builtin/clone.c | 82 +++++++++++++++++++++++++++++++++++++++++------------
> sha1_file.c | 2 +-
> t/t5601-clone.sh | 23 +++++++++++++++
> 3 files changed, 87 insertions(+), 20 deletions(-)
>
>
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 0/2] clone-local fixup
2011-08-23 3:43 ` [PATCH 0/2] clone-local fixup Hui Wang
@ 2011-08-23 16:26 ` Junio C Hamano
0 siblings, 0 replies; 10+ messages in thread
From: Junio C Hamano @ 2011-08-23 16:26 UTC (permalink / raw)
To: Hui Wang; +Cc: git
Hui Wang <jason77.wang@gmail.com> writes:
> This patch series solved the problem from the root cause. :-)
>
> But there is a little problem in the second patch, i provide an
> incremental patch basing on your second patch, if it is fine to you,
> it is OK to squash this patch to your second patch.
Thanks. We also need the following fix-up, as I changed the semantics of
add_to_alternates_file() to take the path to the "objects" directory.
diff --git a/builtin/clone.c b/builtin/clone.c
index 284e325..63c34d0 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -336,14 +336,17 @@ static const struct ref *clone_local(const char *src_repo,
const char *dest_repo)
{
const struct ref *ret;
- struct strbuf src = STRBUF_INIT;
- struct strbuf dest = STRBUF_INIT;
struct remote *remote;
struct transport *transport;
- if (option_shared)
- add_to_alternates_file(src_repo);
- else {
+ if (option_shared) {
+ struct strbuf alt = STRBUF_INIT;
+ strbuf_addf(&alt, "%s/objects", src_repo);
+ add_to_alternates_file(alt.buf);
+ strbuf_release(&alt);
+ } else {
+ struct strbuf src = STRBUF_INIT;
+ struct strbuf dest = STRBUF_INIT;
strbuf_addf(&src, "%s/objects", src_repo);
strbuf_addf(&dest, "%s/objects", dest_repo);
copy_or_link_directory(&src, &dest, src_repo, src.len);
^ permalink raw reply related [flat|nested] 10+ messages in thread
end of thread, other threads:[~2011-08-23 16:26 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-22 9:05 [PATCH v2 0/1] git-clone: fix relative path problem in the alternates Hui Wang
2011-08-22 9:05 ` [PATCH v2 1/1] clone: replace relative paths " Hui Wang
2011-08-22 19:10 ` [PATCH v2 0/1] git-clone: fix relative path problem " Junio C Hamano
2011-08-22 20:38 ` Junio C Hamano
2011-08-22 21:57 ` Junio C Hamano
2011-08-23 1:05 ` [PATCH 0/2] clone-local fixup Junio C Hamano
2011-08-23 1:05 ` [PATCH 1/2] clone: allow more than one --reference Junio C Hamano
2011-08-23 1:05 ` [PATCH 2/2] clone: clone from a repository with relative alternates Junio C Hamano
2011-08-23 3:43 ` [PATCH 0/2] clone-local fixup Hui Wang
2011-08-23 16:26 ` Junio C Hamano
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).