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 { try {
final Repository repo = git.getRepository(); final Repository repo = git.getRepository();
final ObjectId headId = repo.resolve(Constants.HEAD + "^{commit}"); final ObjectId headId = repo.resolve(Constants.HEAD + "^{commit}");
final TreeWalk tw = TreeWalk.forPath(repo, path, try (RevWalk rw = new RevWalk(repo)) {
new RevWalk(repo).parseTree(headId)); final TreeWalk tw = TreeWalk.forPath(repo, path,
return new String(tw.getObjectReader().open(tw.getObjectId(0)) rw.parseTree(headId));
.getBytes()); return new String(tw.getObjectReader().open(tw.getObjectId(0))
.getBytes());
}
} catch (Exception e) { } catch (Exception e) {
return ""; return "";
} }

View File

@ -81,15 +81,14 @@ public class ConcurrentRepackTest extends RepositoryTestCase {
public void setUp() throws Exception { public void setUp() throws Exception {
WindowCacheConfig windowCacheConfig = new WindowCacheConfig(); WindowCacheConfig windowCacheConfig = new WindowCacheConfig();
windowCacheConfig.setPackedGitOpenFiles(1); windowCacheConfig.setPackedGitOpenFiles(1);
WindowCache.reconfigure(windowCacheConfig); windowCacheConfig.install();
super.setUp(); super.setUp();
} }
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
super.tearDown(); super.tearDown();
WindowCacheConfig windowCacheConfig = new WindowCacheConfig(); new WindowCacheConfig().install();
WindowCache.reconfigure(windowCacheConfig);
} }
@Test @Test
@ -206,12 +205,14 @@ public void testObjectMovedToNewPack2()
private static void whackCache() { private static void whackCache() {
final WindowCacheConfig config = new WindowCacheConfig(); final WindowCacheConfig config = new WindowCacheConfig();
config.setPackedGitOpenFiles(1); config.setPackedGitOpenFiles(1);
WindowCache.reconfigure(config); config.install();
} }
private RevObject parse(final AnyObjectId id) private RevObject parse(final AnyObjectId id)
throws MissingObjectException, IOException { 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) 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) private RevObject writeBlob(final Repository repo, final String data)
throws IOException { throws IOException {
final RevWalk revWalk = new RevWalk(repo);
final byte[] bytes = Constants.encode(data); final byte[] bytes = Constants.encode(data);
final ObjectId id; final ObjectId id;
try (ObjectInserter inserter = repo.newObjectInserter()) { try (ObjectInserter inserter = repo.newObjectInserter()) {
@ -293,6 +293,8 @@ private RevObject writeBlob(final Repository repo, final String data)
} catch (MissingObjectException e) { } catch (MissingObjectException e) {
// Ok // 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()); .findGitDir(d).getGitDir());
} }
@SuppressWarnings("unused")
@Test @Test
public void emptyRepositoryFormatVersion() throws Exception { public void emptyRepositoryFormatVersion() throws Exception {
Repository r = createWorkRepository(); Repository r = createWorkRepository();
@ -81,10 +80,11 @@ public void emptyRepositoryFormatVersion() throws Exception {
ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, ""); ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, "");
config.save(); config.save();
new FileRepository(r.getDirectory()); try (FileRepository repo = new FileRepository(r.getDirectory())) {
// Unused
}
} }
@SuppressWarnings("unused")
@Test @Test
public void invalidRepositoryFormatVersion() throws Exception { public void invalidRepositoryFormatVersion() throws Exception {
Repository r = createWorkRepository(); Repository r = createWorkRepository();
@ -93,15 +93,13 @@ public void invalidRepositoryFormatVersion() throws Exception {
ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, "notanumber"); ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, "notanumber");
config.save(); config.save();
try { try (FileRepository repo = new FileRepository(r.getDirectory())) {
new FileRepository(r.getDirectory());
fail("IllegalArgumentException not thrown"); fail("IllegalArgumentException not thrown");
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
assertNotNull(e.getMessage()); assertNotNull(e.getMessage());
} }
} }
@SuppressWarnings("unused")
@Test @Test
public void unknownRepositoryFormatVersion() throws Exception { public void unknownRepositoryFormatVersion() throws Exception {
Repository r = createWorkRepository(); Repository r = createWorkRepository();
@ -110,75 +108,75 @@ public void unknownRepositoryFormatVersion() throws Exception {
ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, 999999); ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, 999999);
config.save(); config.save();
try { try (FileRepository repo = new FileRepository(r.getDirectory())) {
new FileRepository(r.getDirectory());
fail("IOException not thrown"); fail("IOException not thrown");
} catch (IOException e) { } catch (IOException e) {
assertNotNull(e.getMessage()); assertNotNull(e.getMessage());
} }
} }
@SuppressWarnings("resource" /* java 7 */)
@Test @Test
public void absoluteGitDirRef() throws Exception { public void absoluteGitDirRef() throws Exception {
Repository repo1 = createWorkRepository(); Repository repo1 = createWorkRepository();
File dir = createTempDirectory("dir"); File dir = createTempDirectory("dir");
File dotGit = new File(dir, Constants.DOT_GIT); File dotGit = new File(dir, Constants.DOT_GIT);
new FileWriter(dotGit).append( try (FileWriter writer = new FileWriter(dotGit)) {
"gitdir: " + repo1.getDirectory().getAbsolutePath()).close(); writer.append("gitdir: " + repo1.getDirectory().getAbsolutePath()).close();
FileRepositoryBuilder builder = new FileRepositoryBuilder(); FileRepositoryBuilder builder = new FileRepositoryBuilder();
builder.setWorkTree(dir); builder.setWorkTree(dir);
builder.setMustExist(true); builder.setMustExist(true);
Repository repo2 = builder.build(); Repository repo2 = builder.build();
assertEquals(repo1.getDirectory().getAbsolutePath(), repo2 assertEquals(repo1.getDirectory().getAbsolutePath(), repo2
.getDirectory().getAbsolutePath()); .getDirectory().getAbsolutePath());
assertEquals(dir, repo2.getWorkTree()); assertEquals(dir, repo2.getWorkTree());
}
} }
@SuppressWarnings("resource" /* java 7 */)
@Test @Test
public void relativeGitDirRef() throws Exception { public void relativeGitDirRef() throws Exception {
Repository repo1 = createWorkRepository(); Repository repo1 = createWorkRepository();
File dir = new File(repo1.getWorkTree(), "dir"); File dir = new File(repo1.getWorkTree(), "dir");
assertTrue(dir.mkdir()); assertTrue(dir.mkdir());
File dotGit = new File(dir, Constants.DOT_GIT); File dotGit = new File(dir, Constants.DOT_GIT);
new FileWriter(dotGit).append("gitdir: ../" + Constants.DOT_GIT) try (FileWriter writer = new FileWriter(dotGit)) {
.close(); writer.append("gitdir: ../" + Constants.DOT_GIT).close();
FileRepositoryBuilder builder = new FileRepositoryBuilder(); FileRepositoryBuilder builder = new FileRepositoryBuilder();
builder.setWorkTree(dir); builder.setWorkTree(dir);
builder.setMustExist(true); builder.setMustExist(true);
Repository repo2 = builder.build(); Repository repo2 = builder.build();
// The tmp directory may be a symlink so the actual path // The tmp directory may be a symlink so the actual path
// may not // may not
assertEquals(repo1.getDirectory().getCanonicalPath(), repo2 assertEquals(repo1.getDirectory().getCanonicalPath(), repo2
.getDirectory().getCanonicalPath()); .getDirectory().getCanonicalPath());
assertEquals(dir, repo2.getWorkTree()); assertEquals(dir, repo2.getWorkTree());
}
} }
@SuppressWarnings("resource" /* java 7 */)
@Test @Test
public void scanWithGitDirRef() throws Exception { public void scanWithGitDirRef() throws Exception {
Repository repo1 = createWorkRepository(); Repository repo1 = createWorkRepository();
File dir = createTempDirectory("dir"); File dir = createTempDirectory("dir");
File dotGit = new File(dir, Constants.DOT_GIT); File dotGit = new File(dir, Constants.DOT_GIT);
new FileWriter(dotGit).append( try (FileWriter writer = new FileWriter(dotGit)) {
"gitdir: " + repo1.getDirectory().getAbsolutePath()).close(); writer.append(
FileRepositoryBuilder builder = new FileRepositoryBuilder(); "gitdir: " + repo1.getDirectory().getAbsolutePath()).close();
FileRepositoryBuilder builder = new FileRepositoryBuilder();
builder.setWorkTree(dir); builder.setWorkTree(dir);
builder.findGitDir(dir); builder.findGitDir(dir);
assertEquals(repo1.getDirectory().getAbsolutePath(), builder assertEquals(repo1.getDirectory().getAbsolutePath(), builder
.getGitDir().getAbsolutePath()); .getGitDir().getAbsolutePath());
builder.setMustExist(true); builder.setMustExist(true);
Repository repo2 = builder.build(); Repository repo2 = builder.build();
// The tmp directory may be a symlink // The tmp directory may be a symlink
assertEquals(repo1.getDirectory().getCanonicalPath(), repo2 assertEquals(repo1.getDirectory().getCanonicalPath(), repo2
.getDirectory().getCanonicalPath()); .getDirectory().getCanonicalPath());
assertEquals(dir, repo2.getWorkTree()); assertEquals(dir, repo2.getWorkTree());
}
} }
} }

View File

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

View File

@ -143,7 +143,7 @@ public void testStandardFormat_SmallObject() throws Exception {
public void testStandardFormat_LargeObject() throws Exception { public void testStandardFormat_LargeObject() throws Exception {
final int type = Constants.OBJ_BLOB; final int type = Constants.OBJ_BLOB;
byte[] data = getRng().nextBytes(streamThreshold + 5); byte[] data = getRng().nextBytes(streamThreshold + 5);
ObjectId id = new ObjectInserter.Formatter().idFor(type, data); ObjectId id = getId(type, data);
write(id, compressStandardFormat(type, data)); write(id, compressStandardFormat(type, data));
ObjectLoader ol; ObjectLoader ol;
@ -306,7 +306,7 @@ public void testStandardFormat_LargeObject_CorruptZLibStream()
throws Exception { throws Exception {
final int type = Constants.OBJ_BLOB; final int type = Constants.OBJ_BLOB;
byte[] data = getRng().nextBytes(streamThreshold + 5); 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[] gz = compressStandardFormat(type, data);
gz[gz.length - 1] = 0; gz[gz.length - 1] = 0;
gz[gz.length - 2] = 0; gz[gz.length - 2] = 0;
@ -344,7 +344,7 @@ public void testStandardFormat_LargeObject_TruncatedZLibStream()
throws Exception { throws Exception {
final int type = Constants.OBJ_BLOB; final int type = Constants.OBJ_BLOB;
byte[] data = getRng().nextBytes(streamThreshold + 5); 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[] gz = compressStandardFormat(type, data);
byte[] tr = new byte[gz.length - 1]; byte[] tr = new byte[gz.length - 1];
System.arraycopy(gz, 0, tr, 0, tr.length); System.arraycopy(gz, 0, tr, 0, tr.length);
@ -379,7 +379,7 @@ public void testStandardFormat_LargeObject_TrailingGarbage()
throws Exception { throws Exception {
final int type = Constants.OBJ_BLOB; final int type = Constants.OBJ_BLOB;
byte[] data = getRng().nextBytes(streamThreshold + 5); 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[] gz = compressStandardFormat(type, data);
byte[] tr = new byte[gz.length + 1]; byte[] tr = new byte[gz.length + 1];
System.arraycopy(gz, 0, tr, 0, gz.length); System.arraycopy(gz, 0, tr, 0, gz.length);
@ -438,7 +438,7 @@ public void testPackFormat_SmallObject() throws Exception {
public void testPackFormat_LargeObject() throws Exception { public void testPackFormat_LargeObject() throws Exception {
final int type = Constants.OBJ_BLOB; final int type = Constants.OBJ_BLOB;
byte[] data = getRng().nextBytes(streamThreshold + 5); byte[] data = getRng().nextBytes(streamThreshold + 5);
ObjectId id = new ObjectInserter.Formatter().idFor(type, data); ObjectId id = getId(type, data);
write(id, compressPackFormat(type, data)); write(id, compressPackFormat(type, data));
ObjectLoader ol; ObjectLoader ol;
@ -578,4 +578,10 @@ private void write(ObjectId id, byte[] data) throws IOException {
out.close(); 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 + '.archive',
group + '.http.apache', group + '.http.apache',
group + '.http.server', group + '.http.server',
group + '.java7',
group + '.junit', group + '.junit',
group + '.junit.http', group + '.junit.http',
group + '.pgm', group + '.pgm',

View File

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