Skip to content

fetch requests thin packs that PackIndexer cannot index #16

Closed

Description

@dnnsjsk

The fetch negotiation advertises thin-pack (

, ), so a server may send REF_DELTA objects whose bases are not in the pack but already in the local repository. PackIndexer only looks for REF_DELTA bases inside the received pack and throws otherwise (
private static function resolveRefDeltaBase(
int $currentOffset,
string $baseHash,
array $parsed,
array &$resolved,
array &$hashToOffset,
int $depth,
): array {
if (isset($hashToOffset[$baseHash])) {
return self::resolveObjectAtOffset($hashToOffset[$baseHash], $parsed, $resolved, $hashToOffset, $depth);
}
foreach (array_keys($parsed) as $offset) {
if ($offset === $currentOffset) {
continue;
}
$candidate = self::resolveObjectAtOffset($offset, $parsed, $resolved, $hashToOffset, $depth);
if ($candidate['id']->hex === $baseHash) {
return $candidate;
}
}
throw PackParseException::invalidDeltaBase("ref-delta base {$baseHash} not found in pack");
).

A thin pack produced by git pack-objects --thin fails to index with:

PackParseException: ref-delta base 7599e0c... not found in pack

The exception is not a ProtocolException, so fetch() does not fall back and stops after writing the .pack without its .idx (

pitmaster/src/Repository.php

Lines 1611 to 1614 in 5beb97d

if (!is_dir($packDir)) {
mkdir($packDir, 0777, true);
}
). Incremental fetches from a git server that sends a thin pack can fail this way. The same limit applies to reading packs: PackFile resolves REF_DELTA bases only within the same pack (
} else {
if ($entry->baseHash === null) {
throw PackParseException::invalidDeltaBase("ref-delta missing baseHash at {$offset}");
}
$basePackOffset = $this->index->findOffset($entry->baseHash);
if ($basePackOffset === null) {
throw PackParseException::invalidDeltaBase(
"ref-delta base {$entry->baseHash} not found in pack"
);
}
$base = $this->resolveAtOffset($basePackOffset, $depth + 1);
).

Expected

Either stop advertising thin-pack, or resolve external bases from the object database while indexing and complete the pack (append the missing bases), as git index-pack --fix-thin does.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions