From 234afc8888d8d7b134c5d2b2094f68f57051ef0e Mon Sep 17 00:00:00 2001 From: Michael Pfister Date: Wed, 20 Apr 2016 19:11:16 -0700 Subject: [PATCH 1/6] Adds repo version info to repo stat command addresses #2571 License: MIT Signed-off-by: Mike Pfister --- core/commands/repo.go | 2 ++ core/corerepo/stat.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/core/commands/repo.go b/core/commands/repo.go index 0fdcf01064a..0c660b66110 100644 --- a/core/commands/repo.go +++ b/core/commands/repo.go @@ -109,6 +109,7 @@ set of stored objects and print repo statistics. It outputs to stdout: NumObjects int Number of objects in the local repo. RepoPath string The path to the repo being currently used. RepoSize int Size in bytes that the repo is currently taking. +Version string The repo version `, }, Run: func(req cmds.Request, res cmds.Response) { @@ -151,6 +152,7 @@ RepoSize int Size in bytes that the repo is currently taking. fmt.Fprintf(buf, "RepoSize \t %d\n", stat.RepoSize) } fmt.Fprintf(buf, "RepoPath \t %s\n", stat.RepoPath) + fmt.Fprintf(buf, "Version \t %s\n", stat.Version) return buf, nil }, diff --git a/core/corerepo/stat.go b/core/corerepo/stat.go index 65abf2efd42..77dcaf6862e 100644 --- a/core/corerepo/stat.go +++ b/core/corerepo/stat.go @@ -10,6 +10,7 @@ type Stat struct { NumObjects uint64 RepoSize uint64 // size in bytes RepoPath string + Version string } func RepoStat(n *core.IpfsNode, ctx context.Context) (*Stat, error) { @@ -39,5 +40,6 @@ func RepoStat(n *core.IpfsNode, ctx context.Context) (*Stat, error) { NumObjects: count, RepoSize: usage, RepoPath: path, + Version: "fs-repo@" + fsrepo.RepoVersion, }, nil } From cd0a33c7c29de0b36636a4897c812bff6ea5cc00 Mon Sep 17 00:00:00 2001 From: Michael Pfister Date: Wed, 20 Apr 2016 19:41:44 -0700 Subject: [PATCH 2/6] Adds repo version subcommand Fixes #2571 License: MIT Signed-off-by: Mike Pfister --- core/commands/repo.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/core/commands/repo.go b/core/commands/repo.go index 0c660b66110..455dbc97334 100644 --- a/core/commands/repo.go +++ b/core/commands/repo.go @@ -7,12 +7,17 @@ import ( corerepo "github.com/ipfs/go-ipfs/core/corerepo" config "github.com/ipfs/go-ipfs/repo/config" lockfile "github.com/ipfs/go-ipfs/repo/fsrepo/lock" + fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo" u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" "io" "os" "path/filepath" ) +type RepoVersion struct { + Version string +} + var RepoCmd = &cmds.Command{ Helptext: cmds.HelpText{ Tagline: "Manipulate the IPFS repo.", @@ -25,6 +30,7 @@ var RepoCmd = &cmds.Command{ "gc": repoGcCmd, "stat": repoStatCmd, "fsck": RepoFsckCmd, + "version": repoVersionCmd, }, } @@ -208,5 +214,40 @@ daemons are running. Type: MessageOutput{}, Marshalers: cmds.MarshalerMap{ cmds.Text: MessageTextMarshaler, +var repoVersionCmd = &cmds.Command{ + Helptext: cmds.HelpText{ + Tagline: "Show the repo version.", + ShortDescription: ` +'ipfs repo version' returns the current repo version. +`, + }, + + Options: []cmds.Option{ + cmds.BoolOption("quiet", "q", "Write minimal output."), + }, + Run: func(req cmds.Request, res cmds.Response) { + res.SetOutput(&RepoVersion{ + Version: fsrepo.RepoVersion, + }) + }, + Type: RepoVersion{}, + Marshalers: cmds.MarshalerMap{ + cmds.Text: func(res cmds.Response) (io.Reader, error) { + response := res.Output().(*RepoVersion) + + quiet, _, err := res.Request().Option("quiet").Bool() + if err != nil { + return nil, err + } + + buf := new(bytes.Buffer) + if quiet { + buf = bytes.NewBufferString(fmt.Sprintf("fs-repo@%s\n", response.Version)) + } else { + buf = bytes.NewBufferString(fmt.Sprintf("ipfs repo version fs-repo@%s\n", response.Version)) + } + return buf, nil + + }, }, } From 74e701d852d05ea11201803286ff3413c5705997 Mon Sep 17 00:00:00 2001 From: Michael Pfister Date: Thu, 21 Apr 2016 11:03:11 -0700 Subject: [PATCH 3/6] Add period to helptext License: MIT Signed-off-by: Michael Pfister --- core/commands/repo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/commands/repo.go b/core/commands/repo.go index 455dbc97334..a68f3ef8019 100644 --- a/core/commands/repo.go +++ b/core/commands/repo.go @@ -115,7 +115,7 @@ set of stored objects and print repo statistics. It outputs to stdout: NumObjects int Number of objects in the local repo. RepoPath string The path to the repo being currently used. RepoSize int Size in bytes that the repo is currently taking. -Version string The repo version +Version string The repo version. `, }, Run: func(req cmds.Request, res cmds.Response) { From 7517bb393b3d24c6ba42df96012eb493cfb7a75b Mon Sep 17 00:00:00 2001 From: Michael Pfister Date: Fri, 3 Jun 2016 13:20:32 -0700 Subject: [PATCH 4/6] fixing bad rebase License: MIT Signed-off-by: Michael Pfister --- core/commands/repo.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/core/commands/repo.go b/core/commands/repo.go index a68f3ef8019..40147c0dfc2 100644 --- a/core/commands/repo.go +++ b/core/commands/repo.go @@ -6,8 +6,8 @@ import ( cmds "github.com/ipfs/go-ipfs/commands" corerepo "github.com/ipfs/go-ipfs/core/corerepo" config "github.com/ipfs/go-ipfs/repo/config" - lockfile "github.com/ipfs/go-ipfs/repo/fsrepo/lock" fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo" + lockfile "github.com/ipfs/go-ipfs/repo/fsrepo/lock" u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util" "io" "os" @@ -27,9 +27,9 @@ var RepoCmd = &cmds.Command{ }, Subcommands: map[string]*cmds.Command{ - "gc": repoGcCmd, - "stat": repoStatCmd, - "fsck": RepoFsckCmd, + "gc": repoGcCmd, + "stat": repoStatCmd, + "fsck": RepoFsckCmd, "version": repoVersionCmd, }, } @@ -214,6 +214,9 @@ daemons are running. Type: MessageOutput{}, Marshalers: cmds.MarshalerMap{ cmds.Text: MessageTextMarshaler, + }, +} + var repoVersionCmd = &cmds.Command{ Helptext: cmds.HelpText{ Tagline: "Show the repo version.", From 53ccaa9722d05c7cb03664fb4485ca785fba773b Mon Sep 17 00:00:00 2001 From: Michael Pfister Date: Fri, 3 Jun 2016 13:39:56 -0700 Subject: [PATCH 5/6] adding tests License: MIT Signed-off-by: Michael Pfister --- test/sharness/t0080-repo.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/sharness/t0080-repo.sh b/test/sharness/t0080-repo.sh index cbe4e8dcf2d..5b61cbd9064 100755 --- a/test/sharness/t0080-repo.sh +++ b/test/sharness/t0080-repo.sh @@ -244,6 +244,21 @@ test_expect_success "repo stats are updated correctly" ' test $(get_field_num "RepoSize" repo-stats-2) -ge $(get_field_num "RepoSize" repo-stats) ' +test_expect_success "'ipfs repo version' succeeds" ' + ipfs repo version > repo-version +' + +test_expect_success "repo version came out correct" ' + egrep "^ipfs repo version fs-repo@[0-9]" repo-version >/dev/null +' + +test_expect_success "'ipfs repo version' succeeds" ' + ipfs repo version -q > repo-version-q +' +test_expect_success "repo version came out correct" ' + egrep "^fs-repo@[0-9]" repo-version-q >/dev/null +' + test_kill_ipfs_daemon test_done From 5aaebd0b2dbc61f053b6ede03518f2ec6c1c4059 Mon Sep 17 00:00:00 2001 From: Michael Pfister Date: Fri, 3 Jun 2016 13:54:39 -0700 Subject: [PATCH 6/6] Adding tests for repo stat and repo version cmd License: MIT Signed-off-by: Michael Pfister --- test/sharness/t0080-repo.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/sharness/t0080-repo.sh b/test/sharness/t0080-repo.sh index 5b61cbd9064..2da6a824fa7 100755 --- a/test/sharness/t0080-repo.sh +++ b/test/sharness/t0080-repo.sh @@ -233,6 +233,7 @@ test_expect_success "repo stats came out correct" ' grep "RepoPath" repo-stats && grep "RepoSize" repo-stats && grep "NumObjects" repo-stats + grep "Version" repo-stats ' test_expect_success "'ipfs repo stat' after adding a file" ' @@ -252,7 +253,7 @@ test_expect_success "repo version came out correct" ' egrep "^ipfs repo version fs-repo@[0-9]" repo-version >/dev/null ' -test_expect_success "'ipfs repo version' succeeds" ' +test_expect_success "'ipfs repo version -q' succeeds" ' ipfs repo version -q > repo-version-q ' test_expect_success "repo version came out correct" '