git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/1] git-clone: fix relative path problem in the alternates
@ 2011-08-19  5:23 Hui Wang
  2011-08-19  5:23 ` [PATCH 1/1] clone: replace relative paths " Hui Wang
  0 siblings, 1 reply; 4+ messages in thread
From: Hui Wang @ 2011-08-19  5:23 UTC (permalink / raw)
  To: gitster, git

Hi Junio & everyone,

Several days ago, i reported a "git clone" issue, the url is at:
http://marc.info/?l=git&m=131219022632724&w=2

Here i describe the problem again and try to provide a fix for this
problem, please help to review it. Thanks.

The problem:
Suppose we have two git repositories on the local machine, one is
called base repository, another is called source repository, source
repository need refer to some objects of the base repository via
.git/objects/info/alternates. If we set a relative path (source repository
to base repository) in the alternates, we can execute any git commands (branch,
tag, pull, checkout...) successfully in the source repository. But if we
want to clone a destiantion repository from source repository without
"--shared" on the same machine, just like this:
%>git clone $local_path/src_repos $local_path/des_repos
This clone command will fail because git can't get objects of the base
repository.

The reason:
When we execute git clone $local_path/src_repos $local_path/des_repos,
git will copy alternates of the src_repos to the des_repos first, then
des_repos will use this alternates to refer to base repository, this is
the problem, the relative in the alternates is src_repos to base_repos
rather than des_repos to base_repos.

The fix:
After the alternates is copied from src_repos to des_repos and before this
file is used by the des_repos, we can parse it and replace all relative
paths to a corrected path (absolute path of base_repos or new relative path
of des_repos to base_repos). In my patch, i choose to replace relative paths
to absoulte paths of base_repos.

If we add "--shared", this problem doesn't exist becase git doesn't need to
copy alternates, if we add prefix before src_repos like "file://", "git://"...,
this problem also doesn't exist. So i add a function to replace relative paths
in the clone_local(), this only affect git clone $local_path/src_repos
$local_path/des_repos without "--shared" and it has replative paths in the
alternates of src_repos, for other situation, this function will not introduce
any changes. Below is a execution result example of my fix:

the content of the alternates in the source repos (4 lines):
$<relative_path1_source_repos_to_base1>
$<relative_path2_source_repos_to_base2>
# comment line
$<absolute_path_of_base3>

After clone from source repos, the content of the alternates in the des_repos (4 lines):
$<absolute_path_of_base1>
$<absolute_path_of_base2>
# comment line
$<absolute_path_of_base3> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-08-19  6:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-19  5:23 [PATCH 0/1] git-clone: fix relative path problem in the alternates Hui Wang
2011-08-19  5:23 ` [PATCH 1/1] clone: replace relative paths " Hui Wang
2011-08-19  6:22   ` Junio C Hamano
2011-08-19  6:39     ` Hui Wang

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).