Skip to content

Commit aaf3328

Browse files
committed
Move most output behind a -v (verbose mode) flag.
1 parent 2f9e42c commit aaf3328

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

git-subtrac.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ import (
88
"os"
99
)
1010

11-
func debugf(fmt string, args ...interface{}) {
12-
log.Printf(fmt, args...)
13-
}
14-
1511
func fatalf(fmt string, args ...interface{}) {
1612
log.Fatalf("git-subtrac: "+fmt, args...)
1713
}
@@ -32,10 +28,12 @@ func usagef(format string, args ...interface{}) {
3228

3329
func main() {
3430
log.SetFlags(0)
31+
infof := log.Printf
3532

3633
repodir := getopt.StringLong("git-dir", 'd', ".", "path to git repo")
3734
excludes := getopt.ListLong("exclude", 'x', "", "commitids to exclude")
3835
autoexclude := getopt.BoolLong("auto-exclude", 0, "auto exclude missing commits")
36+
verbose := getopt.BoolLong("verbose", 'v', "verbose mode")
3937
getopt.Parse()
4038

4139
r, err := git.PlainOpen(*repodir)
@@ -48,7 +46,13 @@ func main() {
4846
usagef("no command specified.")
4947
}
5048

51-
c := NewCache(*repodir, r, *excludes, *autoexclude, debugf)
49+
var debugf func(fmt string, args ...interface{})
50+
if *verbose {
51+
debugf = infof
52+
} else {
53+
debugf = func(fmt string, args ...interface{}) {}
54+
}
55+
c := NewCache(*repodir, r, *excludes, *autoexclude, debugf, infof)
5256

5357
switch args[0] {
5458
case "update":

subtrac.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func (t Trac) String() string {
3838

3939
type Cache struct {
4040
debugf func(fmt string, args ...interface{})
41+
infof func(fmt string, args ...interface{})
4142
repoDir string
4243
repo *git.Repository
4344
autoexclude bool
@@ -47,9 +48,10 @@ type Cache struct {
4748

4849
func NewCache(rdir string, r *git.Repository, excludes []string,
4950
autoexclude bool,
50-
debugf func(fmt string, args ...interface{})) *Cache {
51+
debugf, infof func(fmt string, args ...interface{})) *Cache {
5152
c := Cache{
5253
debugf: debugf,
54+
infof: infof,
5355
repoDir: rdir,
5456
repo: r,
5557
autoexclude: autoexclude,
@@ -93,7 +95,7 @@ func (c *Cache) UpdateBranchRefs() error {
9395
if strings.HasSuffix(name, ".trac") {
9496
return nil
9597
}
96-
c.debugf("Scanning branch: %v\n", name)
98+
c.infof("Scanning branch: %v\n", name)
9799
commit, err := c.TracByRef(name)
98100
if err != nil {
99101
return err
@@ -110,7 +112,7 @@ func (c *Cache) UpdateBranchRefs() error {
110112
for i := range branches {
111113
newname := string(branches[i].Name()) + ".trac"
112114
hash := commits[i].Hash
113-
c.debugf("Updating %.10v -> %v\n", hash, newname)
115+
c.infof("Updating %.10v -> %v\n", hash, newname)
114116

115117
refname := plumbing.ReferenceName(newname)
116118
ref := plumbing.NewHashReference(refname, hash)
@@ -290,7 +292,7 @@ func commitPath(path string, sub int) string {
290292
}
291293

292294
func (c *Cache) tryFetchFromSubmodules(path string, hash plumbing.Hash) error {
293-
c.debugf("Searching submodules for: %v\n", path)
295+
c.infof("Searching submodules for: %v\n", path)
294296
wt, err := c.repo.Worktree()
295297
if err != nil {
296298
return fmt.Errorf("git worktree: %v", err)
@@ -307,9 +309,10 @@ func (c *Cache) tryFetchFromSubmodules(path string, hash plumbing.Hash) error {
307309
}
308310
_, err = subr.CommitObject(hash)
309311
if err != nil {
310-
c.debugf(" ...not in %v\n", subpath)
312+
c.infof(" ...not in %v\n", subpath)
311313
continue
312314
}
315+
c.infof(" ...found! in %v\n", subpath)
313316
brname := fmt.Sprintf("subtrac-tmp-%v", hash)
314317
brrefname := plumbing.NewBranchReferenceName(brname)
315318
ref := plumbing.NewHashReference(brrefname, hash)

0 commit comments

Comments
 (0)