Skip to content

Commit 1865f33

Browse files
committed
Add a --show-refs option, to show what refs are being processed
This will help people figure out the right reference selection options.
1 parent 99c5f75 commit 1865f33

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

git-sizer.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const Usage = `usage: git-sizer [OPTS]
5252
prefix (e.g., '--exclude=refs/notes')
5353
--exclude-regexp pattern don't process references matching the specified
5454
regular expression
55+
--show-refs show which refs are being included/excluded
5556
5657
Regular expression patterns must match the full reference name.
5758
@@ -166,6 +167,7 @@ func mainImplementation(args []string) error {
166167
var progress bool
167168
var version bool
168169
var filter git.IncludeExcludeFilter
170+
var showRefs bool
169171

170172
flags := pflag.NewFlagSet("git-sizer", pflag.ContinueOnError)
171173
flags.Usage = func() {
@@ -241,6 +243,7 @@ func mainImplementation(args []string) error {
241243
atty = false
242244
}
243245
flags.BoolVar(&progress, "progress", atty, "report progress to stderr")
246+
flags.BoolVar(&showRefs, "show-refs", false, "list the references being processed")
244247
flags.BoolVar(&version, "version", false, "report the git-sizer version number")
245248
flags.Var(&NegatedBoolValue{&progress}, "no-progress", "suppress progress output")
246249
flags.Lookup("no-progress").NoOptDefVal = "true"
@@ -292,7 +295,23 @@ func mainImplementation(args []string) error {
292295

293296
var historySize sizes.HistorySize
294297

295-
historySize, err = sizes.ScanRepositoryUsingGraph(repo, filter.Filter, nameStyle, progress)
298+
var refFilter git.ReferenceFilter = filter.Filter
299+
300+
if showRefs {
301+
oldRefFilter := refFilter
302+
fmt.Fprintf(os.Stderr, "References (included references marked with '+'):\n")
303+
refFilter = func(ref git.Reference) bool {
304+
b := oldRefFilter(ref)
305+
if b {
306+
fmt.Fprintf(os.Stderr, "+ %s\n", ref.Refname)
307+
} else {
308+
fmt.Fprintf(os.Stderr, " %s\n", ref.Refname)
309+
}
310+
return b
311+
}
312+
}
313+
314+
historySize, err = sizes.ScanRepositoryUsingGraph(repo, refFilter, nameStyle, progress)
296315
if err != nil {
297316
return fmt.Errorf("error scanning repository: %s", err)
298317
}

0 commit comments

Comments
 (0)