diff options
| author | 2026-03-08 03:40:00 +0800 | |
|---|---|---|
| committer | 2026-03-08 03:40:00 +0800 | |
| commit | cb207dc2c9ac9218f4e1e75ec3aa46616eaa6c87 (patch) | |
| tree | 5a602996e40f01f522b6a3dcfec485ca65c204d0 /receivepack/service/apply.go | |
| parent | format/pack/ingest: Add more progress (diff) | |
| signature | No signature | |
receivepack/service, format/pack/ingest: Progress uniform
Diffstat (limited to 'receivepack/service/apply.go')
| -rw-r--r-- | receivepack/service/apply.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/receivepack/service/apply.go b/receivepack/service/apply.go index f802e0e8..0f9e07f9 100644 --- a/receivepack/service/apply.go +++ b/receivepack/service/apply.go @@ -1,30 +1,38 @@ package service import ( + "codeberg.org/lindenii/furgit/internal/utils" "codeberg.org/lindenii/furgit/objectid" "codeberg.org/lindenii/furgit/refstore" ) func (service *Service) applyAtomic(result *Result, commands []Command) error { + total := len(commands) + utils.WriteProgressf(service.opts.Progress, "updating refs: 0/%d\r", total) + tx, err := service.opts.Refs.BeginTransaction() if err != nil { return err } - for _, command := range commands { + for i, command := range commands { err = queueWriteTransaction(tx, command) if err != nil { _ = tx.Abort() fillCommandErrors(result, commands, err.Error()) + utils.WriteProgressf(service.opts.Progress, "updating refs: failed at %d/%d\n", i+1, total) return nil } + + utils.WriteProgressf(service.opts.Progress, "updating refs: %d/%d\r", i+1, total) } err = tx.Commit() if err != nil { fillCommandErrors(result, commands, err.Error()) + utils.WriteProgressf(service.opts.Progress, "updating refs: failed at commit\n") return nil } @@ -33,11 +41,15 @@ func (service *Service) applyAtomic(result *Result, commands []Command) error { for _, command := range commands { result.Commands = append(result.Commands, successCommandResult(command)) } + utils.WriteProgressf(service.opts.Progress, "updating refs: done.\n") return nil } func (service *Service) applyBatch(result *Result, commands []Command) error { + total := len(commands) + utils.WriteProgressf(service.opts.Progress, "updating refs...\r") + batch, err := service.opts.Refs.BeginBatch() if err != nil { return err @@ -49,6 +61,8 @@ func (service *Service) applyBatch(result *Result, commands []Command) error { batchResults, err := batch.Apply() if err != nil && len(batchResults) == 0 { + utils.WriteProgressf(service.opts.Progress, "updating refs: failed at apply\n") + return err } @@ -63,9 +77,11 @@ func (service *Service) applyBatch(result *Result, commands []Command) error { } result.Commands = append(result.Commands, item) + utils.WriteProgressf(service.opts.Progress, "updating refs: %d/%d\r", i+1, total) } result.Applied = appliedAny + utils.WriteProgressf(service.opts.Progress, "updating refs: done.\n") return nil } |
