This repository was archived by the owner on Sep 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 534
storage: shallow storage #180
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package storer | ||
|
||
import "gopkg.in/src-d/go-git.v4/plumbing" | ||
|
||
// ShallowStorer storage of shallow commits, meaning that it does not have the | ||
// parents of a commit (explanation from git documentation) | ||
type ShallowStorer interface { | ||
SetShallow([]plumbing.Hash) error | ||
Shallow() ([]plumbing.Hash, error) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package filesystem | ||
|
||
import ( | ||
"fmt" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extra space ;) |
||
"bufio" | ||
|
||
"gopkg.in/src-d/go-git.v4/plumbing" | ||
"gopkg.in/src-d/go-git.v4/storage/filesystem/internal/dotgit" | ||
) | ||
|
||
// ShallowStorage where the shallow commits are stored, an internal to | ||
// manipulate the shallow file | ||
type ShallowStorage struct { | ||
dir *dotgit.DotGit | ||
} | ||
|
||
// SetShallow save the shallows in the shallow file in the .git folder as one | ||
// commit per line represented by 40-byte hexadecimal object terminated by a | ||
// newline. | ||
func (s *ShallowStorage) SetShallow(commits []plumbing.Hash) error { | ||
f, err := s.dir.ShallowWriter() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defer f.Close() | ||
for _, h := range commits { | ||
if _, err := fmt.Fprintf(f, "%s\n", h); err != err { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Shallow return the shallow commits reading from shallo file from .git | ||
func (s *ShallowStorage) Shallow() ([]plumbing.Hash, error) { | ||
f, err := s.dir.Shallow() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var hash []plumbing.Hash | ||
|
||
scn := bufio.NewScanner(f) | ||
for scn.Scan() { | ||
hash = append(hash, plumbing.NewHash(scn.Text())) | ||
} | ||
|
||
return hash, scn.Err() | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there a
storer.ShallowStorer
interface when we already have anstorer.ObjectStorer
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the interfaces repeat the word
Storer
in their name when it is already part of the package name?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it only stores the references not the objects it self.
Yes maybe we can keep the
Storer
what you suggest?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. The comments of ShallowStorer suggest it stores commits not hashes. I would change that.
If this is just a collection of hashes I would said it so, and remove any reference to the
shallow
word in the name of the interface. Maybe call it Hashes, for example.I would call it
storer.Hashes
orstorer.HashCollection
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd propose something along these lines:
?