aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2018-05-16 06:54:13 +0200
committerGitHub <noreply@github.com>2018-05-16 06:54:13 +0200
commit57570e84f8c5739f0f4a59387493e590e709dde9 (patch)
tree9e8386962b8000781c851dc9367839d9e8d2ce65
parente63b032e91ce35e0ecd5f27d43be655625e8af36 (diff)
parent939793b42974c12abf2d2b65facee489004a9e06 (diff)
downloadgo-git-57570e84f8c5739f0f4a59387493e590e709dde9.tar.gz
Merge pull request #833 from jfontan/slow-reference-updatev4.4.0
git: remote, Do not iterate all references on update.
-rw-r--r--remote.go24
1 files changed, 22 insertions, 2 deletions
diff --git a/remote.go b/remote.go
index 4b86955..60461d6 100644
--- a/remote.go
+++ b/remote.go
@@ -371,14 +371,22 @@ func (r *Remote) addReferencesToUpdate(
refspecs []config.RefSpec,
localRefs []*plumbing.Reference,
remoteRefs storer.ReferenceStorer,
- req *packp.ReferenceUpdateRequest) error {
+ req *packp.ReferenceUpdateRequest,
+) error {
+ // This references dictionary will be used to search references by name.
+ refsDict := make(map[string]*plumbing.Reference)
+ for _, ref := range localRefs {
+ refsDict[ref.Name().String()] = ref
+ }
+
for _, rs := range refspecs {
if rs.IsDelete() {
if err := r.deleteReferences(rs, remoteRefs, req); err != nil {
return err
}
} else {
- if err := r.addOrUpdateReferences(rs, localRefs, remoteRefs, req); err != nil {
+ err := r.addOrUpdateReferences(rs, localRefs, refsDict, remoteRefs, req)
+ if err != nil {
return err
}
}
@@ -390,9 +398,21 @@ func (r *Remote) addReferencesToUpdate(
func (r *Remote) addOrUpdateReferences(
rs config.RefSpec,
localRefs []*plumbing.Reference,
+ refsDict map[string]*plumbing.Reference,
remoteRefs storer.ReferenceStorer,
req *packp.ReferenceUpdateRequest,
) error {
+ // If it is not a wilcard refspec we can directly search for the reference
+ // in the references dictionary.
+ if !rs.IsWildcard() {
+ ref, ok := refsDict[rs.Src()]
+ if !ok {
+ return nil
+ }
+
+ return r.addReferenceIfRefSpecMatches(rs, remoteRefs, ref, req)
+ }
+
for _, ref := range localRefs {
err := r.addReferenceIfRefSpecMatches(rs, remoteRefs, ref, req)
if err != nil {