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
This commit is contained in:
parent
5a38e5b440
commit
35d72ac806
|
@ -111,15 +111,22 @@ public static enum PackSource {
|
||||||
|
|
||||||
private final AtomicReference<PackList> packList;
|
private final AtomicReference<PackList> packList;
|
||||||
|
|
||||||
|
private final DfsRepository repository;
|
||||||
|
|
||||||
private DfsReaderOptions readerOptions;
|
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
|
* @param options
|
||||||
* how readers should access the object database.
|
* how readers should access the object database.
|
||||||
*/
|
*/
|
||||||
protected DfsObjDatabase(DfsReaderOptions options) {
|
protected DfsObjDatabase(DfsRepository repository,
|
||||||
|
DfsReaderOptions options) {
|
||||||
|
this.repository = repository;
|
||||||
this.packList = new AtomicReference<PackList>(NO_PACKS);
|
this.packList = new AtomicReference<PackList>(NO_PACKS);
|
||||||
this.readerOptions = options;
|
this.readerOptions = options;
|
||||||
}
|
}
|
||||||
|
@ -151,6 +158,11 @@ public DfsPackFile[] getPacks() throws IOException {
|
||||||
return scanPacks(NO_PACKS).packs;
|
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.
|
* Generate a new unique name for a pack file.
|
||||||
*
|
*
|
||||||
|
|
|
@ -57,6 +57,8 @@
|
||||||
* modified once initialized and presented to the JGit DFS library.
|
* modified once initialized and presented to the JGit DFS library.
|
||||||
*/
|
*/
|
||||||
public class DfsPackDescription implements Comparable<DfsPackDescription> {
|
public class DfsPackDescription implements Comparable<DfsPackDescription> {
|
||||||
|
private final DfsRepositoryDescription repoDesc;
|
||||||
|
|
||||||
private final String packName;
|
private final String packName;
|
||||||
|
|
||||||
private long lastModified;
|
private long lastModified;
|
||||||
|
@ -74,7 +76,7 @@ public class DfsPackDescription implements Comparable<DfsPackDescription> {
|
||||||
private PackWriter.Statistics stats;
|
private PackWriter.Statistics stats;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize a description by pack name.
|
* Initialize a description by pack name and repository.
|
||||||
* <p>
|
* <p>
|
||||||
* The corresponding index file is assumed to exist and end with ".idx"
|
* The corresponding index file is assumed to exist and end with ".idx"
|
||||||
* instead of ".pack". If this is not true implementors must extend the
|
* instead of ".pack". If this is not true implementors must extend the
|
||||||
|
@ -85,11 +87,19 @@ public class DfsPackDescription implements Comparable<DfsPackDescription> {
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* name of the pack file. Must end with ".pack".
|
* 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;
|
this.packName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return description of the repository. */
|
||||||
|
public DfsRepositoryDescription getRepositoryDescription() {
|
||||||
|
return repoDesc;
|
||||||
|
}
|
||||||
|
|
||||||
/** @return name of the pack file. */
|
/** @return name of the pack file. */
|
||||||
public String getPackName() {
|
public String getPackName() {
|
||||||
return packName;
|
return packName;
|
||||||
|
@ -231,8 +241,11 @@ public int hashCode() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object b) {
|
public boolean equals(Object b) {
|
||||||
if (b instanceof DfsPackDescription)
|
if (b instanceof DfsPackDescription) {
|
||||||
return getPackName().equals(((DfsPackDescription) b).getPackName());
|
DfsPackDescription desc = (DfsPackDescription) b;
|
||||||
|
return getPackName().equals(desc.getPackName()) &&
|
||||||
|
getRepositoryDescription().equals(desc.getRepositoryDescription());
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,8 @@
|
||||||
public abstract class DfsRepository extends Repository {
|
public abstract class DfsRepository extends Repository {
|
||||||
private final DfsConfig config;
|
private final DfsConfig config;
|
||||||
|
|
||||||
|
private final DfsRepositoryDescription description;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize a DFS repository.
|
* Initialize a DFS repository.
|
||||||
*
|
*
|
||||||
|
@ -66,6 +68,7 @@ public abstract class DfsRepository extends Repository {
|
||||||
protected DfsRepository(DfsRepositoryBuilder builder) {
|
protected DfsRepository(DfsRepositoryBuilder builder) {
|
||||||
super(builder);
|
super(builder);
|
||||||
this.config = new DfsConfig();
|
this.config = new DfsConfig();
|
||||||
|
this.description = builder.getRepositoryDescription();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -74,6 +77,11 @@ protected DfsRepository(DfsRepositoryBuilder builder) {
|
||||||
@Override
|
@Override
|
||||||
public abstract DfsRefDatabase getRefDatabase();
|
public abstract DfsRefDatabase getRefDatabase();
|
||||||
|
|
||||||
|
/** @return a description of this repository. */
|
||||||
|
public DfsRepositoryDescription getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the repository already exists.
|
* Check if the repository already exists.
|
||||||
*
|
*
|
||||||
|
|
|
@ -60,6 +60,8 @@ public abstract class DfsRepositoryBuilder<B extends DfsRepositoryBuilder, R ext
|
||||||
extends BaseRepositoryBuilder<B, R> {
|
extends BaseRepositoryBuilder<B, R> {
|
||||||
private DfsReaderOptions readerOptions;
|
private DfsReaderOptions readerOptions;
|
||||||
|
|
||||||
|
private DfsRepositoryDescription repoDesc;
|
||||||
|
|
||||||
/** @return options used by readers accessing the repository. */
|
/** @return options used by readers accessing the repository. */
|
||||||
public DfsReaderOptions getReaderOptions() {
|
public DfsReaderOptions getReaderOptions() {
|
||||||
return readerOptions;
|
return readerOptions;
|
||||||
|
@ -77,11 +79,30 @@ public B setReaderOptions(DfsReaderOptions opt) {
|
||||||
return self();
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return a description of the repository. */
|
||||||
|
public DfsRepositoryDescription getRepositoryDescription() {
|
||||||
|
return repoDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the repository description.
|
||||||
|
*
|
||||||
|
* @param desc
|
||||||
|
* new repository description object.
|
||||||
|
* @return {@code this}
|
||||||
|
*/
|
||||||
|
public B setRepositoryDescription(DfsRepositoryDescription desc) {
|
||||||
|
repoDesc = desc;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public B setup() throws IllegalArgumentException, IOException {
|
public B setup() throws IllegalArgumentException, IOException {
|
||||||
super.setup();
|
super.setup();
|
||||||
if (getReaderOptions() == null)
|
if (getReaderOptions() == null)
|
||||||
setReaderOptions(new DfsReaderOptions());
|
setReaderOptions(new DfsReaderOptions());
|
||||||
|
if (getRepositoryDescription() == null)
|
||||||
|
setRepositoryDescription(new DfsRepositoryDescription());
|
||||||
return self();
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,91 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2011, Google Inc.
|
||||||
|
* and other copyright owners as documented in the project's IP log.
|
||||||
|
*
|
||||||
|
* This program and the accompanying materials are made available
|
||||||
|
* under the terms of the Eclipse Distribution License v1.0 which
|
||||||
|
* accompanies this distribution, is reproduced below, and is
|
||||||
|
* available at http://www.eclipse.org/org/documents/edl-v10.php
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or
|
||||||
|
* without modification, are permitted provided that the following
|
||||||
|
* conditions are met:
|
||||||
|
*
|
||||||
|
* - Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* - Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following
|
||||||
|
* disclaimer in the documentation and/or other materials provided
|
||||||
|
* with the distribution.
|
||||||
|
*
|
||||||
|
* - Neither the name of the Eclipse Foundation, Inc. nor the
|
||||||
|
* names of its contributors may be used to endorse or promote
|
||||||
|
* products derived from this software without specific prior
|
||||||
|
* written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.eclipse.jgit.storage.dfs;
|
||||||
|
|
||||||
|
/** A description of a Git repository on a DFS. */
|
||||||
|
public class DfsRepositoryDescription {
|
||||||
|
private final String repositoryName;
|
||||||
|
|
||||||
|
/** Initialize a new, empty repository description. */
|
||||||
|
public DfsRepositoryDescription() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize a new repository description.
|
||||||
|
*
|
||||||
|
* @param repositoryName
|
||||||
|
* the name of the repository.
|
||||||
|
*/
|
||||||
|
public DfsRepositoryDescription(String repositoryName) {
|
||||||
|
this.repositoryName = repositoryName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return the name of the repository. */
|
||||||
|
public String getRepositoryName() {
|
||||||
|
return repositoryName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
if (getRepositoryName() != null)
|
||||||
|
return getRepositoryName().hashCode();
|
||||||
|
return System.identityHashCode(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object b) {
|
||||||
|
if (b instanceof DfsRepositoryDescription){
|
||||||
|
String name = getRepositoryName();
|
||||||
|
String otherName = ((DfsRepositoryDescription) b).getRepositoryName();
|
||||||
|
return name != null ? name.equals(otherName) : this == b;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "DfsRepositoryDescription[" + getRepositoryName() + "]";
|
||||||
|
}
|
||||||
|
}
|
|
@ -30,8 +30,13 @@ public class InMemoryRepository extends DfsRepository {
|
||||||
|
|
||||||
private final DfsRefDatabase refdb;
|
private final DfsRefDatabase refdb;
|
||||||
|
|
||||||
/** Initialize a new in-memory repository. */
|
/**
|
||||||
public InMemoryRepository() {
|
* Initialize a new in-memory repository.
|
||||||
|
*
|
||||||
|
* @param repoDesc
|
||||||
|
* description of the repository.
|
||||||
|
*/
|
||||||
|
public InMemoryRepository(DfsRepository repoDesc) {
|
||||||
super(new DfsRepositoryBuilder<DfsRepositoryBuilder, InMemoryRepository>() {
|
super(new DfsRepositoryBuilder<DfsRepositoryBuilder, InMemoryRepository>() {
|
||||||
@Override
|
@Override
|
||||||
public InMemoryRepository build() throws IOException {
|
public InMemoryRepository build() throws IOException {
|
||||||
|
@ -39,7 +44,7 @@ public InMemoryRepository build() throws IOException {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
objdb = new MemObjDatabase();
|
objdb = new MemObjDatabase(this);
|
||||||
refdb = new MemRefDatabase();
|
refdb = new MemRefDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,8 +62,8 @@ private class MemObjDatabase extends DfsObjDatabase {
|
||||||
private final AtomicInteger packId = new AtomicInteger();
|
private final AtomicInteger packId = new AtomicInteger();
|
||||||
private List<DfsPackDescription> packs = new ArrayList<DfsPackDescription>();
|
private List<DfsPackDescription> packs = new ArrayList<DfsPackDescription>();
|
||||||
|
|
||||||
MemObjDatabase() {
|
MemObjDatabase(DfsRepository repo) {
|
||||||
super(new DfsReaderOptions());
|
super(repo, new DfsReaderOptions());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -69,7 +74,8 @@ protected synchronized List<DfsPackDescription> listPacks() {
|
||||||
@Override
|
@Override
|
||||||
protected DfsPackDescription newPack(PackSource source) {
|
protected DfsPackDescription newPack(PackSource source) {
|
||||||
int id = packId.incrementAndGet();
|
int id = packId.incrementAndGet();
|
||||||
return new MemPack("pack-" + id + "-" + source.name());
|
return new MemPack("pack-" + id + "-" + source.name(),
|
||||||
|
getRepository().getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -136,8 +142,8 @@ private static class MemPack extends DfsPackDescription {
|
||||||
|
|
||||||
private byte[] packIndex;
|
private byte[] packIndex;
|
||||||
|
|
||||||
MemPack(String name) {
|
MemPack(String name, DfsRepositoryDescription repoDesc) {
|
||||||
super(name);
|
super(repoDesc, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue