From 422f3ead0963531537f6005ae2124c1da38bd2fb Mon Sep 17 00:00:00 2001 From: risk danger olson Date: Fri, 18 Nov 2016 11:51:15 -0700 Subject: [PATCH] continue gutting lfs/scanner.go --- lfs/gitscanner.go | 37 ++++++++++++++++++++++++++++ lfs/gitscanner_index.go | 9 +++++++ lfs/gitscanner_refs.go | 2 ++ lfs/scanner.go | 54 +---------------------------------------- 4 files changed, 49 insertions(+), 53 deletions(-) diff --git a/lfs/gitscanner.go b/lfs/gitscanner.go index 60b42023..755a1e1b 100644 --- a/lfs/gitscanner.go +++ b/lfs/gitscanner.go @@ -131,3 +131,40 @@ func (s *GitScanner) opts(mode ScanningMode) *ScanRefsOptions { opts.skippedRefs = s.skippedRefs return opts } + +type ScanningMode int + +const ( + ScanRefsMode = ScanningMode(iota) // 0 - or default scan mode + ScanAllMode = ScanningMode(iota) + ScanLeftToRemoteMode = ScanningMode(iota) +) + +type ScanRefsOptions struct { + ScanMode ScanningMode + RemoteName string + SkipDeletedBlobs bool + skippedRefs []string + nameMap map[string]string + mutex *sync.Mutex +} + +func (o *ScanRefsOptions) GetName(sha string) (string, bool) { + o.mutex.Lock() + name, ok := o.nameMap[sha] + o.mutex.Unlock() + return name, ok +} + +func (o *ScanRefsOptions) SetName(sha, name string) { + o.mutex.Lock() + o.nameMap[sha] = name + o.mutex.Unlock() +} + +func newScanRefsOptions() *ScanRefsOptions { + return &ScanRefsOptions{ + nameMap: make(map[string]string, 0), + mutex: &sync.Mutex{}, + } +} diff --git a/lfs/gitscanner_index.go b/lfs/gitscanner_index.go index a07a2081..fe4c5e7c 100644 --- a/lfs/gitscanner_index.go +++ b/lfs/gitscanner_index.go @@ -174,6 +174,15 @@ func revListIndex(atRef string, cache bool, indexMap *indexFileMap) (*StringChan return NewStringChannelWrapper(revs, errchan), nil } +// indexFile is used when scanning the index. It stores the name of +// the file, the status of the file in the index, and, in the case of +// a moved or copied file, the original name of the file. +type indexFile struct { + Name string + SrcName string + Status string +} + type indexFileMap struct { // mutex guards nameMap and nameShaPairs mutex *sync.Mutex diff --git a/lfs/gitscanner_refs.go b/lfs/gitscanner_refs.go index 00e7d72a..eab3e9dd 100644 --- a/lfs/gitscanner_refs.go +++ b/lfs/gitscanner_refs.go @@ -13,6 +13,8 @@ import ( "github.com/rubyist/tracerx" ) +var z40 = regexp.MustCompile(`\^?0{40}`) + // scanRefsToChan takes a ref and returns a channel of WrappedPointer objects // for all Git LFS pointers it finds for that ref. // Reports unique oids once only, not multiple times if >1 file uses the same content diff --git a/lfs/scanner.go b/lfs/scanner.go index 50368826..1f7e5e73 100644 --- a/lfs/scanner.go +++ b/lfs/scanner.go @@ -1,10 +1,6 @@ package lfs -import ( - "fmt" - "regexp" - "sync" -) +import "fmt" const ( // blobSizeCutoff is used to determine which files to scan for Git LFS @@ -30,54 +26,6 @@ type WrappedPointer struct { *Pointer } -// indexFile is used when scanning the index. It stores the name of -// the file, the status of the file in the index, and, in the case of -// a moved or copied file, the original name of the file. -type indexFile struct { - Name string - SrcName string - Status string -} - -var z40 = regexp.MustCompile(`\^?0{40}`) - -type ScanningMode int - -const ( - ScanRefsMode = ScanningMode(iota) // 0 - or default scan mode - ScanAllMode = ScanningMode(iota) - ScanLeftToRemoteMode = ScanningMode(iota) -) - -type ScanRefsOptions struct { - ScanMode ScanningMode - RemoteName string - SkipDeletedBlobs bool - skippedRefs []string - nameMap map[string]string - mutex *sync.Mutex -} - -func (o *ScanRefsOptions) GetName(sha string) (string, bool) { - o.mutex.Lock() - name, ok := o.nameMap[sha] - o.mutex.Unlock() - return name, ok -} - -func (o *ScanRefsOptions) SetName(sha, name string) { - o.mutex.Lock() - o.nameMap[sha] = name - o.mutex.Unlock() -} - -func newScanRefsOptions() *ScanRefsOptions { - return &ScanRefsOptions{ - nameMap: make(map[string]string, 0), - mutex: &sync.Mutex{}, - } -} - // catFileBatchCheck uses git cat-file --batch-check to get the type // and size of a git object. Any object that isn't of type blob and // under the blobSizeCutoff will be ignored. revs is a channel over