Skip to content

Commit 6b3ca32

Browse files
committed
all: initial commit
0 parents  commit 6b3ca32

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 GitHub, Inc. and Git LFS contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# verify-pack(1)
2+
3+
`verify-pack(1)` parses v1 and v2 packfiles and prints the locations of the
4+
objects contained within them.
5+
6+
## Usage
7+
8+
`verify-pack(1)` accepts the filepath of a v1 or v2 packfile as its argument,
9+
and a line-delimited list of object names (in ASCII-encoded SHA-1 format) on
10+
stdin.
11+
12+
## License
13+
14+
MIT.

cmd/verify-pack/main.go

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"encoding/hex"
6+
"fmt"
7+
"os"
8+
9+
"github.com/git-lfs/git-lfs/git/odb/pack"
10+
"github.com/pkg/errors"
11+
12+
"golang.org/x/exp/mmap"
13+
)
14+
15+
func main() {
16+
if len(os.Args) <= 1 {
17+
die(usage())
18+
}
19+
20+
f, err := mmap.Open(os.Args[1])
21+
if err != nil {
22+
die(errors.Wrap(err, "could not open index file").Error())
23+
}
24+
25+
idx, err := pack.DecodeIndex(f)
26+
if err != nil {
27+
die(errors.Wrap(err, "could not decode index").Error())
28+
}
29+
30+
scanner := bufio.NewScanner(os.Stdin)
31+
for scanner.Scan() {
32+
name := scanner.Text()
33+
34+
oid, err := hex.DecodeString(name)
35+
if err != nil {
36+
die(errors.Wrapf(err, "could not decode name %q", name).Error())
37+
}
38+
39+
e, err := idx.Entry(oid)
40+
if err != nil {
41+
die(errors.Wrapf(err, "could not find entry %q", name).Error())
42+
}
43+
44+
fmt.Printf("%+v\n", e)
45+
}
46+
47+
if err := scanner.Err(); err != nil {
48+
die(err.Error())
49+
}
50+
51+
if err := f.Close(); err != nil {
52+
die(errors.Wrap(err, "could not close file").Error())
53+
}
54+
}
55+
56+
func die(msg string) {
57+
fmt.Fprintln(os.Stderr, msg)
58+
os.Exit(1)
59+
}
60+
61+
func usage() string {
62+
return fmt.Sprintf("usage: %s <pack>", os.Args[0])
63+
}

0 commit comments

Comments
 (0)