Skip to content

Commit

Permalink
Don't load git packs if the .pack file is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
qmfrederik authored and AArnott committed Apr 29, 2021
1 parent 96b6548 commit 675a2fb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
17 changes: 0 additions & 17 deletions src/NerdBank.GitVersioning/ManagedGit/GitPack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,6 @@ public class GitPack : IDisposable
// are closed by the caller).
private readonly Queue<GitPackPooledStream> pooledStreams = new Queue<GitPackPooledStream>();

/// <summary>
/// Initializes a new instance of the <see cref="GitPack"/> class.
/// </summary>
/// <param name="repository">
/// The repository to which this pack file belongs.
/// </param>
/// <param name="name">
/// The name of the pack file.
/// </param>
internal GitPack(GitRepository repository, string name)
: this(
repository.GetObjectBySha,
indexPath: Path.Combine(repository.ObjectDirectory, "pack", $"{name}.idx"),
packPath: Path.Combine(repository.ObjectDirectory, "pack", $"{name}.pack"))
{
}

/// <summary>
/// Initializes a new instance of the <see cref="GitPack"/> class.
/// </summary>
Expand Down
15 changes: 12 additions & 3 deletions src/NerdBank.GitVersioning/ManagedGit/GitRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -648,15 +648,24 @@ private GitPack[] LoadPacks()
}

var indexFiles = Directory.GetFiles(packDirectory, "*.idx");
GitPack[] packs = new GitPack[indexFiles.Length];
List<GitPack> packs = new List<GitPack>(indexFiles.Length);

for (int i = 0; i < indexFiles.Length; i++)
{

var name = Path.GetFileNameWithoutExtension(indexFiles[i]);
packs[i] = new GitPack(this, name);
var indexPath = Path.Combine(this.ObjectDirectory, "pack", $"{name}.idx");
var packPath = Path.Combine(this.ObjectDirectory, "pack", $"{name}.pack");

// Only proceed if both the packfile and index file exist.
if (!File.Exists(packPath))
{
packs.Add(new GitPack(this.GetObjectBySha, indexPath, packPath));
}

}

return packs;
return packs.ToArray();
}

private static string TrimEndingDirectorySeparator(string path)
Expand Down

0 comments on commit 675a2fb

Please sign in to comment.