From 35d72ac806d73f0c2c2a1a9882321d08044bb6f8 Mon Sep 17 00:00:00 2001 From: Dave Borowitz Date: Fri, 7 Oct 2011 15:31:19 -0700 Subject: [PATCH] Add a DFS repository description and reference it in each pack Just as DfsPackDescription describes a pack but does not imply it is open in memory, a DfsRepositoryDescription describes a repository at a basic level without it necessarily being open. Change-Id: I890b5fccdda12c1090cfabf4083b5c0e98d717f6 --- .../jgit/storage/dfs/DfsObjDatabase.java | 16 +++- .../jgit/storage/dfs/DfsPackDescription.java | 21 ++++- .../jgit/storage/dfs/DfsRepository.java | 8 ++ .../storage/dfs/DfsRepositoryBuilder.java | 21 +++++ .../storage/dfs/DfsRepositoryDescription.java | 91 +++++++++++++++++++ .../jgit/storage/dfs/InMemoryRepository.java | 22 +++-- 6 files changed, 165 insertions(+), 14 deletions(-) create mode 100644 org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsRepositoryDescription.java diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsObjDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsObjDatabase.java index 8c95340756..5a6c630bff 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsObjDatabase.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsObjDatabase.java @@ -111,15 +111,22 @@ public abstract class DfsObjDatabase extends ObjectDatabase { private final AtomicReference packList; + private final DfsRepository repository; + private DfsReaderOptions readerOptions; /** - * Initialize an object database for are repository. + * Initialize an object database for our repository. + * + * @param repository + * repository owning this object database. * * @param options * how readers should access the object database. */ - protected DfsObjDatabase(DfsReaderOptions options) { + protected DfsObjDatabase(DfsRepository repository, + DfsReaderOptions options) { + this.repository = repository; this.packList = new AtomicReference(NO_PACKS); this.readerOptions = options; } @@ -151,6 +158,11 @@ public abstract class DfsObjDatabase extends ObjectDatabase { return scanPacks(NO_PACKS).packs; } + /** @return repository owning this object database. */ + protected DfsRepository getRepository() { + return repository; + } + /** * Generate a new unique name for a pack file. * diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackDescription.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackDescription.java index 88a1ec345f..9e1e597afe 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackDescription.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackDescription.java @@ -57,6 +57,8 @@ import org.eclipse.jgit.storage.pack.PackWriter; * modified once initialized and presented to the JGit DFS library. */ public class DfsPackDescription implements Comparable { + private final DfsRepositoryDescription repoDesc; + private final String packName; private long lastModified; @@ -74,7 +76,7 @@ public class DfsPackDescription implements Comparable { private PackWriter.Statistics stats; /** - * Initialize a description by pack name. + * Initialize a description by pack name and repository. *

* The corresponding index file is assumed to exist and end with ".idx" * instead of ".pack". If this is not true implementors must extend the @@ -85,11 +87,19 @@ public class DfsPackDescription implements Comparable { * * @param name * name of the pack file. Must end with ".pack". + * @param repoDesc + * description of the repo containing the pack file. */ - public DfsPackDescription(String name) { + public DfsPackDescription(DfsRepositoryDescription repoDesc, String name) { + this.repoDesc = repoDesc; this.packName = name; } + /** @return description of the repository. */ + public DfsRepositoryDescription getRepositoryDescription() { + return repoDesc; + } + /** @return name of the pack file. */ public String getPackName() { return packName; @@ -231,8 +241,11 @@ public class DfsPackDescription implements Comparable { @Override public boolean equals(Object b) { - if (b instanceof DfsPackDescription) - return getPackName().equals(((DfsPackDescription) b).getPackName()); + if (b instanceof DfsPackDescription) { + DfsPackDescription desc = (DfsPackDescription) b; + return getPackName().equals(desc.getPackName()) && + getRepositoryDescription().equals(desc.getRepositoryDescription()); + } return false; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsRepository.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsRepository.java index df54f2fca5..577e1fa249 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsRepository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsRepository.java @@ -57,6 +57,8 @@ import org.eclipse.jgit.storage.file.ReflogReader; public abstract class DfsRepository extends Repository { private final DfsConfig config; + private final DfsRepositoryDescription description; + /** * Initialize a DFS repository. * @@ -66,6 +68,7 @@ public abstract class DfsRepository extends Repository { protected DfsRepository(DfsRepositoryBuilder builder) { super(builder); this.config = new DfsConfig(); + this.description = builder.getRepositoryDescription(); } @Override @@ -74,6 +77,11 @@ public abstract class DfsRepository extends Repository { @Override public abstract DfsRefDatabase getRefDatabase(); + /** @return a description of this repository. */ + public DfsRepositoryDescription getDescription() { + return description; + } + /** * Check if the repository already exists. * diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsRepositoryBuilder.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsRepositoryBuilder.java index 6fd3ccaebb..a41779f4d0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsRepositoryBuilder.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsRepositoryBuilder.java @@ -60,6 +60,8 @@ public abstract class DfsRepositoryBuilder { private DfsReaderOptions readerOptions; + private DfsRepositoryDescription repoDesc; + /** @return options used by readers accessing the repository. */ public DfsReaderOptions getReaderOptions() { return readerOptions; @@ -77,11 +79,30 @@ public abstract class DfsRepositoryBuilder() { @Override public InMemoryRepository build() throws IOException { @@ -39,7 +44,7 @@ public class InMemoryRepository extends DfsRepository { } }); - objdb = new MemObjDatabase(); + objdb = new MemObjDatabase(this); refdb = new MemRefDatabase(); } @@ -57,8 +62,8 @@ public class InMemoryRepository extends DfsRepository { private final AtomicInteger packId = new AtomicInteger(); private List packs = new ArrayList(); - MemObjDatabase() { - super(new DfsReaderOptions()); + MemObjDatabase(DfsRepository repo) { + super(repo, new DfsReaderOptions()); } @Override @@ -69,7 +74,8 @@ public class InMemoryRepository extends DfsRepository { @Override protected DfsPackDescription newPack(PackSource source) { int id = packId.incrementAndGet(); - return new MemPack("pack-" + id + "-" + source.name()); + return new MemPack("pack-" + id + "-" + source.name(), + getRepository().getDescription()); } @Override @@ -136,8 +142,8 @@ public class InMemoryRepository extends DfsRepository { private byte[] packIndex; - MemPack(String name) { - super(name); + MemPack(String name, DfsRepositoryDescription repoDesc) { + super(repoDesc, name); } } -- 2.39.5