Debian Codegraph @

tasklog/percentage_task.go

raw symbols SCIP
1 package tasklogscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/
2
3 import (
4 "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/"
5 "mathscip-go gomod github.com/golang/go/src go1.25.0 math/"
6 "sync/atomicscip-go gomod github.com/golang/go/src go1.25.0 `sync/atomic`/"
7 "timescip-go gomod github.com/golang/go/src go1.25.0 time/"
8
9 "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`/"
10 )
11
12 // PercentageTask is a task that is performed against a known number of
13 // elements.
14 type PercentageTaskscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask# struct {
15 // members managed via sync/atomic must be aligned at the top of this
16 // structure (see: https://github.com/git-lfs/git-lfs/pull/2880).
17
18 // n is the number of elements whose work has been completed. It is
19 // managed sync/atomic.
20 nscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#n. uint64
21 // total is the total number of elements to execute work upon.
22 totalscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#total. uint64
23 // msg is the task message.
24 msgscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#msg. string
25 // ch is a channel which is written to when the task state changes and
26 // is closed when the task is completed.
27 chscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#ch. chan *Updatescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/Update#
28 }
29
30 func NewPercentageTaskscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/NewPercentageTask().(msg string, total uint64) *PercentageTaskscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask# {
31 p := &PercentageTaskscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#{
32 msgscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#msg.: msg,
33 totalscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#total.: total,
34 chscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#ch.: make(chan *Updatescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/Update#, 1),
35 }
36 p.Countscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#Count().(0)
37
38 return p
39 }
40
41 // Count indicates that work has been completed against "n" number of elements,
42 // marking the task as complete if the total "n" given to all invocations of
43 // this method is equal to total.
44 //
45 // Count returns the new total number of (atomically managed) elements that have
46 // been completed.
47 func (c *PercentageTaskscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#) Countscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#Count().(n uint64) (new uint64) {
48 if new = atomicscip-go gomod github.com/golang/go/src go1.25.0 `sync/atomic`/.AddUint64scip-go gomod github.com/golang/go/src go1.25.0 `sync/atomic`/AddUint64().(&c.nscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#n., n); new > c.totalscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#total. {
49 panic(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().("tasklog: %s", 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().("counted too many items")))
50 }
51
52 var percentage float64
53 if c.totalscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#total. == 0 {
54 percentage = 100
55 } else {
56 percentage = 100 * float64(new) / float64(c.totalscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#total.)
57 }
58
59 c.chscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#ch. <- &Updatescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/Update#{
60 Sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/Update#S.: 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: %3.f%% (%d/%d)",
61 c.msgscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#msg., mathscip-go gomod github.com/golang/go/src go1.25.0 math/.Floorscip-go gomod github.com/golang/go/src go1.25.0 math/Floor().(percentage), new, c.totalscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#total.),
62 Atscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/Update#At.: timescip-go gomod github.com/golang/go/src go1.25.0 time/.Nowscip-go gomod github.com/golang/go/src go1.25.0 time/Now().(),
63 }
64
65 if new >= c.totalscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#total. {
66 close(c.chscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#ch.)
67 }
68
69 return new
70 }
71
72 // Entry logs a line-delimited task entry.
73 func (c *PercentageTaskscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#) Entryscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#Entry().(update string) {
74 c.chscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#ch. <- &Updatescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/Update#{
75 Sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/Update#S.: 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\n", update),
76 Atscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/Update#At.: timescip-go gomod github.com/golang/go/src go1.25.0 time/.Nowscip-go gomod github.com/golang/go/src go1.25.0 time/Now().(),
77 Forcescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/Update#Force.: true,
78 }
79 }
80
81 // Complete notes that the task is completed by setting the number of
82 // completed elements to the total number of elements, and if necessary
83 // closing the Updates channel, which yields the logger to the next Task.
84 func (c *PercentageTaskscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#) Completescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#Complete().() {
85 if count := atomicscip-go gomod github.com/golang/go/src go1.25.0 `sync/atomic`/.SwapUint64scip-go gomod github.com/golang/go/src go1.25.0 `sync/atomic`/SwapUint64().(&c.nscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#n., c.totalscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#total.); count < c.totalscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#total. {
86 close(c.chscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#ch.)
87 }
88 }
89
90 // Updates implements Task.Updates and returns a channel which is written to
91 // when the state of this task changes, and closed when the task is completed.
92 func (c *PercentageTaskscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#) Updatesscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#Updates().() <-chan *Updatescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/Update# {
93 return c.chscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#ch.
94 }
95
96 // Throttled implements Task.Throttled and returns true, indicating that this
97 // task is throttled.
98 func (c *PercentageTaskscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#) Throttledscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tasklog`/PercentageTask#Throttled().() bool { return true }