Skip to content

Commit 3225dc8

Browse files
committed
git/githistory: avoid exporting refUpdater fields
The refUpdater structure and related methods were introduced to the "githistory" package in PR git-lfs#2340, as part of the series of PRs that implemented the "git lfs migrate" command. The structure is not exported outside of the package, as it is only used by the Rewrite() method of the Rewriter structure in the same package. (The Rewriter structure and methods are the principal external interface of the "githistory" package.) While the structure itself is not exported, most of its elements are exported, as is its UpdateRefs() method. However, none of these are referenced outside of the "githistory" package, so we rename them now to clarify that they are only used within the package.
1 parent 1b2c2c9 commit 3225dc8

File tree

3 files changed

+36
-36
lines changed

3 files changed

+36
-36
lines changed

git/githistory/ref_updater.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,41 @@ import (
1616
// refUpdater is a type responsible for moving references from one point in the
1717
// Git object graph to another.
1818
type refUpdater struct {
19-
// CacheFn is a function that returns the SHA1 transformation from an
19+
// cacheFn is a function that returns the SHA1 transformation from an
2020
// original hash to a new one. It specifies a "bool" return value
2121
// signaling whether or not that given "old" SHA1 was migrated.
22-
CacheFn func(old []byte) ([]byte, bool)
23-
// Logger logs the progress of reference updating.
24-
Logger *tasklog.Logger
25-
// Refs is a set of *git.Ref's to migrate.
26-
Refs []*git.Ref
27-
// Root is the given directory on disk in which the repository is
22+
cacheFn func(old []byte) ([]byte, bool)
23+
// logger logs the progress of reference updating.
24+
logger *tasklog.Logger
25+
// refs is a set of *git.Ref's to migrate.
26+
refs []*git.Ref
27+
// root is the given directory on disk in which the repository is
2828
// located.
29-
Root string
30-
29+
root string
30+
// db is the *ObjectDatabase from which blobs, commits, and trees are
31+
// loaded.
3132
db *gitobj.ObjectDatabase
3233
}
3334

34-
// UpdateRefs performs the reference update(s) from existing locations (see:
35+
// updateRefs performs the reference update(s) from existing locations (see:
3536
// Refs) to their respective new locations in the graph (see CacheFn).
3637
//
3738
// It creates reflog entries as well as stderr log entries as it progresses
3839
// through the reference updates.
3940
//
4041
// It returns any error encountered, or nil if the reference update(s) was/were
4142
// successful.
42-
func (r *refUpdater) UpdateRefs() error {
43-
list := r.Logger.List(tr.Tr.Get("Updating refs"))
43+
func (r *refUpdater) updateRefs() error {
44+
list := r.logger.List(tr.Tr.Get("Updating refs"))
4445
defer list.Complete()
4546

4647
var maxNameLen int
47-
for _, ref := range r.Refs {
48+
for _, ref := range r.refs {
4849
maxNameLen = tools.MaxInt(maxNameLen, len(ref.Name))
4950
}
5051

5152
seen := make(map[string]struct{})
52-
for _, ref := range r.Refs {
53+
for _, ref := range r.refs {
5354
if err := r.updateOneRef(list, maxNameLen, seen, ref); err != nil {
5455
return err
5556
}
@@ -86,7 +87,7 @@ func (r *refUpdater) updateOneRef(list *tasklog.ListTask, maxNameLen int, seen m
8687
}
8788
seen[refspec] = struct{}{}
8889

89-
to, ok := r.CacheFn(sha1)
90+
to, ok := r.cacheFn(sha1)
9091

9192
if ref.Type == git.RefTypeLocalTag {
9293
tag, _ := r.db.Tag(sha1)
@@ -121,7 +122,7 @@ func (r *refUpdater) updateOneRef(list *tasklog.ListTask, maxNameLen int, seen m
121122
to = newTag
122123
ok = true
123124
} else if tag != nil && tag.ObjectType == gitobj.CommitObjectType {
124-
toObj, okObj := r.CacheFn(tag.Object)
125+
toObj, okObj := r.cacheFn(tag.Object)
125126
if !okObj {
126127
return nil
127128
}
@@ -139,7 +140,7 @@ func (r *refUpdater) updateOneRef(list *tasklog.ListTask, maxNameLen int, seen m
139140
return nil
140141
}
141142

142-
if err := git.UpdateRefIn(r.Root, ref, to, ""); err != nil {
143+
if err := git.UpdateRefIn(r.root, ref, to, ""); err != nil {
143144
return err
144145
}
145146

git/githistory/ref_updater_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@ func TestRefUpdaterMovesRefs(t *testing.T) {
1515
"refs/tags/middle", HexDecode(t, "228afe30855933151f7a88e70d9d88314fd2f191"))
1616

1717
updater := &refUpdater{
18-
CacheFn: func(old []byte) ([]byte, bool) {
18+
cacheFn: func(old []byte) ([]byte, bool) {
1919
return HexDecode(t, "d941e4756add6b06f5bee766fcf669f55419f13f"), true
2020
},
21-
Refs: []*git.Ref{
21+
refs: []*git.Ref{
2222
{
2323
Name: "middle",
2424
Sha: "228afe30855933151f7a88e70d9d88314fd2f191",
2525
Type: git.RefTypeLocalTag,
2626
},
2727
},
28-
Root: root,
28+
root: root,
2929
db: db,
3030
}
3131

32-
err := updater.UpdateRefs()
32+
err := updater.updateRefs()
3333

3434
assert.NoError(t, err)
3535

@@ -45,21 +45,21 @@ func TestRefUpdaterMovesRefsWithAnnotatedTags(t *testing.T) {
4545
"refs/tags/middle", HexDecode(t, "05797a38b05f910e6efe40dc1a5c0a046a9403e8"))
4646

4747
updater := &refUpdater{
48-
CacheFn: func(old []byte) ([]byte, bool) {
48+
cacheFn: func(old []byte) ([]byte, bool) {
4949
return HexDecode(t, "d941e4756add6b06f5bee766fcf669f55419f13f"), true
5050
},
51-
Refs: []*git.Ref{
51+
refs: []*git.Ref{
5252
{
5353
Name: "middle",
5454
Sha: "05797a38b05f910e6efe40dc1a5c0a046a9403e8",
5555
Type: git.RefTypeLocalTag,
5656
},
5757
},
58-
Root: root,
58+
root: root,
5959
db: db,
6060
}
6161

62-
err := updater.UpdateRefs()
62+
err := updater.updateRefs()
6363

6464
assert.NoError(t, err)
6565

@@ -75,21 +75,21 @@ func TestRefUpdaterIgnoresUnovedRefs(t *testing.T) {
7575
"refs/tags/middle", HexDecode(t, "228afe30855933151f7a88e70d9d88314fd2f191"))
7676

7777
updater := &refUpdater{
78-
CacheFn: func(old []byte) ([]byte, bool) {
78+
cacheFn: func(old []byte) ([]byte, bool) {
7979
return nil, false
8080
},
81-
Refs: []*git.Ref{
81+
refs: []*git.Ref{
8282
{
8383
Name: "middle",
8484
Sha: "228afe30855933151f7a88e70d9d88314fd2f191",
8585
Type: git.RefTypeLocalTag,
8686
},
8787
},
88-
Root: root,
88+
root: root,
8989
db: db,
9090
}
9191

92-
err := updater.UpdateRefs()
92+
err := updater.updateRefs()
9393

9494
assert.NoError(t, err)
9595

git/githistory/rewriter.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,14 @@ func (r *Rewriter) Rewrite(opt *RewriteOptions) ([]byte, error) {
316316
root, _ := r.db.Root()
317317

318318
updater := &refUpdater{
319-
CacheFn: r.uncacheCommit,
320-
Logger: r.l,
321-
Refs: refs,
322-
Root: root,
323-
324-
db: r.db,
319+
cacheFn: r.uncacheCommit,
320+
logger: r.l,
321+
refs: refs,
322+
root: root,
323+
db: r.db,
325324
}
326325

327-
if err := updater.UpdateRefs(); err != nil {
326+
if err := updater.updateRefs(); err != nil {
328327
return nil, errors.Wrap(err, tr.Tr.Get("could not update refs"))
329328
}
330329
}

0 commit comments

Comments
 (0)