Skip to content

Commit 561ed22

Browse files
committed
pack/set: ignore packs without indices
When we look for packs to read, we look for a pack file, and then an index, and fail if either one is missing. When Git looks for packs to read, it looks only for indices and then checks if the pack is present. The Git approach handles the case when there is an extra pack that lacks an index, while our approach does not. Consequently, we can get various errors (showing up so far only on Windows) when an index is missing. If the index file cannot be read for any reason, simply skip the entire pack altogether and continue on. This leaves us no more or less functional than Git in terms of discovering objects and makes our error handling more robust.
1 parent fe8fbf7 commit 561ed22

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pack/set.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,15 @@ func NewSet(db string) (*Set, error) {
5555

5656
name := submatch[1]
5757

58-
packf, err := os.Open(filepath.Join(pd, fmt.Sprintf("pack-%s.pack", name)))
58+
idxf, err := os.Open(filepath.Join(pd, fmt.Sprintf("pack-%s.idx", name)))
5959
if err != nil {
60-
return nil, err
60+
// We have a pack (since it matched the regex), but the
61+
// index is missing or unusable. Skip this pack and
62+
// continue on with the next one, as Git does.
63+
continue
6164
}
6265

63-
idxf, err := os.Open(filepath.Join(pd, fmt.Sprintf("pack-%s.idx", name)))
66+
packf, err := os.Open(filepath.Join(pd, fmt.Sprintf("pack-%s.pack", name)))
6467
if err != nil {
6568
return nil, err
6669
}

0 commit comments

Comments
 (0)