Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

storage: filesystem, add support for git alternates #663

Merged
merged 4 commits into from
Dec 6, 2017

Conversation

darkowlzz
Copy link
Contributor

This change adds a new method Alternates() in DotGit to check and
query alternate source.

func (d *DotGit) Alternates() (string, error)

This is used by ObjectStorage.EncodedObject to check for alternates
and get the queried object from the alternate source.

I've manually tested this with the scenario and code in #325 but I'm not sure what would be the right way to setup an automated test for this. Need help with testing.

Fixes #325

@mcuadros
Copy link
Contributor

You will need to create a fixture with altnernates and pull request it to: https://github.com/src-d/go-git-fixtures

// alternates file.
fs := osfs.New(filepath.Dir(alt))
dir := dotgit.New(fs)
o, oe := newObjectStorage(dir)
Copy link
Contributor

@orirawlings orirawlings Nov 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this secondary storage object should be cached rather than recreated each time we retrieve an object stored in the alternates?

func (d *DotGit) Module(name string) (billy.Filesystem, error) {
return d.fs.Chroot(d.fs.Join(modulePath, name))
}

// Alternates returns the content of objects/info/alternates if available.
// This can be used to checks if it's a shared repository.
func (d *DotGit) Alternates() (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be better if this returned (*DotGit, error) instead of just the file contents?

@darkowlzz
Copy link
Contributor Author

Maybe this secondary storage object should be cached rather than recreated each time we retrieve an object stored in the alternates?

@orirawlings some hints on how to cache storage object would be great :)

@darkowlzz
Copy link
Contributor Author

NOTE: The test TestAlternatesRepo depends on the fixture in src-d/go-git-fixtures#8 .

@mcuadros
Copy link
Contributor

mcuadros commented Dec 4, 2017

This change adds a new method `Alternates()` in `DotGit` to check and
query alternate source.
```
func (d *DotGit) Alternates() (string, error)
```
This is used by `ObjectStorage.EncodedObject` to check for alternates
and get the queried object from the alternate source.
@darkowlzz darkowlzz force-pushed the 325-git-alternates branch 8 times, most recently from 82e5f16 to 3aa04f1 Compare December 5, 2017 19:25
@darkowlzz
Copy link
Contributor Author

Alright, so there were two issues, both related to the paths on Windows. Glad that it was caught.

Failure in dotgit_test.go was due to the hard-coded separators. Replaced them with path/filepath's Separator and added Windows specific conditional in-line fixtures. Seems to work fine now.

Issue in worktree_test.go was due to the alternates in the worktree fixture being in *nix style slash path, which lead to unknown path on windows. Added an internal conversion of relative paths to slash path to solve this issue.

@mcuadros mcuadros merged commit eb74b0e into src-d:master Dec 6, 2017
@mcuadros
Copy link
Contributor

mcuadros commented Dec 6, 2017

Awesome!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants