Skip to content

Commit

Permalink
all: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ttaylorr committed Jul 25, 2017
0 parents commit 6b3ca32
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 GitHub, Inc. and Git LFS contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# verify-pack(1)

`verify-pack(1)` parses v1 and v2 packfiles and prints the locations of the
objects contained within them.

## Usage

`verify-pack(1)` accepts the filepath of a v1 or v2 packfile as its argument,
and a line-delimited list of object names (in ASCII-encoded SHA-1 format) on
stdin.

## License

MIT.
63 changes: 63 additions & 0 deletions cmd/verify-pack/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package main

import (
"bufio"
"encoding/hex"
"fmt"
"os"

"github.com/git-lfs/git-lfs/git/odb/pack"
"github.com/pkg/errors"

"golang.org/x/exp/mmap"
)

func main() {
if len(os.Args) <= 1 {
die(usage())
}

f, err := mmap.Open(os.Args[1])
if err != nil {
die(errors.Wrap(err, "could not open index file").Error())
}

idx, err := pack.DecodeIndex(f)
if err != nil {
die(errors.Wrap(err, "could not decode index").Error())
}

scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
name := scanner.Text()

oid, err := hex.DecodeString(name)
if err != nil {
die(errors.Wrapf(err, "could not decode name %q", name).Error())
}

e, err := idx.Entry(oid)
if err != nil {
die(errors.Wrapf(err, "could not find entry %q", name).Error())
}

fmt.Printf("%+v\n", e)
}

if err := scanner.Err(); err != nil {
die(err.Error())
}

if err := f.Close(); err != nil {
die(errors.Wrap(err, "could not close file").Error())
}
}

func die(msg string) {
fmt.Fprintln(os.Stderr, msg)
os.Exit(1)
}

func usage() string {
return fmt.Sprintf("usage: %s <pack>", os.Args[0])
}

0 comments on commit 6b3ca32

Please sign in to comment.