Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2020-12-14 20:23:02 +0300
committerÆvar Arnfjörð Bjarmason <avarab@gmail.com>2020-12-15 03:20:04 +0300
commitaec19f1a1dc88c2bbaeebdd5f255a19f24620fc0 (patch)
tree921ea80b1ee826042464a448afab69b8fea41c92
parentc4ee34eb64b613305fe92811d40b048708837315 (diff)
Updater: dispatch to update-ref create/delete/updateavar/use-update-ref-delete-and-create
Instead of always issuing "update" commands, use the "create" and "delete" verbs too. This doesn't make any difference in the result as git does the same dispatching internally, but makes things a bit more obvious if you're tracing the output.
-rw-r--r--changelogs/unreleased/avar-use-update-ref-delete-and-create.yml5
-rw-r--r--internal/git/updateref/updateref.go14
-rw-r--r--internal/gitaly/service/operations/update_with_hooks.go2
3 files changed, 20 insertions, 1 deletions
diff --git a/changelogs/unreleased/avar-use-update-ref-delete-and-create.yml b/changelogs/unreleased/avar-use-update-ref-delete-and-create.yml
new file mode 100644
index 000000000..240c41335
--- /dev/null
+++ b/changelogs/unreleased/avar-use-update-ref-delete-and-create.yml
@@ -0,0 +1,5 @@
+---
+title: 'Cleaner & DeleteRefs: use safer ''update-ref delete'' with <oldvalue> argument'
+merge_request: 2929
+author:
+type: fixed
diff --git a/internal/git/updateref/updateref.go b/internal/git/updateref/updateref.go
index c141b4eac..f82098626 100644
--- a/internal/git/updateref/updateref.go
+++ b/internal/git/updateref/updateref.go
@@ -65,6 +65,20 @@ func New(ctx context.Context, repo repository.GitRepo, opts ...UpdaterOpt) (*Upd
return &Updater{repo: repo, cmd: cmd}, nil
}
+// CreateUpdateDelete dispatches to Create()/Update()/Delete() as needed
+//
+// The underlying "update-ref" does the same dispatching depending on
+// what it get passed.
+func (u *Updater) CreateUpdateDelete(ref, newvalue, oldvalue string) error {
+ if newvalue == git.NullSHA {
+ return u.Delete(ref, oldvalue)
+ } else if oldvalue == git.NullSHA {
+ return u.Create(ref, newvalue)
+ } else {
+ return u.Update(ref, newvalue, oldvalue)
+ }
+}
+
// Create commands the reference to be created with the sha specified in value
func (u *Updater) Create(ref, value string) error {
_, err := fmt.Fprintf(u.cmd, "create %s\x00%s\x00", ref, value)
diff --git a/internal/gitaly/service/operations/update_with_hooks.go b/internal/gitaly/service/operations/update_with_hooks.go
index ba90634bc..937b00f40 100644
--- a/internal/gitaly/service/operations/update_with_hooks.go
+++ b/internal/gitaly/service/operations/update_with_hooks.go
@@ -80,7 +80,7 @@ func (s *Server) updateReferenceWithHooks(ctx context.Context, repo *gitalypb.Re
return err
}
- if err := updater.Update(reference, newrev, oldrev); err != nil {
+ if err := updater.CreateUpdateDelete(reference, newrev, oldrev); err != nil {
return err
}