Repository navigation
Expand file tree
/
Copy pathapi.go
More file actions
214 lines (185 loc) · 6.97 KB
/
Copy pathapi.go
File metadata and controls
214 lines (185 loc) · 6.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
package kgraph
import (
"slices"
"strings"
"github.com/linux-analysis/kgraph/kernel"
)
// Commit is a commit of the graph.
type Commit struct {
g *Graph
i uint32
}
// Commit finds the one commit that the full or abbreviated hex id names,
// in either case; ok is false when no commit or several do.
func (g *Graph) Commit(id string) (Commit, bool) {
if len(id) == 0 || len(id) > 40 {
return Commit{}, false
}
i, ok := g.resolve([]byte(strings.ToLower(id)))
if !ok {
return Commit{}, false
}
return Commit{g, uint32(i)}, true
}
// Ambiguous tells whether the ids of several commits start with the
// abbreviated id, in either case, so that Commit finds none.
func (g *Graph) Ambiguous(id string) bool {
if len(id) >= 40 {
return false
}
_, found := g.prefix([]byte(strings.ToLower(id)))
return found > 1
}
// Hash is the full hex id of the commit.
func (c Commit) Hash() string { return c.g.hashes[c.i].String() }
// Mainline tells whether the mainline tip or a mainline tag reaches the
// commit.
func (c Commit) Mainline() bool { return c.g.mainline(c.i) }
// Tree is where the commit is: mainline, else the first of stable, next
// and the vendor branches, such as uek/uek8/u2, that has it.
func (c Commit) Tree() string { return c.g.treeOf(c.i) }
// Date is the committer date, Unix time.
func (c Commit) Date() int64 { return c.g.date[c.i] }
// Tag is the first release tag in version order that contains the commit,
// such as v6.7-rc1 or v6.6.8; "" when none does yet.
func (c Commit) Tag() string {
if t := c.g.firstTag[c.i]; t != none {
return c.g.tags[t].Name
}
return ""
}
// Release is the mainline release of Tag, -rc folded: v6.7 for v6.7-rc1.
// It is Unreleased when Tag is a stable tag or "".
func (c Commit) Release() kernel.Release {
if t := c.g.firstTag[c.i]; t != none && !c.g.tags[t].Stable {
return c.g.tags[t].Release
}
return kernel.Unreleased
}
// SeriesRelease is the release a stable Tag is a patch level of: v6.6 for
// v6.6.8. It is Unreleased when Tag is a mainline tag or "".
func (c Commit) SeriesRelease() kernel.Release {
if t := c.g.firstTag[c.i]; t != none && c.g.tags[t].Stable {
return c.g.tags[t].Release
}
return kernel.Unreleased
}
// Upstream is the mainline commit a backport was made from: the one its
// message names, or else the only earlier mainline commit with its author
// and subject, or for a vendor commit with its subject alone. ok is false
// for a commit that is no backport, and for a vendor commit that names
// several upstreams, as Red Hat's squashed rebases do: it is a backport of
// each, a patch of its own.
func (c Commit) Upstream() (Commit, bool) { return c.g.commit(c.g.upstream[c.i]) }
// Reverts is the commit that the commit reverts; ok is false when it
// reverts none.
func (c Commit) Reverts() (Commit, bool) { return c.g.commit(c.g.revert[c.i]) }
// Fixes are the commits that the commit's own Fixes: tags name, in message
// order: by id, or by the quoted subject when no commit of the graph has
// the id. A tag that names a backport names that backport, where the
// patch's Fixes name the patch it carries.
func (c Commit) Fixes() []Commit { return c.g.commits(c.g.fixes[c.g.fstart[c.i]:c.g.fstart[c.i+1]]) }
// RevertedBy are the commits that revert the commit, oldest first.
func (c Commit) RevertedBy() []Commit {
return c.g.commits(c.g.reverters[c.g.rstart[c.i]:c.g.rstart[c.i+1]])
}
// Patch is the patch the commit carries: its own, or for a backport its
// upstream's.
func (c Commit) Patch() Patch { return Patch{c.g, c.g.of[c.i]} }
// commit is the commit with index i, ok false for none.
func (g *Graph) commit(i int32) (Commit, bool) {
if i == none {
return Commit{}, false
}
return Commit{g, uint32(i)}, true
}
func (g *Graph) commits(list []uint32) []Commit {
if len(list) == 0 {
return nil
}
out := make([]Commit, len(list))
for j, i := range list {
out[j] = Commit{g, i}
}
return out
}
// Patch is a change: the mainline and linux-next commits that are the
// same patch merged more than once, its copies, with the stable and vendor
// commits backported from any of them. Every question about a change is a
// question about its patch, whichever of its commits names it. A commit
// outside mainline and linux-next that is no backport is a patch of its
// own.
type Patch struct {
g *Graph
c uint32 // the canonical copy
}
// Commit is the canonical copy of the patch: the copy in the earliest
// release, untagged ones last and a mainline one before a linux-next one.
func (p Patch) Commit() Commit { return Commit{p.g, p.c} }
// Copies are the copies of the patch, canonical first.
func (p Patch) Copies() []Commit { return p.g.commits(p.g.members[p.g.mstart[p.c]:p.g.mstart[p.c+1]]) }
// Fixes are the patches that the Fixes: tags of the patch's commits name,
// its copies' first and then its backports', in message order: by id, or
// by the quoted subject when no commit of the graph has the id.
func (p Patch) Fixes() []Patch {
g := p.g
var out []Patch
for _, run := range [][]uint32{g.members[g.mstart[p.c]:g.mstart[p.c+1]], g.backports[g.bstart[p.c]:g.bstart[p.c+1]]} {
for _, m := range run {
for _, t := range g.fixes[g.fstart[m]:g.fstart[m+1]] {
if f := (Patch{g, g.of[t]}); f != p && !slices.Contains(out, f) {
out = append(out, f)
}
}
}
}
return out
}
// FixedBy are the patches with a commit whose Fixes: tags name the patch,
// oldest first.
func (p Patch) FixedBy() []Patch {
return p.g.patchList(p.g.fixedBy[p.g.fbstart[p.c]:p.g.fbstart[p.c+1]])
}
// Needs are the patches that the patch needs first, oldest first: what the
// Depends-on: tags of its commits, the ids of their Cc: stable lines and
// "depends on commit" in their text name, and the patch of every stable
// commit whose Stable-dep-of: tag names the patch.
func (p Patch) Needs() []Patch { return p.g.patchList(p.g.sorted(withKey(p.g.needs, uint64(p.c)))) }
// NeededBy are the patches that need the patch first, as Needs tells,
// oldest first.
func (p Patch) NeededBy() []Patch {
return p.g.patchList(p.g.sorted(withKey(p.g.neededBy, uint64(p.c))))
}
// Series are the patches of the patch series the patch came in, oldest
// first: those with mainline or linux-next commits whose Link: lines name
// a message id of the same series, git send-email's, b4's or
// format-patch's less the patch number. A patch of no series is alone.
func (p Patch) Series() []Patch {
g := p.g
list := []uint32{p.c}
for _, m := range g.members[g.mstart[p.c]:g.mstart[p.c+1]] {
if key := g.facts.patchset[m]; key != 0 && g.pooled(m) {
for _, c := range withKey(g.series, key) {
list = append(list, g.of[c])
}
}
}
slices.SortFunc(list, g.byDate)
return g.patchList(slices.Compact(list))
}
func (g *Graph) patchList(list []uint32) []Patch {
if len(list) == 0 {
return nil
}
out := make([]Patch, len(list))
for j, c := range list {
out[j] = Patch{g, c}
}
return out
}
// sorted orders a copy of list oldest first.
func (g *Graph) sorted(list []uint32) []uint32 {
list = slices.Clone(list)
slices.SortFunc(list, g.byDate)
return list
}