From 12dc6dd88b6bd6ea87e4faf779e0b3f28163f411 Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Fri, 8 Jun 2018 15:27:39 -0500 Subject: [PATCH 1/5] tq/meter: introduce tq.Direction.Verb --- tq/meter.go | 5 +---- tq/transfer.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/tq/meter.go b/tq/meter.go index a42a2cbb..36a6ae2d 100644 --- a/tq/meter.go +++ b/tq/meter.go @@ -5,7 +5,6 @@ import ( "math" "os" "path/filepath" - "strings" "sync" "sync/atomic" "time" @@ -231,12 +230,10 @@ func (m *Meter) skipUpdate() bool { func (m *Meter) str() string { // (Uploading|Downloading) LFS objects: 100% (10/10) 100 MiB | 10 MiB/s - - direction := strings.Title(m.Direction.String()) + "ing" percentage := 100 * float64(m.finishedFiles) / float64(m.estimatedFiles) return fmt.Sprintf("%s LFS objects: %3.f%% (%d/%d), %s | %s", - direction, + m.Direction.Verb(), percentage, m.finishedFiles, m.estimatedFiles, humanize.FormatBytes(clamp(m.currentBytes)), diff --git a/tq/transfer.go b/tq/transfer.go index b6a31ecc..77e05aab 100644 --- a/tq/transfer.go +++ b/tq/transfer.go @@ -18,6 +18,18 @@ const ( Download = Direction(iota) ) +// Verb returns a string containing the verb form of the receiving action. +func (d Direction) Verb() string { + switch d { + case Download: + return "Downloading" + case Upload: + return "Uploading" + default: + return "" + } +} + func (d Direction) String() string { switch d { case Download: From aa2ad1243df36192b0b9303c49456df748e6d02d Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Fri, 8 Jun 2018 15:29:15 -0500 Subject: [PATCH 2/5] tq/transfer.go: add Checkout direction --- tq/transfer.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tq/transfer.go b/tq/transfer.go index 77e05aab..60484e74 100644 --- a/tq/transfer.go +++ b/tq/transfer.go @@ -16,11 +16,14 @@ type Direction int const ( Upload = Direction(iota) Download = Direction(iota) + Checkout = Direction(iota) ) // Verb returns a string containing the verb form of the receiving action. func (d Direction) Verb() string { switch d { + case Checkout: + return "Checking out" case Download: return "Downloading" case Upload: @@ -32,6 +35,8 @@ func (d Direction) Verb() string { func (d Direction) String() string { switch d { + case Checkout: + return "checkout" case Download: return "download" case Upload: From 58815a6ac4a0ed221b31d370b88d7ce080f4e665 Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Fri, 8 Jun 2018 15:29:24 -0500 Subject: [PATCH 3/5] commands/checkout: ensure that the checkout direction is printed as such --- commands/command_checkout.go | 1 + test/test-checkout.sh | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/commands/command_checkout.go b/commands/command_checkout.go index d26b0026..e77dcf6c 100644 --- a/commands/command_checkout.go +++ b/commands/command_checkout.go @@ -29,6 +29,7 @@ func checkoutCommand(cmd *cobra.Command, args []string) { var pointers []*lfs.WrappedPointer logger := tasklog.NewLogger(os.Stdout) meter := tq.NewMeter() + meter.Direction = tq.Checkout meter.Logger = meter.LoggerFromEnv(cfg.Os) logger.Enqueue(meter) chgitscanner := lfs.NewGitScanner(func(p *lfs.WrappedPointer, err error) { diff --git a/test/test-checkout.sh b/test/test-checkout.sh index ef0ee6ae..b0acec7a 100755 --- a/test/test-checkout.sh +++ b/test/test-checkout.sh @@ -41,65 +41,73 @@ begin_test "checkout" rm -rf file1.dat file2.dat file3.dat folder1/nested.dat folder2/nested.dat echo "checkout should replace all" - git lfs checkout + git lfs checkout 2>&1 | tee checkout.log [ "$contents" = "$(cat file1.dat)" ] [ "$contents" = "$(cat file2.dat)" ] [ "$contents" = "$(cat file3.dat)" ] [ "$contents" = "$(cat folder1/nested.dat)" ] [ "$contents" = "$(cat folder2/nested.dat)" ] + grep "Checking out LFS objects: 100% (5/5), 95 B" checkout.log # Remove the working directory rm -rf file1.dat file2.dat file3.dat folder1/nested.dat folder2/nested.dat echo "checkout with filters" - git lfs checkout file2.dat + git lfs checkout file2.dat 2>&1 | tee checkout.log [ "$contents" = "$(cat file2.dat)" ] [ ! -f file1.dat ] [ ! -f file3.dat ] [ ! -f folder1/nested.dat ] [ ! -f folder2/nested.dat ] + grep "Checking out LFS objects: 100% (1/1), 19 B" checkout.log echo "quotes to avoid shell globbing" - git lfs checkout "file*.dat" + git lfs checkout "file*.dat" 2>&1 | tee checkout.log [ "$contents" = "$(cat file1.dat)" ] [ "$contents" = "$(cat file3.dat)" ] [ ! -f folder1/nested.dat ] [ ! -f folder2/nested.dat ] + grep "Checking out LFS objects: 100% (3/3), 57 B" checkout.log echo "test subdir context" pushd folder1 - git lfs checkout nested.dat + git lfs checkout nested.dat 2>&1 | tee checkout.log + grep "Checking out LFS objects: 100% (1/1), 19 B" checkout.log [ "$contents" = "$(cat nested.dat)" ] [ ! -f ../folder2/nested.dat ] # test '.' in current dir rm nested.dat - git lfs checkout . + git lfs checkout . 2>&1 | tee checkout.log [ "$contents" = "$(cat nested.dat)" ] + grep "Checking out LFS objects: 100% (1/1), 19 B" checkout.log popd echo "test folder param" - git lfs checkout folder2 + git lfs checkout folder2 2>&1 | tee checkout.log [ "$contents" = "$(cat folder2/nested.dat)" ] + grep "Checking out LFS objects: 100% (1/1), 19 B" checkout.log echo "test '.' in current dir" rm -rf file1.dat file2.dat file3.dat folder1/nested.dat folder2/nested.dat - git lfs checkout . + git lfs checkout . 2>&1 | tee checkout.log [ "$contents" = "$(cat file1.dat)" ] [ "$contents" = "$(cat file2.dat)" ] [ "$contents" = "$(cat file3.dat)" ] [ "$contents" = "$(cat folder1/nested.dat)" ] [ "$contents" = "$(cat folder2/nested.dat)" ] + grep "Checking out LFS objects: 100% (5/5), 95 B" checkout.log echo "test checkout with missing data doesn't fail" git push origin master rm -rf .git/lfs/objects rm file*.dat - git lfs checkout + git lfs checkout 2>&1 | tee checkout.log [ "$(pointer $contents_oid $contentsize)" = "$(cat file1.dat)" ] [ "$(pointer $contents_oid $contentsize)" = "$(cat file2.dat)" ] [ "$(pointer $contents_oid $contentsize)" = "$(cat file3.dat)" ] [ "$contents" = "$(cat folder1/nested.dat)" ] [ "$contents" = "$(cat folder2/nested.dat)" ] + grep "Checking out LFS objects: 100% (5/5), 95 B" checkout.log ) end_test From d2e4b9b40ddb582e7de9f0bbba9dadcb0097522c Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Mon, 11 Jun 2018 12:12:59 -0500 Subject: [PATCH 4/5] test/test-checkout.sh: remove extraneous grepping --- test/test-checkout.sh | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/test/test-checkout.sh b/test/test-checkout.sh index b0acec7a..1a5f2df5 100755 --- a/test/test-checkout.sh +++ b/test/test-checkout.sh @@ -53,25 +53,23 @@ begin_test "checkout" rm -rf file1.dat file2.dat file3.dat folder1/nested.dat folder2/nested.dat echo "checkout with filters" - git lfs checkout file2.dat 2>&1 | tee checkout.log + git lfs checkout file2.dat [ "$contents" = "$(cat file2.dat)" ] [ ! -f file1.dat ] [ ! -f file3.dat ] [ ! -f folder1/nested.dat ] [ ! -f folder2/nested.dat ] - grep "Checking out LFS objects: 100% (1/1), 19 B" checkout.log echo "quotes to avoid shell globbing" - git lfs checkout "file*.dat" 2>&1 | tee checkout.log + git lfs checkout "file*.dat" [ "$contents" = "$(cat file1.dat)" ] [ "$contents" = "$(cat file3.dat)" ] [ ! -f folder1/nested.dat ] [ ! -f folder2/nested.dat ] - grep "Checking out LFS objects: 100% (3/3), 57 B" checkout.log echo "test subdir context" pushd folder1 - git lfs checkout nested.dat 2>&1 | tee checkout.log + git lfs checkout nested.dat 2>&1 grep "Checking out LFS objects: 100% (1/1), 19 B" checkout.log [ "$contents" = "$(cat nested.dat)" ] [ ! -f ../folder2/nested.dat ] @@ -79,35 +77,31 @@ begin_test "checkout" rm nested.dat git lfs checkout . 2>&1 | tee checkout.log [ "$contents" = "$(cat nested.dat)" ] - grep "Checking out LFS objects: 100% (1/1), 19 B" checkout.log popd echo "test folder param" - git lfs checkout folder2 2>&1 | tee checkout.log + git lfs checkout folder2 [ "$contents" = "$(cat folder2/nested.dat)" ] - grep "Checking out LFS objects: 100% (1/1), 19 B" checkout.log echo "test '.' in current dir" rm -rf file1.dat file2.dat file3.dat folder1/nested.dat folder2/nested.dat - git lfs checkout . 2>&1 | tee checkout.log + git lfs checkout . [ "$contents" = "$(cat file1.dat)" ] [ "$contents" = "$(cat file2.dat)" ] [ "$contents" = "$(cat file3.dat)" ] [ "$contents" = "$(cat folder1/nested.dat)" ] [ "$contents" = "$(cat folder2/nested.dat)" ] - grep "Checking out LFS objects: 100% (5/5), 95 B" checkout.log echo "test checkout with missing data doesn't fail" git push origin master rm -rf .git/lfs/objects rm file*.dat - git lfs checkout 2>&1 | tee checkout.log + git lfs checkout [ "$(pointer $contents_oid $contentsize)" = "$(cat file1.dat)" ] [ "$(pointer $contents_oid $contentsize)" = "$(cat file2.dat)" ] [ "$(pointer $contents_oid $contentsize)" = "$(cat file3.dat)" ] [ "$contents" = "$(cat folder1/nested.dat)" ] [ "$contents" = "$(cat folder2/nested.dat)" ] - grep "Checking out LFS objects: 100% (5/5), 95 B" checkout.log ) end_test From 830f611f5722b790535bd896ec6abd50d7883589 Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Mon, 11 Jun 2018 12:28:14 -0500 Subject: [PATCH 5/5] test/test-checkout.sh: remove logging grep site --- test/test-checkout.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/test-checkout.sh b/test/test-checkout.sh index 1a5f2df5..cd2633c8 100755 --- a/test/test-checkout.sh +++ b/test/test-checkout.sh @@ -69,8 +69,7 @@ begin_test "checkout" echo "test subdir context" pushd folder1 - git lfs checkout nested.dat 2>&1 - grep "Checking out LFS objects: 100% (1/1), 19 B" checkout.log + git lfs checkout nested.dat [ "$contents" = "$(cat nested.dat)" ] [ ! -f ../folder2/nested.dat ] # test '.' in current dir