From 09f5f2a35f0f4c42b2def0642540f32e59fdeeb3 Mon Sep 17 00:00:00 2001 From: "Santiago M. Mola" Date: Mon, 10 Jul 2017 18:25:28 +0200 Subject: improve delete support on push * server: implement delete-refs and announce it. * remote: check if server announced delete-refs before trying to delete and fail fast if it does not. Note that the client does not need no send 'delete-refs' back to the server to be able to delete references: ``` delete-refs ----------- If the server sends back the 'delete-refs' capability, it means that it is capable of accepting a zero-id value as the target value of a reference update. It is not sent back by the client, it simply informs the client that it can be sent zero-id values to delete references. ``` So our server implementation does not check if the client sent delete-refs back, it just accepts deletes if it receives them. --- plumbing/transport/server/receive_pack_test.go | 5 --- plumbing/transport/server/server.go | 44 +++++++------------------- 2 files changed, 12 insertions(+), 37 deletions(-) (limited to 'plumbing/transport/server') diff --git a/plumbing/transport/server/receive_pack_test.go b/plumbing/transport/server/receive_pack_test.go index 73ba60b..54c2fba 100644 --- a/plumbing/transport/server/receive_pack_test.go +++ b/plumbing/transport/server/receive_pack_test.go @@ -27,11 +27,6 @@ func (s *ReceivePackSuite) TearDownTest(c *C) { s.Suite.TearDownSuite(c) } -// TODO -func (s *ReceivePackSuite) TestSendPackAddDeleteReference(c *C) { - c.Skip("delete reference not supported yet") -} - // Overwritten, server returns error earlier. func (s *ReceivePackSuite) TestAdvertisedReferencesNotExists(c *C) { r, err := s.Client.NewReceivePackSession(s.NonExistentEndpoint, s.EmptyAuth) diff --git a/plumbing/transport/server/server.go b/plumbing/transport/server/server.go index 89fce5f..dd278c8 100644 --- a/plumbing/transport/server/server.go +++ b/plumbing/transport/server/server.go @@ -225,31 +225,11 @@ func (s *rpSession) ReceivePack(req *packp.ReferenceUpdateRequest) (*packp.Repor return s.reportStatus(), err } - updatedRefs := s.updatedReferences(req) - - if s.caps.Supports(capability.Atomic) && s.firstErr != nil { - //TODO: add support for 'atomic' once we have reference - // transactions, currently we do not announce it. - rs := s.reportStatus() - for _, cs := range rs.CommandStatuses { - if cs.Error() == nil { - cs.Status = "" - } - } - } - - for name, ref := range updatedRefs { - //TODO: add support for 'delete-refs' once we can delete - // references, currently we do not announce it. - err := s.storer.SetReference(ref) - s.setStatus(name, err) - } - + s.updateReferences(req) return s.reportStatus(), s.firstErr } -func (s *rpSession) updatedReferences(req *packp.ReferenceUpdateRequest) map[plumbing.ReferenceName]*plumbing.Reference { - refs := map[plumbing.ReferenceName]*plumbing.Reference{} +func (s *rpSession) updateReferences(req *packp.ReferenceUpdateRequest) { for _, cmd := range req.Commands { exists, err := referenceExists(s.storer, cmd.Name) if err != nil { @@ -265,19 +245,16 @@ func (s *rpSession) updatedReferences(req *packp.ReferenceUpdateRequest) map[plu } ref := plumbing.NewHashReference(cmd.Name, cmd.New) - refs[ref.Name()] = ref + err := s.storer.SetReference(ref) + s.setStatus(cmd.Name, err) case packp.Delete: if !exists { s.setStatus(cmd.Name, ErrUpdateReference) continue } - if !s.caps.Supports(capability.DeleteRefs) { - s.setStatus(cmd.Name, fmt.Errorf("delete not supported")) - continue - } - - refs[cmd.Name] = nil + err := s.storer.RemoveReference(cmd.Name) + s.setStatus(cmd.Name, err) case packp.Update: if !exists { s.setStatus(cmd.Name, ErrUpdateReference) @@ -290,11 +267,10 @@ func (s *rpSession) updatedReferences(req *packp.ReferenceUpdateRequest) map[plu } ref := plumbing.NewHashReference(cmd.Name, cmd.New) - refs[ref.Name()] = ref + err := s.storer.SetReference(ref) + s.setStatus(cmd.Name, err) } } - - return refs } func (s *rpSession) failAtomicUpdate() (*packp.ReportStatus, error) { @@ -368,6 +344,10 @@ func (*rpSession) setSupportedCapabilities(c *capability.List) error { return err } + if err := c.Set(capability.DeleteRefs); err != nil { + return err + } + return c.Set(capability.ReportStatus) } -- cgit