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
|
package main
import (
"bufio"
"fmt"
"os"
"gitlab.com/gitlab-org/gitaly/v14/internal/git/packfile"
)
func listBitmapPack(idxFile string) {
idx, err := packfile.ReadIndex(idxFile)
noError(err)
noError(idx.LabelObjectTypes())
out := bufio.NewWriter(os.Stdout)
defer flush(out)
fprintf(out, "# pack-%s\n", idx.ID)
for _, o := range idx.PackfileOrder {
fprintln(out, o)
}
}
func mapBitmapPack(idxFile string) {
idx, err := packfile.ReadIndex(idxFile)
noError(err)
noError(idx.LabelObjectTypes())
out := bufio.NewWriter(os.Stdout)
defer flush(out)
fprintf(out, "# pack-%s\n", idx.ID)
// Use a mix of lower and upper case that is easier to distinguish than all upper / all lower.
fprintln(out, "# b: blob, C: commit, e: tree, T: tag")
for _, o := range idx.PackfileOrder {
c := ""
switch o.Type {
case packfile.TBlob:
c = "b"
case packfile.TCommit:
c = "C"
case packfile.TTree:
c = "e"
case packfile.TTag:
c = "T"
}
fprint(out, c+" ")
}
}
func listBitmapCommits(idxFile string) {
idx, err := packfile.ReadIndex(idxFile)
noError(err)
noError(idx.LabelObjectTypes())
out := bufio.NewWriter(os.Stdout)
defer flush(out)
fprintf(out, "# pack-%s\n", idx.ID)
for i := 0; i < idx.IndexBitmap.NumBitmapCommits(); i++ {
bc, err := idx.IndexBitmap.BitmapCommit(i)
noError(err)
fprintln(out, bc.OID)
}
}
func listBitmapReachable(idxFile string, commitID string) {
idx, err := packfile.ReadIndex(idxFile)
noError(err)
noError(idx.LabelObjectTypes())
var bc *packfile.BitmapCommit
for i := 0; i < idx.IndexBitmap.NumBitmapCommits(); i++ {
var err error
bc, err = idx.BitmapCommit(i)
noError(err)
if bc.OID == commitID {
break
}
}
if bc == nil || bc.OID != commitID {
fatal(fmt.Errorf("bitmap commit not found: %s", commitID))
}
out := bufio.NewWriter(os.Stdout)
defer flush(out)
fprintf(out, "# pack-%s\n", idx.ID)
fprintf(out, "# bitmap commit %s\n", bc.OID)
noError(bc.Bitmap.Scan(func(i int) error {
_, err := fmt.Fprintln(out, idx.PackfileOrder[i])
return err
}))
}
|