Merge pull request #578 from billygor/major-pre-push-optimization-for-current-remote
major pre-push optimization (alternative: look for deltas against current remote only)
This commit is contained in:
commit
4457d7c7c5
@ -67,7 +67,8 @@ func prePushCommand(cmd *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Just use scanner here
|
// Just use scanner here
|
||||||
pointers, err := lfs.ScanRefs(left, right, nil)
|
scanOpt := &lfs.ScanRefsOptions{ScanMode: lfs.ScanLeftToRemoteMode, RemoteName: lfs.Config.CurrentRemote}
|
||||||
|
pointers, err := lfs.ScanRefs(left, right, scanOpt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Panic(err, "Error scanning for Git LFS files")
|
Panic(err, "Error scanning for Git LFS files")
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package lfs
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -60,9 +61,18 @@ type indexFile struct {
|
|||||||
|
|
||||||
var z40 = regexp.MustCompile(`\^?0{40}`)
|
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 {
|
type ScanRefsOptions struct {
|
||||||
|
ScanMode ScanningMode
|
||||||
|
RemoteName string
|
||||||
SkipDeletedBlobs bool
|
SkipDeletedBlobs bool
|
||||||
scanAll bool
|
|
||||||
nameMap map[string]string
|
nameMap map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +83,9 @@ func ScanRefs(refLeft, refRight string, opt *ScanRefsOptions) ([]*WrappedPointer
|
|||||||
if opt == nil {
|
if opt == nil {
|
||||||
opt = &ScanRefsOptions{}
|
opt = &ScanRefsOptions{}
|
||||||
}
|
}
|
||||||
opt.scanAll = refLeft == ""
|
if refLeft == "" {
|
||||||
|
opt.ScanMode = ScanAllMode
|
||||||
|
}
|
||||||
opt.nameMap = make(map[string]string, 0)
|
opt.nameMap = make(map[string]string, 0)
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
@ -174,9 +186,8 @@ func ScanIndex() ([]*WrappedPointer, error) {
|
|||||||
// channel from which sha1 strings can be read.
|
// channel from which sha1 strings can be read.
|
||||||
func revListShas(refLeft, refRight string, opt ScanRefsOptions) (chan string, error) {
|
func revListShas(refLeft, refRight string, opt ScanRefsOptions) (chan string, error) {
|
||||||
refArgs := []string{"rev-list", "--objects"}
|
refArgs := []string{"rev-list", "--objects"}
|
||||||
if opt.scanAll {
|
switch opt.ScanMode {
|
||||||
refArgs = append(refArgs, "--all")
|
case ScanRefsMode:
|
||||||
} else {
|
|
||||||
if opt.SkipDeletedBlobs {
|
if opt.SkipDeletedBlobs {
|
||||||
refArgs = append(refArgs, "--no-walk")
|
refArgs = append(refArgs, "--no-walk")
|
||||||
} else {
|
} else {
|
||||||
@ -187,6 +198,12 @@ func revListShas(refLeft, refRight string, opt ScanRefsOptions) (chan string, er
|
|||||||
if refRight != "" && !z40.MatchString(refRight) {
|
if refRight != "" && !z40.MatchString(refRight) {
|
||||||
refArgs = append(refArgs, refRight)
|
refArgs = append(refArgs, refRight)
|
||||||
}
|
}
|
||||||
|
case ScanAllMode:
|
||||||
|
refArgs = append(refArgs, "--all")
|
||||||
|
case ScanLeftToRemoteMode:
|
||||||
|
refArgs = append(refArgs, refLeft, "--not", "--remotes="+opt.RemoteName)
|
||||||
|
default:
|
||||||
|
return nil, errors.New("scanner: unknown scan type: " + strconv.Itoa(int(opt.ScanMode)))
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd, err := startCommand("git", refArgs...)
|
cmd, err := startCommand("git", refArgs...)
|
||||||
|
@ -122,13 +122,15 @@ begin_test "credentials with useHttpPath, with correct password"
|
|||||||
git lfs track "*.dat" 2>&1 | tee track.log
|
git lfs track "*.dat" 2>&1 | tee track.log
|
||||||
grep "Tracking \*.dat" track.log
|
grep "Tracking \*.dat" track.log
|
||||||
|
|
||||||
contents="a"
|
# creating new branch does not re-sent any objects existing on other
|
||||||
|
# remote branches anymore, generate new object, different from prev tests
|
||||||
|
contents="b"
|
||||||
contents_oid=$(printf "$contents" | shasum -a 256 | cut -f 1 -d " ")
|
contents_oid=$(printf "$contents" | shasum -a 256 | cut -f 1 -d " ")
|
||||||
|
|
||||||
printf "$contents" > a.dat
|
printf "$contents" > b.dat
|
||||||
git add a.dat
|
git add b.dat
|
||||||
git add .gitattributes
|
git add .gitattributes
|
||||||
git commit -m "add a.dat"
|
git commit -m "add b.dat"
|
||||||
|
|
||||||
git push origin with-path-correct-pass 2>&1 | tee push.log
|
git push origin with-path-correct-pass 2>&1 | tee push.log
|
||||||
grep "(1 of 1 files)" push.log
|
grep "(1 of 1 files)" push.log
|
||||||
|
Loading…
Reference in New Issue
Block a user