Debian Codegraph @

git/githistory/ref_updater.go

raw symbols SCIP
1 package githistoryscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/githistory`/
2
3 import (
4 "bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/"
5 "encoding/hexscip-go gomod github.com/golang/go/src go1.25.0 `encoding/hex`/"
6 "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/"
7 "ioscip-go gomod github.com/golang/go/src go1.25.0 io/"
8 "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/"
9
10 "github.com/git-lfs/git-lfs/v3/errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/"
11 "github.com/git-lfs/git-lfs/v3/gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/"
12 "github.com/git-lfs/git-lfs/v3/tasklogscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/"
13 "github.com/git-lfs/git-lfs/v3/trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/"
14 "github.com/git-lfs/gitobj/v2scip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/"
15 )
16
17 // refUpdater is a type responsible for moving references from one point in the
18 // Git object graph to another.
19 type refUpdaterscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/githistory`/refUpdater# struct {
20 // cacheFn is a function that returns the SHA1 transformation from an
21 // original hash to a new one. It specifies a "bool" return value
22 // signaling whether or not that given "old" SHA1 was migrated.
23 cacheFnscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/githistory`/refUpdater#cacheFn. func(old []byte) ([]byte, bool)
24 // logger logs the progress of reference updating.
25 loggerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/githistory`/refUpdater#logger. *tasklogscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/.Loggerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/Logger#
26 // refs is a set of *git.Ref's to migrate.
27 refsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/githistory`/refUpdater#refs. []*gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/.Refscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Ref#
28 // root is the given directory on disk in which the repository is
29 // located.
30 rootscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/githistory`/refUpdater#root. string
31 // db is the *ObjectDatabase from which blobs, commits, and trees are
32 // loaded.
33 dbscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/githistory`/refUpdater#db. *gitobjscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/.ObjectDatabasescip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/ObjectDatabase#
34 }
35
36 // updateRefs performs the reference update(s) from existing locations (see:
37 // Refs) to their respective new locations in the graph (see CacheFn).
38 //
39 // It creates reflog entries as well as stderr log entries as it progresses
40 // through the reference updates.
41 //
42 // It returns any error encountered, or nil if the reference update(s) was/were
43 // successful.
44 func (r *refUpdaterscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/githistory`/refUpdater#) updateRefsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/githistory`/refUpdater#updateRefs().() error {
45 list := r.loggerscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/githistory`/refUpdater#logger..Listscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/Logger#List().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("Updating refs"))
46 defer list.Completescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/ListTask#Complete().()
47
48 var maxNameLen int
49 for _, ref := range r.refsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/githistory`/refUpdater#refs. {
50 maxNameLen = max(maxNameLen, len(ref.Namescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Ref#Name.))
51 }
52
53 cmd, err := gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/.UpdateRefsFromStdinscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/UpdateRefsFromStdin().(r.rootscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/githistory`/refUpdater#root.)
54 if err != nil {
55 return err
56 }
57
58 var output bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.25.0 bytes/Buffer#
59 cmd.Stdoutscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#Stdout. = &output
60 cmd.Stderrscip-go gomod github.com/golang/go/src go1.25.0 `os/exec`/Cmd#Stderr. = &output
61
62 input, err := cmd.StdinPipescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/subprocess`/Cmd#StdinPipe().()
63 if err != nil {
64 return err
65 }
66
67 err = cmd.Startscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/subprocess`/Cmd#Start().()
68 if err != nil {
69 return err
70 }
71 defer func() {
72 if cmd != nil {
73 cmd.Waitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/subprocess`/Cmd#Wait().()
74 }
75 }()
76
77 gitUpRefTransactions := gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/.IsGitVersionAtLeastscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/IsGitVersionAtLeast().("2.27.0")
78 if gitUpRefTransactions {
79 if _, err = ioscip-go gomod github.com/golang/go/src go1.25.0 io/.WriteStringscip-go gomod github.com/golang/go/src go1.25.0 io/WriteString().(input, "start\x00"); err != nil {
80 return err
81 }
82 }
83
84 seen := make(map[string][]byte)
85 for _, ref := range r.refsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/githistory`/refUpdater#refs. {
86 if err := r.updateOneRefscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/githistory`/refUpdater#updateOneRef().(list, maxNameLen, seen, ref, input); err != nil {
87 return err
88 }
89 }
90
91 if gitUpRefTransactions {
92 if _, err = ioscip-go gomod github.com/golang/go/src go1.25.0 io/.WriteStringscip-go gomod github.com/golang/go/src go1.25.0 io/WriteString().(input, "prepare\x00commit\x00"); err != nil {
93 return err
94 }
95 }
96
97 if err = input.Closescip-go gomod github.com/golang/go/src go1.25.0 io/Closer#Close().(); err != nil {
98 return err
99 }
100
101 err = cmd.Waitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/subprocess`/Cmd#Wait().()
102 cmd = nil
103 if err != nil {
104 return fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("git update-ref failed: %s, output: %s", err.Error(), output.Stringscip-go gomod github.com/golang/go/src go1.25.0 bytes/Buffer#String().())
105 }
106
107 return nil
108 }
109
110 func (r *refUpdaterscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/githistory`/refUpdater#) updateOneTagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/githistory`/refUpdater#updateOneTag().(tag *gitobjscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/.Tagscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/Tag#, toObj []byte) ([]byte, error) {
111 newTag, err := r.dbscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/githistory`/refUpdater#db..WriteTagscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/ObjectDatabase#WriteTag().(&gitobjscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/.Tagscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/Tag#{
112 Objectscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/Tag#Object.: toObj,
113 ObjectTypescip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/Tag#ObjectType.: tag.ObjectTypescip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/Tag#ObjectType.,
114 Namescip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/Tag#Name.: tag.Namescip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/Tag#Name.,
115 Taggerscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/Tag#Tagger.: tag.Taggerscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/Tag#Tagger.,
116
117 Messagescip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/Tag#Message.: tag.Messagescip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/Tag#Message.,
118 })
119
120 if err != nil {
121 return nil, errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.Wrapscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/Wrap().(err, trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("could not rewrite tag: %s", tag.Namescip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/Tag#Name.))
122 }
123 return newTag, nil
124 }
125
126 func (r *refUpdaterscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/githistory`/refUpdater#) updateOneRefscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/githistory`/refUpdater#updateOneRef().(list *tasklogscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/.ListTaskscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/ListTask#, maxNameLen int, seen map[string][]byte, ref *gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/.Refscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Ref#, gitUpRefIn ioscip-go gomod github.com/golang/go/src go1.25.0 io/.WriteCloserscip-go gomod github.com/golang/go/src go1.25.0 io/WriteCloser#) error {
127 sha1, err := hexscip-go gomod github.com/golang/go/src go1.25.0 `encoding/hex`/.DecodeStringscip-go gomod github.com/golang/go/src go1.25.0 `encoding/hex`/DecodeString().(ref.Shascip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Ref#Sha.)
128 if err != nil {
129 return errorsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/.Wrapscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/errors`/Wrap().(err, trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("could not decode: %q", ref.Shascip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Ref#Sha.))
130 }
131
132 refspec := ref.Refspecscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Ref#Refspec().()
133 if _, ok := seen[refspec]; ok {
134 return nil
135 }
136
137 to, ok := r.cacheFnscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/githistory`/refUpdater#cacheFn.(sha1)
138
139 if ref.Typescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Ref#Type. == gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/.RefTypeLocalTagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/RefTypeLocalTag. {
140 tag, _ := r.dbscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/githistory`/refUpdater#db..Tagscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/ObjectDatabase#Tag().(sha1)
141 if tag != nil && tag.ObjectTypescip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/Tag#ObjectType. == gitobjscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/.TagObjectTypescip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/TagObjectType. {
142 innerTag, _ := r.dbscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/githistory`/refUpdater#db..Tagscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/ObjectDatabase#Tag().(tag.Objectscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/Tag#Object.)
143 name := fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("refs/tags/%s", innerTag.Namescip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/Tag#Name.)
144 if _, ok := seen[name]; !ok {
145 old, err := gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/.ResolveRefscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ResolveRef().(name)
146 if err != nil {
147 return err
148 }
149
150 err = r.updateOneRefscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/githistory`/refUpdater#updateOneRef().(list, maxNameLen, seen, old, gitUpRefIn)
151 if err != nil {
152 return err
153 }
154 }
155
156 updatedSha, refUpOk := seen[name]
157 if !refUpOk {
158 return nil
159 }
160
161 newTag, err := r.updateOneTagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/githistory`/refUpdater#updateOneTag().(tag, updatedSha)
162 if newTag == nil {
163 return err
164 }
165 to = newTag
166 ok = true
167 } else if tag != nil && tag.ObjectTypescip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/Tag#ObjectType. == gitobjscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/.CommitObjectTypescip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/CommitObjectType. {
168 toObj, okObj := r.cacheFnscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/githistory`/refUpdater#cacheFn.(tag.Objectscip-go gomod github.com/git-lfs/gitobj/v2 v2.1.1 `github.com/git-lfs/gitobj/v2`/Tag#Object.)
169 if !okObj {
170 return nil
171 }
172
173 newTag, err := r.updateOneTagscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git/githistory`/refUpdater#updateOneTag().(tag, toObj)
174 if newTag == nil {
175 return err
176 }
177 to = newTag
178 ok = true
179 }
180 }
181
182 if !ok {
183 return nil
184 }
185
186 if _, err = ioscip-go gomod github.com/golang/go/src go1.25.0 io/.WriteStringscip-go gomod github.com/golang/go/src go1.25.0 io/WriteString().(gitUpRefIn, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("update %s\x00%s\x00\x00", ref.Refspecscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Ref#Refspec().(), hexscip-go gomod github.com/golang/go/src go1.25.0 `encoding/hex`/.EncodeToStringscip-go gomod github.com/golang/go/src go1.25.0 `encoding/hex`/EncodeToString().(to))); err != nil {
187 return err
188 }
189
190 namePadding := max(maxNameLen-len(ref.Namescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Ref#Name.), 0)
191 list.Entryscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/ListTask#Entry().(fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().(" %s%s\t%s -> %x", ref.Namescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Ref#Name., stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 strings/Repeat().(" ", namePadding), ref.Shascip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Ref#Sha., to))
192 seen[refspec] = to
193 return nil
194 }