Skip to content

Commit 4a7c8da

Browse files
authored
Merge pull request #268 from achilleas-k/fix/add-slowness
Fix for add command seemingly hanging at the end
2 parents eb2bfa9 + cd8a947 commit 4a7c8da

File tree

12 files changed

+114
-340
lines changed

12 files changed

+114
-340
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ services:
88
env:
99
global:
1010
- GO111MODULE=on
11+
- GOPROXY=https://proxy.golang.org
1112

1213

1314
matrix:
@@ -22,15 +23,14 @@ matrix:
2223
homebrew:
2324
packages:
2425
- python3
26+
- git-annex
27+
update: true
2528
allow_failures:
2629
- go: tip
2730

2831
before_install:
2932
- if [[ "${TRAVIS_OS_NAME}" != "osx" ]]; then
3033
pyenv global 3.7.1;
31-
else
32-
brew update;
33-
brew install git-annex;
3434
fi
3535
- pip3 install --user pytest pyyaml
3636

appveyor.yml

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ stack: go 1.12
88
environment:
99
SRCDIR: C:\gopath\src\github.com\G-Node\gin-cli
1010
GOPATH: C:\gopath
11+
GO111MODULE: on
12+
GOPROXY: https://proxy.golang.org
1113
BINDIR: bin
1214
# download dev build
1315
BUNDLEREPO: https://gin.g-node.org/achilleas/gin-cli-builds/raw/master
14-
GIN_LOG_DIR: C:\gin-log
1516

1617
matrix:
1718
# 32-bit
@@ -20,8 +21,6 @@ environment:
2021
# 64-bit
2122
- arch: "amd64"
2223

23-
24-
2524
install:
2625
- set PATH=C:\Python37-x64\;%PATH%;%GOPATH%\bin;c:\gin-bundle\git\usr\bin
2726
# download latest stable gin-cli-windows-bundle
@@ -36,21 +35,7 @@ install:
3635

3736
build_script:
3837
- cd %SRCDIR%
39-
# download deps
40-
- go get github.com/spf13/viper
41-
- go get github.com/spf13/cobra
42-
- go get github.com/howeyc/gopass
43-
- go get golang.org/x/crypto/ssh
44-
- go get github.com/G-Node/gin-core/gin
45-
- go get github.com/G-Node/gin-repo/wire
46-
- go get golang.org/x/crypto/ssh
47-
- go get github.com/gogits/go-gogs-client
48-
- go get github.com/fatih/color
49-
- go get github.com/shibukawa/configdir
50-
- go get github.com/bbrks/wrap
51-
- go get github.com/docker/docker/pkg/term
52-
- go get github.com/alecthomas/template
53-
- go get github.com/dustin/go-humanize
38+
- go get -v ./...
5439
- go vet ./...
5540
- set GOARCH=%arch%
5641
- go build -ldflags "-X main.gincliversion=APPVEYOR-%APPVEYOR_REPO_NAME%-%APPVEYOR_REPO_BRANCH% -X main.build=%APPVEYOR_BUILD_NUMBER% -X main.commit=%APPVEYOR_REPO_COMMIT%" -o %GOPATH%\bin\gin.exe .
@@ -74,6 +59,7 @@ test_script:
7459
deploy: off
7560

7661
on_finish:
77-
- appveyor PushArtifact %GIN_LOG_DIR%\gin.log
62+
- appveyor PushArtifact %SRCDIR%\tests\log\gin.log
63+
- appveyor PushArtifact %SRCDIR%\tests\log\runner.log
7864
# Uncomment next line to enable RDP
7965
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))

dorelease.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,12 @@ def get_git_annex_for_windows():
200200
"""
201201
Download the git annex for windows installer.
202202
"""
203-
win_git_annex_url = ("https://downloads.kitenet.net/git-annex/windows/"
204-
"current/git-annex-installer.exe")
205-
return download(win_git_annex_url)
206-
#
207-
# git-annex version 7 is very broken on Windows. Until it is fixed, we are
208-
# fixing the git-annex version (for Windows) to the last v6 version.
209-
# This was obtained from the official git-annex website history:
210-
# https://downloads.kitenet.net/.git/
211-
# fname = os.path.join(DESTDIR, "downloads", "git-annex-windows-v6.exe")
212-
# return fname
203+
# win_git_annex_url = ("https://downloads.kitenet.net/git-annex/windows/"
204+
# "current/git-annex-installer.exe")
205+
# return download(win_git_annex_url)
206+
# fixing windows installer version (again)
207+
fname = os.path.join(DESTDIR, "downloads", "git-annex-installer.exe")
208+
return fname
213209

214210

215211
def package_linux_plain(binfile):

ginclient/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var (
3333
Host: "gin.g-node.org",
3434
Port: 22,
3535
User: "git",
36-
HostKey: "gin.g-node.org,141.84.41.216 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBE5IBgKP3nUryEFaACwY4N3jlqDx8Qw1xAxU2Xpt5V0p9RNefNnedVmnIBV6lA3n+9kT1OSbyqA/+SgsQ57nHo0=",
36+
HostKey: "gin.g-node.org,141.84.41.219 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBE5IBgKP3nUryEFaACwY4N3jlqDx8Qw1xAxU2Xpt5V0p9RNefNnedVmnIBV6lA3n+9kT1OSbyqA/+SgsQ57nHo0=",
3737
},
3838
}
3939

ginclient/repos.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
// High level functions for managing repositories.
2323
// These functions either end up performing web calls (using the web package) or git shell commands (using the git package).
2424

25-
const unknownhostname = "(unknown)"
25+
const unknownhostname = "(unknownhost)"
2626

2727
// Types
2828

@@ -240,19 +240,35 @@ func Add(paths []string, addchan chan<- git.RepoFileStatus) {
240240
}
241241

242242
if len(paths) > 0 {
243+
gitaddpaths := make([]string, 0) // most times, this wont be used, so start with 0
244+
statuschan := make(chan git.AnnexStatusRes)
245+
go git.AnnexStatus(paths, statuschan)
246+
for stat := range statuschan {
247+
if stat.Status == "D" {
248+
// deleted files match but weren't added
249+
// this can happen when the annex filters don't match a file
250+
// and it doesn't go through to get added to git
251+
gitaddpaths = append(gitaddpaths, stat.File)
252+
}
253+
}
254+
255+
// Run git add on deleted files only
256+
if len(gitaddpaths) > 0 {
257+
gitaddchan := make(chan git.RepoFileStatus)
258+
go git.Add(gitaddpaths, gitaddchan)
259+
for addstat := range gitaddchan {
260+
addstat.State = "Removing"
261+
addchan <- addstat
262+
}
263+
}
264+
243265
// Run git annex add using exclusion filters
244266
// Files matching filters are automatically added to git
245267
annexaddchan := make(chan git.RepoFileStatus)
246268
go git.AnnexAdd(paths, annexaddchan)
247269
for addstat := range annexaddchan {
248270
addchan <- addstat
249271
}
250-
251-
gitaddchan := make(chan git.RepoFileStatus)
252-
go git.Add(paths, gitaddchan)
253-
for addstat := range gitaddchan {
254-
addchan <- addstat
255-
}
256272
}
257273
}
258274

gincmd/common.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ func printProgressWithBar(statuschan <-chan git.RepoFileStatus, nitems int) (fil
196196
outline.Reset()
197197
outline.WriteString(" ")
198198
outappend(stat.State)
199-
outappend(stat.FileName)
199+
if stat.FileName != "" {
200+
outappend(fmt.Sprintf("%q", stat.FileName))
201+
}
200202
if stat.Err == nil {
201203
if stat.Progress == "100%" {
202204
outappend(green("OK"))
@@ -247,7 +249,9 @@ func printProgressOutput(statuschan <-chan git.RepoFileStatus) (filesuccess map[
247249
state = stat.State
248250
}
249251
outappend(stat.State)
250-
outappend(stat.FileName)
252+
if stat.FileName != "" {
253+
outappend(fmt.Sprintf("%q", stat.FileName))
254+
}
251255
if stat.Err == nil {
252256
if stat.Progress == "100%" {
253257
outappend(green("OK"))
@@ -315,7 +319,7 @@ func determinePrintStyle(cmd *cobra.Command) printstyle {
315319
case verboseOn && jsonOn:
316320
Die("--verbose and --json cannot be used together")
317321
case verboseOn:
318-
git.JsonBool = false
322+
git.RawMode = true
319323
return psVerbose
320324
case jsonOn:
321325
return psJSON

git/annex.go

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ import (
1414
"github.com/G-Node/gin-cli/git/shell"
1515
)
1616

17+
// The following appears in the 'note' field when a file is added to git
18+
// instead of annex
19+
const addedToGitNote = "non-large file; adding content to git repository"
20+
1721
// Git annex commands
1822

19-
// Determine if json or normal command is used
20-
var JsonBool bool = true
23+
// RawMode disables --json output for annex commands
24+
var RawMode bool = false
2125

2226
// Types (private)
2327
type annexAction struct {
@@ -262,11 +266,11 @@ func AnnexPush(paths []string, remote string, pushchan chan<- RepoFileStatus) {
262266
}
263267

264268
var args []string
265-
if JsonBool {
266-
args = []string{"copy", "--json-progress", fmt.Sprintf("--to=%s", remote)}
267-
} else {
268-
args = []string{"copy", "--verbose", fmt.Sprintf("--to=%s", remote)}
269+
outflag := "--json-progress"
270+
if RawMode {
271+
outflag = "--verbose"
269272
}
273+
args = []string{"copy", outflag, fmt.Sprintf("--to=%s", remote)}
270274
if len(paths) == 0 {
271275
paths = []string{"--all"}
272276
}
@@ -299,7 +303,7 @@ func AnnexPush(paths []string, remote string, pushchan chan<- RepoFileStatus) {
299303
// skip empty lines
300304
continue
301305
}
302-
if !JsonBool {
306+
if RawMode {
303307
status.RawOutput = string(outline)
304308
lineInput := cmd.Args
305309
input := strings.Join(lineInput, " ")
@@ -393,7 +397,7 @@ func baseAnnexGet(cmdargs []string, getchan chan<- RepoFileStatus) {
393397
continue
394398
}
395399

396-
if !JsonBool {
400+
if RawMode {
397401
lineInput := cmd.Args
398402
input := strings.Join(lineInput, " ")
399403
status.RawInput = input
@@ -453,12 +457,11 @@ func baseAnnexGet(cmdargs []string, getchan chan<- RepoFileStatus) {
453457
// (git annex get)
454458
func AnnexGet(filepaths []string, getchan chan<- RepoFileStatus) {
455459
defer close(getchan)
456-
var cmdargs []string
457-
if JsonBool {
458-
cmdargs = append([]string{"get", "--json-progress"}, filepaths...)
459-
} else {
460-
cmdargs = append([]string{"get"}, filepaths...)
460+
cmdargs := []string{"get"}
461+
if !RawMode {
462+
cmdargs = append(cmdargs, "--json-progress")
461463
}
464+
cmdargs = append(cmdargs, filepaths...)
462465
baseAnnexGet(cmdargs, getchan)
463466
}
464467

@@ -477,12 +480,12 @@ func AnnexGetKey(key string, getchan chan<- RepoFileStatus) {
477480
// (git annex drop)
478481
func AnnexDrop(filepaths []string, dropchan chan<- RepoFileStatus) {
479482
defer close(dropchan)
480-
var cmdargs []string
481-
if JsonBool {
482-
cmdargs = append([]string{"drop", "--json"}, filepaths...)
483-
} else {
484-
cmdargs = append([]string{"drop"}, filepaths...)
483+
cmdargs := []string{"drop"}
484+
if !RawMode {
485+
cmdargs = append(cmdargs, "--json")
485486
}
487+
cmdargs = append(cmdargs, filepaths...)
488+
486489
cmd := AnnexCommand(cmdargs...)
487490
err := cmd.Start()
488491
if err != nil {
@@ -508,7 +511,7 @@ func AnnexDrop(filepaths []string, dropchan chan<- RepoFileStatus) {
508511
continue
509512
}
510513

511-
if !JsonBool {
514+
if RawMode {
512515
lineInput := cmd.Args
513516
input := strings.Join(lineInput, " ")
514517
status.RawInput = input
@@ -673,11 +676,9 @@ func AnnexLock(filepaths []string, lockchan chan<- RepoFileStatus) {
673676
log.Write("No paths to lock. Nothing to do.")
674677
return
675678
}
676-
var cmdargs []string
677-
if JsonBool {
678-
cmdargs = []string{"lock", "--json-error-messages"}
679-
} else {
680-
cmdargs = []string{"lock"}
679+
cmdargs := []string{"lock"}
680+
if !RawMode {
681+
cmdargs = append(cmdargs, "--json-error-messages")
681682
}
682683

683684
cmdargs = append(cmdargs, filepaths...)
@@ -700,7 +701,7 @@ func AnnexLock(filepaths []string, lockchan chan<- RepoFileStatus) {
700701
// Empty line output. Ignore
701702
continue
702703
}
703-
if !JsonBool {
704+
if RawMode {
704705
status.RawOutput = string(outline)
705706
lineInput := cmd.Args
706707
input := strings.Join(lineInput, " ")
@@ -756,11 +757,9 @@ func AnnexLock(filepaths []string, lockchan chan<- RepoFileStatus) {
756757
// (git annex unlock)
757758
func AnnexUnlock(filepaths []string, unlockchan chan<- RepoFileStatus) {
758759
defer close(unlockchan)
759-
var cmdargs []string
760-
if JsonBool {
761-
cmdargs = []string{"unlock", "--json"}
762-
} else {
763-
cmdargs = []string{"unlock"}
760+
cmdargs := []string{"unlock"}
761+
if !RawMode {
762+
cmdargs = append(cmdargs, "--json")
764763
}
765764
cmdargs = append(cmdargs, filepaths...)
766765
cmd := AnnexCommand(cmdargs...)
@@ -781,7 +780,7 @@ func AnnexUnlock(filepaths []string, unlockchan chan<- RepoFileStatus) {
781780
// Empty line output. Ignore
782781
continue
783782
}
784-
if !JsonBool {
783+
if RawMode {
785784
lineInput := cmd.Args
786785
input := strings.Join(lineInput, " ")
787786
status.RawInput = input
@@ -930,11 +929,9 @@ func AnnexAdd(filepaths []string, addchan chan<- RepoFileStatus) {
930929
log.Write("No paths to add to annex. Nothing to do.")
931930
return
932931
}
933-
var cmdargs []string
934-
if JsonBool {
935-
cmdargs = []string{"add", "--json"}
936-
} else {
937-
cmdargs = []string{"add"}
932+
cmdargs := []string{"add"}
933+
if !RawMode {
934+
cmdargs = append(cmdargs, "--json")
938935
}
939936
exclargs := annexExclArgs()
940937
if len(exclargs) > 0 {
@@ -954,21 +951,21 @@ func AnnexAdd(filepaths []string, addchan chan<- RepoFileStatus) {
954951
var status RepoFileStatus
955952
var addresult annexAction
956953
// NOTE Can differentiate "git" and "annex" files from note in JSON struct
957-
status.State = "Adding"
958954
var filenames []string
959955
for rerr = nil; rerr == nil; outline, rerr = cmd.OutReader.ReadBytes('\n') {
960956
if len(outline) == 0 {
961957
// Empty line output. Ignore
962958
continue
963959
}
964-
if !JsonBool {
960+
if RawMode {
965961
status.RawOutput = string(outline)
966962
lineInput := cmd.Args
967963
input := strings.Join(lineInput, " ")
968964
status.RawInput = input
969965
addchan <- status
970966
continue
971967
}
968+
addresult = annexAction{} // clear existing result
972969
err := json.Unmarshal(outline, &addresult)
973970
if err != nil || addresult.Command == "" {
974971
// Couldn't parse output
@@ -983,7 +980,13 @@ func AnnexAdd(filepaths []string, addchan chan<- RepoFileStatus) {
983980
status.RawInput = input
984981
status.RawOutput = string(outline)
985982
if addresult.Success {
986-
log.Write("%s added to annex", addresult.File)
983+
if addresult.Note == addedToGitNote {
984+
status.State = "Added to git"
985+
log.Write("%s added to git", addresult.File)
986+
} else {
987+
status.State = "Added to annex"
988+
log.Write("%s added to annex", addresult.File)
989+
}
987990
status.Err = nil
988991
filenames = append(filenames, status.FileName)
989992
} else {

0 commit comments

Comments
 (0)