Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix relative alternates paths

Relative paths in a <repo>.git/objects/info/alternates file are to
be expanded relative to the <repo>.git/objects directory.
Previously, they were expanded relative to the <repo>.git directory.

The current code checks in both locations for backward compatibility
with grit <= 2.3.0 but I'd rather rip it out completely.
  • Loading branch information...
commit 7fc2b567f3aacd1b5697ace19b3e518a7f23ae02 1 parent 62d2ce1
@rtomayko rtomayko authored
View
50 lib/grit/git-ruby/repository.rb
@@ -701,21 +701,35 @@ def initloose
@loose
end
- def load_alternate_loose(path)
- # load alternate loose, too
+ def each_alternate_path(path)
alt = File.join(path, 'info/alternates')
- if File.exists?(alt)
- File.readlines(alt).each do |line|
- next if @loaded.include?(line.chomp)
- if line[0, 2] == '..'
- line = File.expand_path(File.join(@git_dir, line))
- end
- load_loose(line.chomp)
- load_alternate_loose(line.chomp)
+ return if !File.exists?(alt)
+
+ File.readlines(alt).each do |line|
+ path = line.chomp
+ if path[0, 2] == '..'
+ yield File.expand_path(File.join(@git_dir, 'objects', path))
+
+ # XXX this is here for backward compatibility with grit < 2.3.0
+ # relative alternate objects paths are expanded relative to the
+ # objects directory, not the git repository directory.
+ yield File.expand_path(File.join(@git_dir, path))
+ else
+ yield path
end
end
end
+ def load_alternate_loose(path)
+ # load alternate loose, too
+ each_alternate_path path do |path|
+ next if @loaded.include?(path)
+ next if !File.exist?(path)
+ load_loose(path)
+ load_alternate_loose(path)
+ end
+ end
+
def load_loose(path)
@loaded << path
return if !File.exists?(path)
@@ -732,17 +746,11 @@ def initpacks
end
def load_alternate_packs(path)
- alt = File.join(path, 'info/alternates')
- if File.exists?(alt)
- File.readlines(alt).each do |line|
- if line[0, 2] == '..'
- line = File.expand_path(File.join(@git_dir, line))
- end
- full_pack = File.join(line.chomp, 'pack')
- next if @loaded_packs.include?(full_pack)
- load_packs(full_pack)
- load_alternate_packs(File.join(line.chomp))
- end
+ each_alternate_path path do |path|
+ full_pack = File.join(path, 'pack')
+ next if @loaded_packs.include?(full_pack)
+ load_packs(full_pack)
+ load_alternate_packs(path)
end
end
View
2  test/dot_git_clone/objects/info/alternates
@@ -1 +1 @@
-../dot_git/objects
+../../dot_git/objects
View
2  test/dot_git_clone2/objects/info/alternates
@@ -1 +1 @@
-../dot_git_clone/objects
+../../dot_git_clone/objects

1 comment on commit 7fc2b56

@rtomayko
Collaborator

Documentation for objects/info/alternates mentioning the base for relative paths is here:

http://www.kernel.org/pub/software/scm/git/docs/gitrepository-layout.html

objects/info/alternates

This file records paths to alternate object stores that this object store borrows objects from, one pathname per line. Note that not only native Git tools use it locally, but the HTTP fetcher also tries to use it remotely; this will usually work if you have relative paths (relative to the object database, not to the repository!) in your alternates file, but it will not work if you use absolute paths unless the absolute path in filesystem and web URL is the same. See also objects/info/http-alternates.

Please sign in to comment.
Something went wrong with that request. Please try again.