Change ScanIndex to ref & expose git.RefBeforeFirstCommit for clarity

This commit is contained in:
Steve Streeting 2016-09-27 17:44:30 +01:00
parent da4b9efede
commit eca20ad9dd
4 changed files with 13 additions and 12 deletions

@ -39,7 +39,7 @@ func doFsck() (bool, error) {
}
// TODO(zeroshirts): do we want to look for LFS stuff in past commits?
p2, err := lfs.ScanIndex(false)
p2, err := lfs.ScanIndex("HEAD")
if err != nil {
return false, err
}

@ -18,7 +18,12 @@ func statusCommand(cmd *cobra.Command, args []string) {
// tolerate errors getting ref so this works before first commit
ref, _ := git.CurrentRef()
stagedPointers, err := lfs.ScanIndex(ref == nil)
scanIndexAt := "HEAD"
if ref == nil {
scanIndexAt = git.RefBeforeFirstCommit
}
stagedPointers, err := lfs.ScanIndex(scanIndexAt)
if err != nil {
Panic(err, "Could not scan staging for Git LFS objects")
}

@ -30,6 +30,10 @@ const (
RefTypeRemoteTag = RefType(iota)
RefTypeHEAD = RefType(iota) // current checkout
RefTypeOther = RefType(iota) // stash or unknown
// A ref which can be used as a placeholder for before the first commit
// Equivalent to git mktree < /dev/null, useful for diffing before first commit
RefBeforeFirstCommit = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
)
// A git reference (branch, tag etc)

@ -30,9 +30,6 @@ const (
// chanBufSize is the size of the channels used to pass data from one
// sub-process to another.
chanBufSize = 100
// Equivalent to git mktree < /dev/null, useful for diffing before first commit
nullTreeish = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
)
var (
@ -195,8 +192,8 @@ func (m *indexFileMap) Set(sha string, index *indexFile) {
// ScanIndex returns a slice of WrappedPointer objects for all
// Git LFS pointers it finds in the index.
// Reports unique oids once only, not multiple times if >1 file uses the same content
// isFirstCommit must be true if this repo doesn't have any commits yet
func ScanIndex(isFirstCommit bool) ([]*WrappedPointer, error) {
// Ref is the ref at which to scan, which may be "HEAD" if there is at least one commit
func ScanIndex(ref string) ([]*WrappedPointer, error) {
indexMap := &indexFileMap{
nameMap: make(map[string]*indexFile, 0),
mutex: &sync.Mutex{},
@ -207,11 +204,6 @@ func ScanIndex(isFirstCommit bool) ([]*WrappedPointer, error) {
tracerx.PerformanceSince("scan-staging", start)
}()
ref := "HEAD"
if isFirstCommit {
ref = nullTreeish
}
revs, err := revListIndex(ref, false, indexMap)
if err != nil {
return nil, err