Merge branch 'stable-4.2'

* stable-4.2:
  ConcurrentRepackTest: Don't use deprecated WindowCache.reconfigure
  ConcurrentRepackTest: Open RevWalk in try-with-resource
  CommitOnlyTest: Open RevWalk in try-with-resource
  UnpackedObjectTest: Create ObjectInserter.Formatter in try-with-resource
  FileRepositoryBuilderTest: Use try-with-resource for auto-closeables
  RepositorySetupWorkDirTest: Fix "resource leak" warnings
  Remove java7 bundle from Maven central scripts
  Prepare 4.2.1-SNAPSHOT builds
  JGit v4.2.0.201601211800-r
  Add progress monitor to Merger
  Fix TransportException when reading bundle
  Fix unused throws CorruptObjectException from addTree

Change-Id: I2325fb995561a6249b7b5e82fa413dfd34ef6007
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
Matthias Sohn 2016-01-24 10:59:14 +01:00
commit 114ee5a613
7 changed files with 78 additions and 71 deletions

View File

@ -1294,10 +1294,12 @@ static private String getHead(final Git git, final String path)
try {
final Repository repo = git.getRepository();
final ObjectId headId = repo.resolve(Constants.HEAD + "^{commit}");
final TreeWalk tw = TreeWalk.forPath(repo, path,
new RevWalk(repo).parseTree(headId));
return new String(tw.getObjectReader().open(tw.getObjectId(0))
.getBytes());
try (RevWalk rw = new RevWalk(repo)) {
final TreeWalk tw = TreeWalk.forPath(repo, path,
rw.parseTree(headId));
return new String(tw.getObjectReader().open(tw.getObjectId(0))
.getBytes());
}
} catch (Exception e) {
return "";
}

View File

@ -81,15 +81,14 @@ public class ConcurrentRepackTest extends RepositoryTestCase {
public void setUp() throws Exception {
WindowCacheConfig windowCacheConfig = new WindowCacheConfig();
windowCacheConfig.setPackedGitOpenFiles(1);
WindowCache.reconfigure(windowCacheConfig);
windowCacheConfig.install();
super.setUp();
}
@After
public void tearDown() throws Exception {
super.tearDown();
WindowCacheConfig windowCacheConfig = new WindowCacheConfig();
WindowCache.reconfigure(windowCacheConfig);
new WindowCacheConfig().install();
}
@Test
@ -206,12 +205,14 @@ public void testObjectMovedToNewPack2()
private static void whackCache() {
final WindowCacheConfig config = new WindowCacheConfig();
config.setPackedGitOpenFiles(1);
WindowCache.reconfigure(config);
config.install();
}
private RevObject parse(final AnyObjectId id)
throws MissingObjectException, IOException {
return new RevWalk(db).parseAny(id);
try (RevWalk rw = new RevWalk(db)) {
return rw.parseAny(id);
}
}
private File[] pack(final Repository src, final RevObject... list)
@ -280,7 +281,6 @@ private File fullPackFileName(final ObjectId name, final String suffix) {
private RevObject writeBlob(final Repository repo, final String data)
throws IOException {
final RevWalk revWalk = new RevWalk(repo);
final byte[] bytes = Constants.encode(data);
final ObjectId id;
try (ObjectInserter inserter = repo.newObjectInserter()) {
@ -293,6 +293,8 @@ private RevObject writeBlob(final Repository repo, final String data)
} catch (MissingObjectException e) {
// Ok
}
return revWalk.lookupBlob(id);
try (RevWalk revWalk = new RevWalk(repo)) {
return revWalk.lookupBlob(id);
}
}
}

View File

@ -72,7 +72,6 @@ public void testShouldAutomagicallyDetectGitDirectory() throws Exception {
.findGitDir(d).getGitDir());
}
@SuppressWarnings("unused")
@Test
public void emptyRepositoryFormatVersion() throws Exception {
Repository r = createWorkRepository();
@ -81,10 +80,11 @@ public void emptyRepositoryFormatVersion() throws Exception {
ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, "");
config.save();
new FileRepository(r.getDirectory());
try (FileRepository repo = new FileRepository(r.getDirectory())) {
// Unused
}
}
@SuppressWarnings("unused")
@Test
public void invalidRepositoryFormatVersion() throws Exception {
Repository r = createWorkRepository();
@ -93,15 +93,13 @@ public void invalidRepositoryFormatVersion() throws Exception {
ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, "notanumber");
config.save();
try {
new FileRepository(r.getDirectory());
try (FileRepository repo = new FileRepository(r.getDirectory())) {
fail("IllegalArgumentException not thrown");
} catch (IllegalArgumentException e) {
assertNotNull(e.getMessage());
}
}
@SuppressWarnings("unused")
@Test
public void unknownRepositoryFormatVersion() throws Exception {
Repository r = createWorkRepository();
@ -110,75 +108,75 @@ public void unknownRepositoryFormatVersion() throws Exception {
ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, 999999);
config.save();
try {
new FileRepository(r.getDirectory());
try (FileRepository repo = new FileRepository(r.getDirectory())) {
fail("IOException not thrown");
} catch (IOException e) {
assertNotNull(e.getMessage());
}
}
@SuppressWarnings("resource" /* java 7 */)
@Test
public void absoluteGitDirRef() throws Exception {
Repository repo1 = createWorkRepository();
File dir = createTempDirectory("dir");
File dotGit = new File(dir, Constants.DOT_GIT);
new FileWriter(dotGit).append(
"gitdir: " + repo1.getDirectory().getAbsolutePath()).close();
FileRepositoryBuilder builder = new FileRepositoryBuilder();
try (FileWriter writer = new FileWriter(dotGit)) {
writer.append("gitdir: " + repo1.getDirectory().getAbsolutePath()).close();
FileRepositoryBuilder builder = new FileRepositoryBuilder();
builder.setWorkTree(dir);
builder.setMustExist(true);
Repository repo2 = builder.build();
builder.setWorkTree(dir);
builder.setMustExist(true);
Repository repo2 = builder.build();
assertEquals(repo1.getDirectory().getAbsolutePath(), repo2
.getDirectory().getAbsolutePath());
assertEquals(dir, repo2.getWorkTree());
assertEquals(repo1.getDirectory().getAbsolutePath(), repo2
.getDirectory().getAbsolutePath());
assertEquals(dir, repo2.getWorkTree());
}
}
@SuppressWarnings("resource" /* java 7 */)
@Test
public void relativeGitDirRef() throws Exception {
Repository repo1 = createWorkRepository();
File dir = new File(repo1.getWorkTree(), "dir");
assertTrue(dir.mkdir());
File dotGit = new File(dir, Constants.DOT_GIT);
new FileWriter(dotGit).append("gitdir: ../" + Constants.DOT_GIT)
.close();
try (FileWriter writer = new FileWriter(dotGit)) {
writer.append("gitdir: ../" + Constants.DOT_GIT).close();
FileRepositoryBuilder builder = new FileRepositoryBuilder();
builder.setWorkTree(dir);
builder.setMustExist(true);
Repository repo2 = builder.build();
FileRepositoryBuilder builder = new FileRepositoryBuilder();
builder.setWorkTree(dir);
builder.setMustExist(true);
Repository repo2 = builder.build();
// The tmp directory may be a symlink so the actual path
// may not
assertEquals(repo1.getDirectory().getCanonicalPath(), repo2
.getDirectory().getCanonicalPath());
assertEquals(dir, repo2.getWorkTree());
// The tmp directory may be a symlink so the actual path
// may not
assertEquals(repo1.getDirectory().getCanonicalPath(), repo2
.getDirectory().getCanonicalPath());
assertEquals(dir, repo2.getWorkTree());
}
}
@SuppressWarnings("resource" /* java 7 */)
@Test
public void scanWithGitDirRef() throws Exception {
Repository repo1 = createWorkRepository();
File dir = createTempDirectory("dir");
File dotGit = new File(dir, Constants.DOT_GIT);
new FileWriter(dotGit).append(
"gitdir: " + repo1.getDirectory().getAbsolutePath()).close();
FileRepositoryBuilder builder = new FileRepositoryBuilder();
try (FileWriter writer = new FileWriter(dotGit)) {
writer.append(
"gitdir: " + repo1.getDirectory().getAbsolutePath()).close();
FileRepositoryBuilder builder = new FileRepositoryBuilder();
builder.setWorkTree(dir);
builder.findGitDir(dir);
assertEquals(repo1.getDirectory().getAbsolutePath(), builder
.getGitDir().getAbsolutePath());
builder.setMustExist(true);
Repository repo2 = builder.build();
builder.setWorkTree(dir);
builder.findGitDir(dir);
assertEquals(repo1.getDirectory().getAbsolutePath(), builder
.getGitDir().getAbsolutePath());
builder.setMustExist(true);
Repository repo2 = builder.build();
// The tmp directory may be a symlink
assertEquals(repo1.getDirectory().getCanonicalPath(), repo2
.getDirectory().getCanonicalPath());
assertEquals(dir, repo2.getWorkTree());
// The tmp directory may be a symlink
assertEquals(repo1.getDirectory().getCanonicalPath(), repo2
.getDirectory().getCanonicalPath());
assertEquals(dir, repo2.getWorkTree());
}
}
}

View File

@ -73,13 +73,14 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase {
public void testIsBare_CreateRepositoryFromArbitraryGitDir()
throws Exception {
File gitDir = getFile("workdir");
assertTrue(new FileRepository(gitDir).isBare());
Repository repo = new FileRepositoryBuilder().setGitDir(gitDir).build();
assertTrue(repo.isBare());
}
@Test
public void testNotBare_CreateRepositoryFromDotGitGitDir() throws Exception {
File gitDir = getFile("workdir", Constants.DOT_GIT);
Repository repo = new FileRepository(gitDir);
Repository repo = new FileRepositoryBuilder().setGitDir(gitDir).build();
assertFalse(repo.isBare());
assertWorkdirPath(repo, "workdir");
assertGitdirPath(repo, "workdir", Constants.DOT_GIT);
@ -89,7 +90,7 @@ public void testNotBare_CreateRepositoryFromDotGitGitDir() throws Exception {
public void testWorkdirIsParentDir_CreateRepositoryFromDotGitGitDir()
throws Exception {
File gitDir = getFile("workdir", Constants.DOT_GIT);
Repository repo = new FileRepository(gitDir);
Repository repo = new FileRepositoryBuilder().setGitDir(gitDir).build();
String workdir = repo.getWorkTree().getName();
assertEquals(workdir, "workdir");
}
@ -157,8 +158,8 @@ public void testNotBare_CreateRepositoryFromGitDirOnlyWithBareConfigFalse()
@Test
public void testExceptionThrown_BareRepoGetWorkDir() throws Exception {
File gitDir = getFile("workdir");
try {
new FileRepository(gitDir).getWorkTree();
try (Repository repo = new FileRepository(gitDir)) {
repo.getWorkTree();
fail("Expected NoWorkTreeException missing");
} catch (NoWorkTreeException e) {
// expected
@ -168,8 +169,8 @@ public void testExceptionThrown_BareRepoGetWorkDir() throws Exception {
@Test
public void testExceptionThrown_BareRepoGetIndex() throws Exception {
File gitDir = getFile("workdir");
try {
new FileRepository(gitDir).readDirCache();
try (Repository repo = new FileRepository(gitDir)) {
repo.readDirCache();
fail("Expected NoWorkTreeException missing");
} catch (NoWorkTreeException e) {
// expected
@ -179,8 +180,8 @@ public void testExceptionThrown_BareRepoGetIndex() throws Exception {
@Test
public void testExceptionThrown_BareRepoGetIndexFile() throws Exception {
File gitDir = getFile("workdir");
try {
new FileRepository(gitDir).getIndexFile();
try (Repository repo = new FileRepository(gitDir)) {
repo.getIndexFile();
fail("Expected NoWorkTreeException missing");
} catch (NoWorkTreeException e) {
// expected

View File

@ -143,7 +143,7 @@ public void testStandardFormat_SmallObject() throws Exception {
public void testStandardFormat_LargeObject() throws Exception {
final int type = Constants.OBJ_BLOB;
byte[] data = getRng().nextBytes(streamThreshold + 5);
ObjectId id = new ObjectInserter.Formatter().idFor(type, data);
ObjectId id = getId(type, data);
write(id, compressStandardFormat(type, data));
ObjectLoader ol;
@ -306,7 +306,7 @@ public void testStandardFormat_LargeObject_CorruptZLibStream()
throws Exception {
final int type = Constants.OBJ_BLOB;
byte[] data = getRng().nextBytes(streamThreshold + 5);
ObjectId id = new ObjectInserter.Formatter().idFor(type, data);
ObjectId id = getId(type, data);
byte[] gz = compressStandardFormat(type, data);
gz[gz.length - 1] = 0;
gz[gz.length - 2] = 0;
@ -344,7 +344,7 @@ public void testStandardFormat_LargeObject_TruncatedZLibStream()
throws Exception {
final int type = Constants.OBJ_BLOB;
byte[] data = getRng().nextBytes(streamThreshold + 5);
ObjectId id = new ObjectInserter.Formatter().idFor(type, data);
ObjectId id = getId(type, data);
byte[] gz = compressStandardFormat(type, data);
byte[] tr = new byte[gz.length - 1];
System.arraycopy(gz, 0, tr, 0, tr.length);
@ -379,7 +379,7 @@ public void testStandardFormat_LargeObject_TrailingGarbage()
throws Exception {
final int type = Constants.OBJ_BLOB;
byte[] data = getRng().nextBytes(streamThreshold + 5);
ObjectId id = new ObjectInserter.Formatter().idFor(type, data);
ObjectId id = getId(type, data);
byte[] gz = compressStandardFormat(type, data);
byte[] tr = new byte[gz.length + 1];
System.arraycopy(gz, 0, tr, 0, gz.length);
@ -438,7 +438,7 @@ public void testPackFormat_SmallObject() throws Exception {
public void testPackFormat_LargeObject() throws Exception {
final int type = Constants.OBJ_BLOB;
byte[] data = getRng().nextBytes(streamThreshold + 5);
ObjectId id = new ObjectInserter.Formatter().idFor(type, data);
ObjectId id = getId(type, data);
write(id, compressPackFormat(type, data));
ObjectLoader ol;
@ -578,4 +578,10 @@ private void write(ObjectId id, byte[] data) throws IOException {
out.close();
}
}
private ObjectId getId(int type, byte[] data) {
try (ObjectInserter.Formatter formatter = new ObjectInserter.Formatter()) {
return formatter.idFor(type, data);
}
}
}

View File

@ -53,7 +53,6 @@ artifacts = [group,
group + '.archive',
group + '.http.apache',
group + '.http.server',
group + '.java7',
group + '.junit',
group + '.junit.http',
group + '.pgm',

View File

@ -13,7 +13,6 @@ artifacts = [group,
group + '.archive',
group + '.http.apache',
group + '.http.server',
group + '.java7',
group + '.junit',
group + '.junit.http',
group + '.pgm',