Browse Source

Merge branch 'delta'

* delta: (103 commits)
  Discard the uncompressed delta as soon as its compressed
  Honor pack.windowlimit to cap memory usage during packing
  Honor pack.threads and perform delta search in parallel
  Cache small deltas during packing
  Implement delta generation during packing
  debug-show-packdelta:  Dump a pack delta to the console
  Initial pack format delta generator
  Add debugging toString() method to ObjectToPack
  Make ObjectToPack clearReuseAsIs signal available to subclasses
  Correctly classify the compressing objects phase
  Refactor ObjectToPack's delta depth setting
  Configure core.bigFileThreshold into PackWriter
  Add doNotDelta flag to ObjectToPack
  Add more configuration options to PackWriter
  Save object path hash codes during packing
  Add path hash code to ObjectWalk
  Add getObjectSize to ObjectReader
  Allow TemporaryBuffer.Heap to allocate smaller than 8 KiB
  Define a constant for 127 in DeltaEncoder
  Cap delta copy instructions at 64k
  ...

Conflicts:
	org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Diff.java
	org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties
	org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java
	org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteTreeFilter.java

Change-Id: I7c7a05e443a48d32c836173a409ee7d340c70796
stable-0.9
Shawn O. Pearce 15 years ago
parent
commit
fa9b225e06
  1. 1
      org.eclipse.jgit.http.server/META-INF/MANIFEST.MF
  2. 4
      org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/InfoPacksServlet.java
  3. 7
      org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/InfoRefsServlet.java
  4. 2
      org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/IsLocalFilter.java
  5. 2
      org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ObjectFileServlet.java
  6. 7
      org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java
  7. 2
      org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/TextFileServlet.java
  8. 14
      org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java
  9. 4
      org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/FileResolver.java
  10. 1
      org.eclipse.jgit.http.test/META-INF/MANIFEST.MF
  11. 9
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AdvertiseErrorTest.java
  12. 9
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HookMessageTest.java
  13. 17
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java
  14. 15
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java
  15. 6
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/util/HttpTestCase.java
  16. 1
      org.eclipse.jgit.iplog/META-INF/MANIFEST.MF
  17. 18
      org.eclipse.jgit.iplog/src/org/eclipse/jgit/iplog/IpLogGenerator.java
  18. 4
      org.eclipse.jgit.iplog/src/org/eclipse/jgit/iplog/IpLogMeta.java
  19. 2
      org.eclipse.jgit.junit/META-INF/MANIFEST.MF
  20. 17
      org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java
  21. 2
      org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java
  22. 135
      org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
  23. 2
      org.eclipse.jgit.pgm/META-INF/MANIFEST.MF
  24. 1
      org.eclipse.jgit.pgm/META-INF/services/org.eclipse.jgit.pgm.TextBuiltin
  25. 21
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java
  26. 8
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Glog.java
  27. 4
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/IndexPack.java
  28. 4
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java
  29. 76
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java
  30. 18
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ReceivePack.java
  31. 4
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Rm.java
  32. 9
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java
  33. 26
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/UploadPack.java
  34. 2
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/MakeCacheTree.java
  35. 3
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ReadDirCache.java
  36. 3
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java
  37. 2
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowCacheTree.java
  38. 2
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowDirCache.java
  39. 127
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java
  40. 2
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/WriteDirCache.java
  41. 2
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/eclipse/Iplog.java
  42. 2
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/eclipse/Ipzilla.java
  43. 6
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/AbstractTreeIteratorHandler.java
  44. 2
      org.eclipse.jgit.test/META-INF/MANIFEST.MF
  45. 2
      org.eclipse.jgit.test/exttst/org/eclipse/jgit/lib/T0007_GitIndexTest.java
  46. 44
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java
  47. 18
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
  48. 16
      org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java
  49. 20
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java
  50. 2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java
  51. 20
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderTest.java
  52. 2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheFindTest.java
  53. 16
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java
  54. 4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheLargePathTest.java
  55. 14
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheTreeTest.java
  56. 18
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReadTreeTest.java
  57. 4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java
  58. 7
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java
  59. 2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SampleDataRepositoryTestCase.java
  60. 4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/WorkDirCheckout_ReadTreeTest.java
  61. 28
      org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java
  62. 75
      org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java
  63. 5
      org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java
  64. 26
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ConcurrentRepackTest.java
  65. 387
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackFileTest.java
  66. 5
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackIndexTestCase.java
  67. 3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackIndexV1Test.java
  68. 3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackIndexV2Test.java
  69. 5
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackReverseIndexTest.java
  70. 23
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java
  71. 6
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefDirectoryTest.java
  72. 31
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefUpdateTest.java
  73. 7
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ReflogReaderTest.java
  74. 86
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RepositorySetupWorkDirTest.java
  75. 106
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_Basic.java
  76. 15
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0004_PackReader.java
  77. 534
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/UnpackedObjectTest.java
  78. 19
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/WindowCacheGetTest.java
  79. 4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/WindowCacheReconfigureTest.java
  80. 2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/XInputStream.java
  81. 228
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/pack/DeltaIndexTest.java
  82. 273
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/pack/DeltaStreamTest.java
  83. 4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java
  84. 2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/IndexPackTest.java
  85. 34
      org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackRefFilterTest.java
  86. 4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java
  87. 4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/AbstractTreeIteratorTest.java
  88. 7
      org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/EmptyTreeIteratorTest.java
  89. 4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
  90. 16
      org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/NameConflictTreeWalkTest.java
  91. 6
      org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/PostOrderTreeWalkTest.java
  92. 30
      org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTestCase.java
  93. 3
      org.eclipse.jgit/META-INF/MANIFEST.MF
  94. 4
      org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties
  95. 4
      org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java
  96. 4
      org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java
  97. 58
      org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java
  98. 6
      org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java
  99. 47
      org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
  100. 8
      org.eclipse.jgit/src/org/eclipse/jgit/diff/RenameDetector.java
  101. Some files were not shown because too many files have changed in this diff Show More

1
org.eclipse.jgit.http.server/META-INF/MANIFEST.MF

@ -17,6 +17,7 @@ Import-Package: javax.servlet;version="[2.5.0,3.0.0)",
org.eclipse.jgit.lib;version="[0.9.0,0.10.0)",
org.eclipse.jgit.nls;version="[0.9.0,0.10.0)",
org.eclipse.jgit.revwalk;version="[0.9.0,0.10.0)",
org.eclipse.jgit.storage.file;version="[0.9.0,0.10.0)",
org.eclipse.jgit.transport;version="[0.9.0,0.10.0)",
org.eclipse.jgit.util;version="[0.9.0,0.10.0)",
org.eclipse.jgit.util.io;version="[0.9.0,0.10.0)"

4
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/InfoPacksServlet.java

@ -53,8 +53,8 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jgit.lib.ObjectDatabase;
import org.eclipse.jgit.lib.ObjectDirectory;
import org.eclipse.jgit.lib.PackFile;
import org.eclipse.jgit.storage.file.ObjectDirectory;
import org.eclipse.jgit.storage.file.PackFile;
/** Sends the current list of pack files, sorted most recent first. */
class InfoPacksServlet extends HttpServlet {

7
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/InfoRefsServlet.java

@ -74,13 +74,15 @@ class InfoRefsServlet extends HttpServlet {
final Repository db = getRepository(req);
final RevWalk walk = new RevWalk(db);
try {
final RevFlag ADVERTISED = walk.newFlag("ADVERTISED");
final OutputStreamWriter out = new OutputStreamWriter(
new SmartOutputStream(req, rsp), Constants.CHARSET);
final RefAdvertiser adv = new RefAdvertiser() {
@Override
protected void writeOne(final CharSequence line) throws IOException {
protected void writeOne(final CharSequence line)
throws IOException {
// Whoever decided that info/refs should use a different
// delimiter than the native git:// protocol shouldn't
// be allowed to design this sort of stuff. :-(
@ -99,5 +101,8 @@ class InfoRefsServlet extends HttpServlet {
refs.remove(Constants.HEAD);
adv.send(refs);
out.close();
} finally {
walk.release();
}
}
}

2
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/IsLocalFilter.java

@ -56,8 +56,8 @@ import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jgit.lib.ObjectDirectory;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.storage.file.ObjectDirectory;
/**
* Requires the target {@link Repository} to be available via local filesystem.

2
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ObjectFileServlet.java

@ -60,8 +60,8 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jgit.lib.ObjectDirectory;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.storage.file.ObjectDirectory;
/** Sends any object from {@code GIT_DIR/objects/??/0 38}, or any pack file. */
abstract class ObjectFileServlet extends HttpServlet {

7
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java

@ -83,7 +83,12 @@ class ReceivePackServlet extends HttpServlet {
protected void advertise(HttpServletRequest req, Repository db,
PacketLineOutRefAdvertiser pck) throws IOException,
ServiceNotEnabledException, ServiceNotAuthorizedException {
receivePackFactory.create(req, db).sendAdvertisedRefs(pck);
ReceivePack rp = receivePackFactory.create(req, db);
try {
rp.sendAdvertisedRefs(pck);
} finally {
rp.getRevWalk().release();
}
}
}

2
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/TextFileServlet.java

@ -80,6 +80,8 @@ class TextFileServlet extends HttpServlet {
private byte[] read(final HttpServletRequest req) throws IOException {
final File gitdir = getRepository(req).getDirectory();
if (gitdir == null)
throw new FileNotFoundException(fileName);
return IO.readFully(new File(gitdir, fileName));
}
}

14
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java

@ -83,7 +83,12 @@ class UploadPackServlet extends HttpServlet {
protected void advertise(HttpServletRequest req, Repository db,
PacketLineOutRefAdvertiser pck) throws IOException,
ServiceNotEnabledException, ServiceNotAuthorizedException {
uploadPackFactory.create(req, db).sendAdvertisedRefs(pck);
UploadPack up = uploadPackFactory.create(req, db);
try {
up.sendAdvertisedRefs(pck);
} finally {
up.getRevWalk().release();
}
}
}
@ -107,7 +112,12 @@ class UploadPackServlet extends HttpServlet {
up.setBiDirectionalPipe(false);
rsp.setContentType(RSP_TYPE);
final SmartOutputStream out = new SmartOutputStream(req, rsp);
final SmartOutputStream out = new SmartOutputStream(req, rsp) {
@Override
public void flush() throws IOException {
doFlush();
}
};
up.upload(getInputStream(req), out, null);
out.close();

4
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/resolver/FileResolver.java

@ -138,8 +138,10 @@ public class FileResolver implements RepositoryResolver {
Repository db) throws IOException {
if (isExportAll())
return true;
else
else if (db.getDirectory() != null)
return new File(db.getDirectory(), "git-daemon-export-ok").exists();
else
return false;
}
private static boolean isUnreasonableName(final String name) {

1
org.eclipse.jgit.http.test/META-INF/MANIFEST.MF

@ -29,5 +29,6 @@ Import-Package: javax.servlet;version="[2.5.0,3.0.0)",
org.eclipse.jgit.junit;version="[0.9.0,0.10.0)",
org.eclipse.jgit.lib;version="[0.9.0,0.10.0)",
org.eclipse.jgit.revwalk;version="[0.9.0,0.10.0)",
org.eclipse.jgit.storage.file;version="[0.9.0,0.10.0)",
org.eclipse.jgit.transport;version="[0.9.0,0.10.0)",
org.eclipse.jgit.util;version="[0.9.0,0.10.0)"

9
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AdvertiseErrorTest.java

@ -62,23 +62,24 @@ import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryConfig;
import org.eclipse.jgit.revwalk.RevBlob;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.jgit.transport.ReceivePack;
import org.eclipse.jgit.transport.RemoteRefUpdate;
import org.eclipse.jgit.transport.Transport;
import org.eclipse.jgit.transport.URIish;
public class AdvertiseErrorTest extends HttpTestCase {
private Repository remoteRepository;
private FileRepository remoteRepository;
private URIish remoteURI;
protected void setUp() throws Exception {
super.setUp();
final TestRepository src = createTestRepository();
final TestRepository<FileRepository> src = createTestRepository();
final String srcName = src.getRepository().getDirectory().getName();
ServletContextHandler app = server.addContext("/git");
@ -114,7 +115,7 @@ public class AdvertiseErrorTest extends HttpTestCase {
remoteRepository = src.getRepository();
remoteURI = toURIish(app, srcName);
RepositoryConfig cfg = remoteRepository.getConfig();
FileBasedConfig cfg = remoteRepository.getConfig();
cfg.setBoolean("http", null, "receivepack", true);
cfg.save();
}

9
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HookMessageTest.java

@ -64,9 +64,10 @@ import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryConfig;
import org.eclipse.jgit.revwalk.RevBlob;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.jgit.transport.PreReceiveHook;
import org.eclipse.jgit.transport.PushResult;
import org.eclipse.jgit.transport.ReceiveCommand;
@ -76,14 +77,14 @@ import org.eclipse.jgit.transport.Transport;
import org.eclipse.jgit.transport.URIish;
public class HookMessageTest extends HttpTestCase {
private Repository remoteRepository;
private FileRepository remoteRepository;
private URIish remoteURI;
protected void setUp() throws Exception {
super.setUp();
final TestRepository src = createTestRepository();
final TestRepository<FileRepository> src = createTestRepository();
final String srcName = src.getRepository().getDirectory().getName();
ServletContextHandler app = server.addContext("/git");
@ -124,7 +125,7 @@ public class HookMessageTest extends HttpTestCase {
remoteRepository = src.getRepository();
remoteURI = toURIish(app, srcName);
RepositoryConfig cfg = remoteRepository.getConfig();
FileBasedConfig cfg = remoteRepository.getConfig();
cfg.setBoolean("http", null, "receivepack", true);
cfg.save();
}

17
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java

@ -66,12 +66,13 @@ import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.jgit.transport.FetchConnection;
import org.eclipse.jgit.transport.Transport;
import org.eclipse.jgit.transport.URIish;
public class HttpClientTests extends HttpTestCase {
private TestRepository remoteRepository;
private TestRepository<FileRepository> remoteRepository;
private URIish dumbAuthNoneURI;
@ -95,7 +96,7 @@ public class HttpClientTests extends HttpTestCase {
server.setUp();
final String srcName = nameOf(remoteRepository);
final String srcName = nameOf(remoteRepository.getRepository());
dumbAuthNoneURI = toURIish(dNone, srcName);
dumbAuthBasicURI = toURIish(dBasic, srcName);
@ -119,10 +120,10 @@ public class HttpClientTests extends HttpTestCase {
public Repository open(HttpServletRequest req, String name)
throws RepositoryNotFoundException,
ServiceNotEnabledException {
if (!name.equals(nameOf(remoteRepository)))
final FileRepository db = remoteRepository.getRepository();
if (!name.equals(nameOf(db)))
throw new RepositoryNotFoundException(name);
final Repository db = remoteRepository.getRepository();
db.incrementOpen();
return db;
}
@ -133,8 +134,8 @@ public class HttpClientTests extends HttpTestCase {
return ctx;
}
private static String nameOf(final TestRepository db) {
return db.getRepository().getDirectory().getName();
private static String nameOf(final FileRepository db) {
return db.getDirectory().getName();
}
public void testRepositoryNotFound_Dumb() throws Exception {
@ -198,7 +199,7 @@ public class HttpClientTests extends HttpTestCase {
}
public void testListRemote_Dumb_NoHEAD() throws Exception {
Repository src = remoteRepository.getRepository();
FileRepository src = remoteRepository.getRepository();
File headref = new File(src.getDirectory(), Constants.HEAD);
assertTrue("HEAD used to be present", headref.delete());
assertFalse("HEAD is gone", headref.exists());
@ -306,7 +307,7 @@ public class HttpClientTests extends HttpTestCase {
}
public void testListRemote_Smart_UploadPackDisabled() throws Exception {
Repository src = remoteRepository.getRepository();
FileRepository src = remoteRepository.getRepository();
src.getConfig().setBoolean("http", null, "uploadpack", false);
src.getConfig().save();

15
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java

@ -79,11 +79,12 @@ import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.ReflogReader;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryConfig;
import org.eclipse.jgit.revwalk.RevBlob;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.jgit.storage.file.ReflogReader;
import org.eclipse.jgit.transport.FetchConnection;
import org.eclipse.jgit.transport.HttpTransport;
import org.eclipse.jgit.transport.RemoteRefUpdate;
@ -94,7 +95,7 @@ import org.eclipse.jgit.transport.URIish;
public class SmartClientSmartServerTest extends HttpTestCase {
private static final String HDR_TRANSFER_ENCODING = "Transfer-Encoding";
private Repository remoteRepository;
private FileRepository remoteRepository;
private URIish remoteURI;
@ -107,7 +108,7 @@ public class SmartClientSmartServerTest extends HttpTestCase {
protected void setUp() throws Exception {
super.setUp();
final TestRepository src = createTestRepository();
final TestRepository<FileRepository> src = createTestRepository();
final String srcName = src.getRepository().getDirectory().getName();
ServletContextHandler app = server.addContext("/git");
@ -489,10 +490,10 @@ public class SmartClientSmartServerTest extends HttpTestCase {
}
public void testPush_ChunkedEncoding() throws Exception {
final TestRepository src = createTestRepository();
final TestRepository<FileRepository> src = createTestRepository();
final RevBlob Q_bin = src.blob(new TestRng("Q").nextBytes(128 * 1024));
final RevCommit Q = src.commit().add("Q", Q_bin).create();
final Repository db = src.getRepository();
final FileRepository db = src.getRepository();
final String dstName = Constants.R_HEADS + "new.branch";
Transport t;
@ -547,7 +548,7 @@ public class SmartClientSmartServerTest extends HttpTestCase {
}
private void enableReceivePack() throws IOException {
final RepositoryConfig cfg = remoteRepository.getConfig();
final FileBasedConfig cfg = remoteRepository.getConfig();
cfg.setBoolean("http", null, "receivepack", true);
cfg.save();
}

6
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/util/HttpTestCase.java

@ -61,6 +61,7 @@ import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevObject;
import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteRefUpdate;
import org.eclipse.jgit.transport.URIish;
@ -82,8 +83,9 @@ public abstract class HttpTestCase extends LocalDiskRepositoryTestCase {
super.tearDown();
}
protected TestRepository createTestRepository() throws Exception {
return new TestRepository(createBareRepository());
protected TestRepository<FileRepository> createTestRepository()
throws IOException {
return new TestRepository<FileRepository>(createBareRepository());
}
protected URIish toURIish(String path) throws URISyntaxException {

1
org.eclipse.jgit.iplog/META-INF/MANIFEST.MF

@ -15,6 +15,7 @@ Import-Package: org.eclipse.jgit.diff;version="[0.9.0,0.10.0)",
org.eclipse.jgit.revplot;version="[0.9.0,0.10.0)",
org.eclipse.jgit.revwalk;version="[0.9.0,0.10.0)",
org.eclipse.jgit.revwalk.filter;version="[0.9.0,0.10.0)",
org.eclipse.jgit.storage.file;version="[0.9.0,0.10.0)",
org.eclipse.jgit.transport;version="[0.9.0,0.10.0)",
org.eclipse.jgit.treewalk;version="[0.9.0,0.10.0)",
org.eclipse.jgit.treewalk.filter;version="[0.9.0,0.10.0)",

18
org.eclipse.jgit.iplog/src/org/eclipse/jgit/iplog/IpLogGenerator.java

@ -78,15 +78,13 @@ import org.eclipse.jgit.diff.EditList;
import org.eclipse.jgit.diff.MyersDiff;
import org.eclipse.jgit.diff.RawText;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.iplog.Committer.ActiveRange;
import org.eclipse.jgit.lib.BlobBasedConfig;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.MutableObjectId;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.WindowCursor;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.revwalk.RevWalk;
@ -144,7 +142,7 @@ public class IpLogGenerator {
private NameConflictTreeWalk tw;
private final WindowCursor curs = new WindowCursor();
private ObjectReader curs;
private final MutableObjectId idbuf = new MutableObjectId();
@ -184,8 +182,9 @@ public class IpLogGenerator {
throws IOException, ConfigInvalidException {
try {
db = repo;
rw = new RevWalk(db);
tw = new NameConflictTreeWalk(db);
curs = db.newObjectReader();
rw = new RevWalk(curs);
tw = new NameConflictTreeWalk(curs);
RevCommit c = rw.parseCommit(startCommit);
@ -194,7 +193,7 @@ public class IpLogGenerator {
scanProjectCommits(meta.getProjects().get(0), c);
commits.add(c);
} finally {
WindowCursor.release(curs);
curs.release();
db = null;
rw = null;
tw = null;
@ -417,10 +416,7 @@ public class IpLogGenerator {
private byte[] openBlob(int side) throws IOException {
tw.getObjectId(idbuf, side);
ObjectLoader ldr = db.openObject(curs, idbuf);
if (ldr == null)
throw new MissingObjectException(idbuf.copy(), Constants.OBJ_BLOB);
return ldr.getCachedBytes();
return curs.open(idbuf, Constants.OBJ_BLOB).getCachedBytes();
}
/**

4
org.eclipse.jgit.iplog/src/org/eclipse/jgit/iplog/IpLogMeta.java

@ -58,9 +58,9 @@ import java.util.Set;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileBasedConfig;
import org.eclipse.jgit.lib.LockFile;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.storage.file.LockFile;
/**
* Manages the {@code .eclipse_iplog} file in a project.

2
org.eclipse.jgit.junit/META-INF/MANIFEST.MF

@ -18,6 +18,8 @@ Import-Package: junit.framework;version="[3.8.2,4.0.0)",
org.eclipse.jgit.revplot;version="[0.9.0,0.10.0)",
org.eclipse.jgit.revwalk;version="[0.9.0,0.10.0)",
org.eclipse.jgit.revwalk.filter;version="[0.9.0,0.10.0)",
org.eclipse.jgit.storage.file;version="[0.9.0,0.10.0)",
org.eclipse.jgit.storage.pack;version="[0.9.0,0.10.0)",
org.eclipse.jgit.transport;version="[0.9.0,0.10.0)",
org.eclipse.jgit.treewalk;version="[0.9.0,0.10.0)",
org.eclipse.jgit.treewalk.filter;version="[0.9.0,0.10.0)",

17
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java

@ -62,12 +62,13 @@ import junit.framework.TestCase;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileBasedConfig;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryCache;
import org.eclipse.jgit.lib.WindowCache;
import org.eclipse.jgit.lib.WindowCacheConfig;
import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.jgit.storage.file.WindowCache;
import org.eclipse.jgit.storage.file.WindowCacheConfig;
import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.SystemReader;
@ -259,7 +260,7 @@ public abstract class LocalDiskRepositoryTestCase extends TestCase {
* @throws IOException
* the repository could not be created in the temporary area
*/
protected Repository createBareRepository() throws IOException {
protected FileRepository createBareRepository() throws IOException {
return createRepository(true /* bare */);
}
@ -270,7 +271,7 @@ public abstract class LocalDiskRepositoryTestCase extends TestCase {
* @throws IOException
* the repository could not be created in the temporary area
*/
protected Repository createWorkRepository() throws IOException {
protected FileRepository createWorkRepository() throws IOException {
return createRepository(false /* not bare */);
}
@ -284,11 +285,11 @@ public abstract class LocalDiskRepositoryTestCase extends TestCase {
* @throws IOException
* the repository could not be created in the temporary area
*/
private Repository createRepository(boolean bare) throws IOException {
private FileRepository createRepository(boolean bare) throws IOException {
String uniqueId = System.currentTimeMillis() + "_" + (testCount++);
String gitdirName = "test" + uniqueId + (bare ? "" : "/") + Constants.DOT_GIT;
File gitdir = new File(trash, gitdirName).getCanonicalFile();
Repository db = new Repository(gitdir);
FileRepository db = new FileRepository(gitdir);
assertFalse(gitdir.exists());
db.create();
@ -323,7 +324,7 @@ public abstract class LocalDiskRepositoryTestCase extends TestCase {
putPersonIdent(env, "AUTHOR", author);
putPersonIdent(env, "COMMITTER", committer);
final File cwd = db.getWorkDir();
final File cwd = db.getWorkTree();
final Process p = Runtime.getRuntime().exec(argv, toEnvArray(env), cwd);
p.getOutputStream().close();
p.getErrorStream().close();

2
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/MockSystemReader.java

@ -52,7 +52,7 @@ import java.util.TimeZone;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileBasedConfig;
import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.SystemReader;

135
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java

@ -73,22 +73,16 @@ import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Commit;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.LockFile;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectChecker;
import org.eclipse.jgit.lib.ObjectDatabase;
import org.eclipse.jgit.lib.ObjectDirectory;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectWriter;
import org.eclipse.jgit.lib.PackFile;
import org.eclipse.jgit.lib.PackWriter;
import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.RefWriter;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.Tag;
import org.eclipse.jgit.lib.PackIndex.MutableEntry;
import org.eclipse.jgit.revwalk.ObjectWalk;
import org.eclipse.jgit.revwalk.RevBlob;
import org.eclipse.jgit.revwalk.RevCommit;
@ -96,11 +90,22 @@ import org.eclipse.jgit.revwalk.RevObject;
import org.eclipse.jgit.revwalk.RevTag;
import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.jgit.storage.file.LockFile;
import org.eclipse.jgit.storage.file.ObjectDirectory;
import org.eclipse.jgit.storage.file.PackFile;
import org.eclipse.jgit.storage.file.PackIndex.MutableEntry;
import org.eclipse.jgit.storage.pack.PackWriter;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
/** Wrapper to make creating test data easier. */
public class TestRepository {
/**
* Wrapper to make creating test data easier.
*
* @param <R>
* type of Repository the test data is stored on.
*/
public class TestRepository<R extends Repository> {
private static final PersonIdent author;
private static final PersonIdent committer;
@ -119,11 +124,11 @@ public class TestRepository {
committer = new PersonIdent(cn, ce, now, tz);
}
private final Repository db;
private final R db;
private final RevWalk pool;
private final ObjectWriter writer;
private final ObjectInserter inserter;
private long now;
@ -132,9 +137,9 @@ public class TestRepository {
*
* @param db
* the test repository to write into.
* @throws Exception
* @throws IOException
*/
public TestRepository(Repository db) throws Exception {
public TestRepository(R db) throws IOException {
this(db, new RevWalk(db));
}
@ -145,17 +150,17 @@ public class TestRepository {
* the test repository to write into.
* @param rw
* the RevObject pool to use for object lookup.
* @throws Exception
* @throws IOException
*/
public TestRepository(Repository db, RevWalk rw) throws Exception {
public TestRepository(R db, RevWalk rw) throws IOException {
this.db = db;
this.pool = rw;
this.writer = new ObjectWriter(db);
this.inserter = db.newObjectInserter();
this.now = 1236977987000L;
}
/** @return the repository this helper class operates against. */
public Repository getRepository() {
public R getRepository() {
return db;
}
@ -200,7 +205,14 @@ public class TestRepository {
* @throws Exception
*/
public RevBlob blob(final byte[] content) throws Exception {
return pool.lookupBlob(writer.writeBlob(content));
ObjectId id;
try {
id = inserter.insert(Constants.OBJ_BLOB, content);
inserter.flush();
} finally {
inserter.release();
}
return pool.lookupBlob(id);
}
/**
@ -236,7 +248,14 @@ public class TestRepository {
for (final DirCacheEntry e : entries)
b.add(e);
b.finish();
return pool.lookupTree(dc.writeTree(writer));
ObjectId root;
try {
root = dc.writeTree(inserter);
inserter.flush();
} finally {
inserter.release();
}
return pool.lookupTree(root);
}
/**
@ -253,7 +272,7 @@ public class TestRepository {
*/
public RevObject get(final RevTree tree, final String path)
throws AssertionFailedError, Exception {
final TreeWalk tw = new TreeWalk(db);
final TreeWalk tw = new TreeWalk(pool.getObjectReader());
tw.setFilter(PathFilterGroup.createFromStrings(Collections
.singleton(path)));
tw.reset(tree);
@ -346,7 +365,14 @@ public class TestRepository {
c.setAuthor(new PersonIdent(author, new Date(now)));
c.setCommitter(new PersonIdent(committer, new Date(now)));
c.setMessage("");
return pool.lookupCommit(writer.writeCommit(c));
ObjectId id;
try {
id = inserter.insert(Constants.OBJ_COMMIT, inserter.format(c));
inserter.flush();
} finally {
inserter.release();
}
return pool.lookupCommit(id);
}
/** @return a new commit builder. */
@ -377,7 +403,14 @@ public class TestRepository {
t.setTag(name);
t.setTagger(new PersonIdent(committer, new Date(now)));
t.setMessage("");
return (RevTag) pool.lookupAny(writer.writeTag(t), Constants.OBJ_TAG);
ObjectId id;
try {
id = inserter.insert(Constants.OBJ_TAG, inserter.format(t));
inserter.flush();
} finally {
inserter.release();
}
return (RevTag) pool.lookupAny(id, Constants.OBJ_TAG);
}
/**
@ -443,25 +476,27 @@ public class TestRepository {
* @throws Exception
*/
public void updateServerInfo() throws Exception {
final ObjectDatabase odb = db.getObjectDatabase();
if (odb instanceof ObjectDirectory) {
RefWriter rw = new RefWriter(db.getAllRefs().values()) {
if (db instanceof FileRepository) {
final FileRepository fr = (FileRepository) db;
RefWriter rw = new RefWriter(fr.getAllRefs().values()) {
@Override
protected void writeFile(final String name, final byte[] bin)
throws IOException {
TestRepository.this.writeFile(name, bin);
File path = new File(fr.getDirectory(), name);
TestRepository.this.writeFile(path, bin);
}
};
rw.writePackedRefs();
rw.writeInfoRefs();
final StringBuilder w = new StringBuilder();
for (PackFile p : ((ObjectDirectory) odb).getPacks()) {
for (PackFile p : fr.getObjectDatabase().getPacks()) {
w.append("P ");
w.append(p.getPackFile().getName());
w.append('\n');
}
writeFile("objects/info/packs", Constants.encodeASCII(w.toString()));
writeFile(new File(new File(fr.getObjectDatabase().getDirectory(),
"info"), "packs"), Constants.encodeASCII(w.toString()));
}
}
@ -528,7 +563,7 @@ public class TestRepository {
if (o == null)
break;
final byte[] bin = db.openObject(o).getCachedBytes();
final byte[] bin = db.open(o, o.getType()).getCachedBytes();
oc.checkCommit(bin);
assertHash(o, bin);
}
@ -538,7 +573,7 @@ public class TestRepository {
if (o == null)
break;
final byte[] bin = db.openObject(o).getCachedBytes();
final byte[] bin = db.open(o, o.getType()).getCachedBytes();
oc.check(o.getType(), bin);
assertHash(o, bin);
}
@ -563,27 +598,31 @@ public class TestRepository {
* @throws Exception
*/
public void packAndPrune() throws Exception {
final ObjectDirectory odb = (ObjectDirectory) db.getObjectDatabase();
final PackWriter pw = new PackWriter(db, NullProgressMonitor.INSTANCE);
if (db.getObjectDatabase() instanceof ObjectDirectory) {
ObjectDirectory odb = (ObjectDirectory) db.getObjectDatabase();
NullProgressMonitor m = NullProgressMonitor.INSTANCE;
final File pack, idx;
PackWriter pw = new PackWriter(db);
try {
Set<ObjectId> all = new HashSet<ObjectId>();
for (Ref r : db.getAllRefs().values())
all.add(r.getObjectId());
pw.preparePack(all, Collections.<ObjectId> emptySet());
pw.preparePack(m, all, Collections.<ObjectId> emptySet());
final ObjectId name = pw.computeName();
OutputStream out;
final File pack = nameFor(odb, name, ".pack");
pack = nameFor(odb, name, ".pack");
out = new BufferedOutputStream(new FileOutputStream(pack));
try {
pw.writePack(out);
pw.writePack(m, m, out);
} finally {
out.close();
}
pack.setReadOnly();
final File idx = nameFor(odb, name, ".idx");
idx = nameFor(odb, name, ".idx");
out = new BufferedOutputStream(new FileOutputStream(idx));
try {
pw.writeIndex(out);
@ -591,11 +630,15 @@ public class TestRepository {
out.close();
}
idx.setReadOnly();
} finally {
pw.release();
}
odb.openPack(pack, idx);
updateServerInfo();
prunePacked(odb);
}
}
private void prunePacked(ObjectDirectory odb) {
for (PackFile p : odb.getPacks()) {
@ -609,9 +652,8 @@ public class TestRepository {
return new File(packdir, "pack-" + name.name() + t);
}
private void writeFile(final String name, final byte[] bin)
throws IOException, ObjectWritingException {
final File p = new File(db.getDirectory(), name);
private void writeFile(final File p, final byte[] bin) throws IOException,
ObjectWritingException {
final LockFile lck = new LockFile(p);
if (!lck.lock())
throw new ObjectWritingException("Can't write " + p);
@ -711,7 +753,8 @@ public class TestRepository {
if (parents.isEmpty()) {
DirCacheBuilder b = tree.builder();
parseBody(p);
b.addTree(new byte[0], DirCacheEntry.STAGE_0, db, p.getTree());
b.addTree(new byte[0], DirCacheEntry.STAGE_0, pool
.getObjectReader(), p.getTree());
b.finish();
}
parents.add(p);
@ -769,13 +812,21 @@ public class TestRepository {
TestRepository.this.tick(tick);
final Commit c = new Commit(db);
c.setTreeId(pool.lookupTree(tree.writeTree(writer)));
c.setParentIds(parents.toArray(new RevCommit[parents.size()]));
c.setAuthor(new PersonIdent(author, new Date(now)));
c.setCommitter(new PersonIdent(committer, new Date(now)));
c.setMessage(message);
self = pool.lookupCommit(writer.writeCommit(c));
ObjectId commitId;
try {
c.setTreeId(tree.writeTree(inserter));
commitId = inserter.insert(Constants.OBJ_COMMIT, inserter
.format(c));
inserter.flush();
} finally {
inserter.release();
}
self = pool.lookupCommit(commitId);
if (branch != null)
branch.update(self);

2
org.eclipse.jgit.pgm/META-INF/MANIFEST.MF

@ -17,6 +17,8 @@ Import-Package: org.eclipse.jgit.api;version="[0.9.0,0.10.0)",
org.eclipse.jgit.revplot;version="[0.9.0,0.10.0)",
org.eclipse.jgit.revwalk;version="[0.9.0,0.10.0)",
org.eclipse.jgit.revwalk.filter;version="[0.9.0,0.10.0)",
org.eclipse.jgit.storage.file;version="[0.9.0,0.10.0)",
org.eclipse.jgit.storage.pack;version="[0.9.0,0.10.0)",
org.eclipse.jgit.transport;version="[0.9.0,0.10.0)",
org.eclipse.jgit.treewalk;version="[0.9.0,0.10.0)",
org.eclipse.jgit.treewalk.filter;version="[0.9.0,0.10.0)",

1
org.eclipse.jgit.pgm/META-INF/services/org.eclipse.jgit.pgm.TextBuiltin

@ -30,6 +30,7 @@ org.eclipse.jgit.pgm.debug.RebuildCommitGraph
org.eclipse.jgit.pgm.debug.ShowCacheTree
org.eclipse.jgit.pgm.debug.ShowCommands
org.eclipse.jgit.pgm.debug.ShowDirCache
org.eclipse.jgit.pgm.debug.ShowPackDelta
org.eclipse.jgit.pgm.debug.WriteDirCache
org.eclipse.jgit.pgm.eclipse.Iplog

21
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java

@ -61,10 +61,10 @@ import org.eclipse.jgit.lib.GitIndex;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefComparator;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.TextProgressMonitor;
import org.eclipse.jgit.lib.Tree;
import org.eclipse.jgit.lib.WorkDirCheckout;
import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.jgit.transport.FetchResult;
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig;
@ -82,6 +82,8 @@ class Clone extends AbstractFetchCommand {
@Argument(index = 1, metaVar = "metaVar_directory")
private String localName;
private FileRepository dst;
@Override
protected final boolean requiresRepository() {
return false;
@ -103,10 +105,11 @@ class Clone extends AbstractFetchCommand {
if (gitdir == null)
gitdir = new File(localName, Constants.DOT_GIT);
db = new Repository(gitdir);
db.create();
db.getConfig().setBoolean("core", null, "bare", false);
db.getConfig().save();
dst = new FileRepository(gitdir);
dst.create();
dst.getConfig().setBoolean("core", null, "bare", false);
dst.getConfig().save();
db = dst;
out.format(CLIText.get().initializedEmptyGitRepositoryIn, gitdir.getAbsolutePath());
out.println();
@ -120,13 +123,13 @@ class Clone extends AbstractFetchCommand {
private void saveRemote(final URIish uri) throws URISyntaxException,
IOException {
final RemoteConfig rc = new RemoteConfig(db.getConfig(), remoteName);
final RemoteConfig rc = new RemoteConfig(dst.getConfig(), remoteName);
rc.addURI(uri);
rc.addFetchRefSpec(new RefSpec().setForceUpdate(true)
.setSourceDestination(Constants.R_HEADS + "*",
Constants.R_REMOTES + remoteName + "/*"));
rc.update(db.getConfig());
db.getConfig().save();
rc.update(dst.getConfig());
dst.getConfig().save();
}
private FetchResult runFetch() throws NotSupportedException,
@ -180,7 +183,7 @@ class Clone extends AbstractFetchCommand {
final Tree tree = commit.getTree();
final WorkDirCheckout co;
co = new WorkDirCheckout(db, db.getWorkDir(), index, tree);
co = new WorkDirCheckout(db, db.getWorkTree(), index, tree);
co.checkout();
index.write();
}

8
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Glog.java

@ -125,10 +125,12 @@ class Glog extends RevWalkTextBuiltin {
}
private String repoName() {
final File f = db.getDirectory();
String n = f.getName();
final File gitDir = db.getDirectory();
if (gitDir == null)
return db.toString();
String n = gitDir.getName();
if (Constants.DOT_GIT.equals(n))
n = f.getParentFile().getName();
n = gitDir.getParentFile().getName();
return n;
}
}

4
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/IndexPack.java

@ -49,6 +49,7 @@ import java.io.File;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option;
import org.eclipse.jgit.lib.CoreConfig;
import org.eclipse.jgit.lib.TextProgressMonitor;
class IndexPack extends TextBuiltin {
@ -64,7 +65,8 @@ class IndexPack extends TextBuiltin {
@Override
protected void run() throws Exception {
if (indexVersion == -1)
indexVersion = db.getConfig().getCore().getPackIndexVersion();
indexVersion = db.getConfig().get(CoreConfig.KEY)
.getPackIndexVersion();
final BufferedInputStream in;
final org.eclipse.jgit.transport.IndexPack ip;
in = new BufferedInputStream(System.in);

4
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java

@ -50,7 +50,7 @@ import java.text.MessageFormat;
import org.kohsuke.args4j.Option;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.storage.file.FileRepository;
@Command(common = true, usage = "usage_CreateAnEmptyGitRepository")
class Init extends TextBuiltin {
@ -66,7 +66,7 @@ class Init extends TextBuiltin {
protected void run() throws Exception {
if (gitdir == null)
gitdir = new File(bare ? "." : Constants.DOT_GIT);
db = new Repository(gitdir);
db = new FileRepository(gitdir);
db.create(bare);
out.println(MessageFormat.format(CLIText.get().initializedEmptyGitRepositoryIn, gitdir.getAbsolutePath()));
}

76
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java

@ -51,20 +51,15 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.jgit.awtui.AwtAuthenticator;
import org.eclipse.jgit.awtui.AwtSshSessionFactory;
import org.eclipse.jgit.errors.TransportException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryBuilder;
import org.eclipse.jgit.pgm.opt.CmdLineParser;
import org.eclipse.jgit.pgm.opt.SubcommandHandler;
import org.eclipse.jgit.util.CachedAuthenticator;
import org.eclipse.jgit.util.SystemReader;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.ExampleMode;
@ -168,51 +163,17 @@ public class Main {
final TextBuiltin cmd = subcommand;
if (cmd.requiresRepository()) {
if (gitdir == null) {
String gitDirEnv = SystemReader.getInstance().getenv(Constants.GIT_DIR_KEY);
if (gitDirEnv != null)
gitdir = new File(gitDirEnv);
}
if (gitdir == null)
gitdir = findGitDir();
File gitworktree;
String gitWorkTreeEnv = SystemReader.getInstance().getenv(Constants.GIT_WORK_TREE_KEY);
if (gitWorkTreeEnv != null)
gitworktree = new File(gitWorkTreeEnv);
else
gitworktree = null;
File indexfile;
String indexFileEnv = SystemReader.getInstance().getenv(Constants.GIT_INDEX_KEY);
if (indexFileEnv != null)
indexfile = new File(indexFileEnv);
else
indexfile = null;
File objectdir;
String objectDirEnv = SystemReader.getInstance().getenv(Constants.GIT_OBJECT_DIRECTORY_KEY);
if (objectDirEnv != null)
objectdir = new File(objectDirEnv);
else
objectdir = null;
File[] altobjectdirs;
String altObjectDirEnv = SystemReader.getInstance().getenv(Constants.GIT_ALTERNATE_OBJECT_DIRECTORIES_KEY);
if (altObjectDirEnv != null) {
String[] parserdAltObjectDirEnv = altObjectDirEnv.split(File.pathSeparator);
altobjectdirs = new File[parserdAltObjectDirEnv.length];
for (int i = 0; i < parserdAltObjectDirEnv.length; i++)
altobjectdirs[i] = new File(parserdAltObjectDirEnv[i]);
} else
altobjectdirs = null;
if (gitdir == null || !gitdir.isDirectory()) {
RepositoryBuilder rb = new RepositoryBuilder() //
.setGitDir(gitdir) //
.readEnvironment() //
.findGitDir();
if (rb.getGitDir() == null) {
writer.println(CLIText.get().cantFindGitDirectory);
writer.flush();
System.exit(1);
}
cmd.init(new Repository(gitdir, gitworktree, objectdir, altobjectdirs, indexfile), gitdir);
cmd.init(rb.build(), null);
} else {
cmd.init(null, gitdir);
}
@ -224,27 +185,6 @@ public class Main {
}
}
private static File findGitDir() {
Set<String> ceilingDirectories = new HashSet<String>();
String ceilingDirectoriesVar = SystemReader.getInstance().getenv(
Constants.GIT_CEILING_DIRECTORIES_KEY);
if (ceilingDirectoriesVar != null) {
ceilingDirectories.addAll(Arrays.asList(ceilingDirectoriesVar
.split(File.pathSeparator)));
}
File current = new File("").getAbsoluteFile();
while (current != null) {
final File gitDir = new File(current, Constants.DOT_GIT);
if (gitDir.isDirectory())
return gitDir;
current = current.getParentFile();
if (current != null
&& ceilingDirectories.contains(current.getPath()))
break;
}
return null;
}
private static boolean installConsole() {
try {
install("org.eclipse.jgit.console.ConsoleAuthenticator");

18
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ReceivePack.java

@ -47,9 +47,10 @@ package org.eclipse.jgit.pgm;
import java.io.File;
import java.text.MessageFormat;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.RepositoryCache.FileKey;
import org.eclipse.jgit.util.FS;
import org.kohsuke.args4j.Argument;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Repository;
@Command(common = false, usage = "usage_ServerSideBackendForJgitPush")
class ReceivePack extends TextBuiltin {
@ -65,11 +66,14 @@ class ReceivePack extends TextBuiltin {
protected void run() throws Exception {
final org.eclipse.jgit.transport.ReceivePack rp;
if (new File(dstGitdir, Constants.DOT_GIT).isDirectory())
dstGitdir = new File(dstGitdir, Constants.DOT_GIT);
db = new Repository(dstGitdir);
if (!db.getObjectsDirectory().isDirectory())
throw die(MessageFormat.format(CLIText.get().notAGitRepository, dstGitdir.getPath()));
try {
FileKey key = FileKey.lenient(dstGitdir, FS.DETECTED);
db = key.open(true /* must exist */);
} catch (RepositoryNotFoundException notFound) {
throw die(MessageFormat.format(CLIText.get().notAGitRepository,
dstGitdir.getPath()));
}
rp = new org.eclipse.jgit.transport.ReceivePack(db);
rp.receive(System.in, System.out, System.err);
}

4
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Rm.java

@ -67,9 +67,9 @@ class Rm extends TextBuiltin {
@Override
protected void run() throws Exception {
root = db.getWorkDir();
root = db.getWorkTree();
final DirCache dirc = DirCache.lock(db);
final DirCache dirc = db.lockDirCache();
final DirCacheBuilder edit = dirc.builder();
final TreeWalk walk = new TreeWalk(db);

9
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java

@ -49,13 +49,12 @@ package org.eclipse.jgit.pgm;
import java.text.MessageFormat;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.PersonIdent;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option;
@Command(common = true, usage = "usage_CreateATag")
class Tag extends TextBuiltin {
@ -86,9 +85,7 @@ class Tag extends TextBuiltin {
, tagName.substring(Constants.R_TAGS.length())));
}
final ObjectLoader ldr = db.openObject(object);
if (ldr == null)
throw new MissingObjectException(object, "any");
final ObjectLoader ldr = db.open(object);
org.eclipse.jgit.lib.Tag tag = new org.eclipse.jgit.lib.Tag(db);
tag.setObjId(object);

26
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/UploadPack.java

@ -47,10 +47,11 @@ package org.eclipse.jgit.pgm;
import java.io.File;
import java.text.MessageFormat;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.RepositoryCache.FileKey;
import org.eclipse.jgit.util.FS;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Repository;
@Command(common = false, usage = "usage_ServerSideBackendForJgitFetch")
class UploadPack extends TextBuiltin {
@ -67,16 +68,19 @@ class UploadPack extends TextBuiltin {
@Override
protected void run() throws Exception {
final org.eclipse.jgit.transport.UploadPack rp;
final org.eclipse.jgit.transport.UploadPack up;
if (new File(srcGitdir, Constants.DOT_GIT).isDirectory())
srcGitdir = new File(srcGitdir, Constants.DOT_GIT);
db = new Repository(srcGitdir);
if (!db.getObjectsDirectory().isDirectory())
throw die(MessageFormat.format(CLIText.get().notAGitRepository, srcGitdir.getPath()));
rp = new org.eclipse.jgit.transport.UploadPack(db);
try {
FileKey key = FileKey.lenient(srcGitdir, FS.DETECTED);
db = key.open(true /* must exist */);
} catch (RepositoryNotFoundException notFound) {
throw die(MessageFormat.format(CLIText.get().notAGitRepository,
srcGitdir.getPath()));
}
up = new org.eclipse.jgit.transport.UploadPack(db);
if (0 <= timeout)
rp.setTimeout(timeout);
rp.upload(System.in, System.out, System.err);
up.setTimeout(timeout);
up.upload(System.in, System.out, System.err);
}
}

2
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/MakeCacheTree.java

@ -54,7 +54,7 @@ import org.eclipse.jgit.pgm.TextBuiltin;
class MakeCacheTree extends TextBuiltin {
@Override
protected void run() throws Exception {
final DirCache cache = DirCache.read(db);
final DirCache cache = db.readDirCache();
final DirCacheTree tree = cache.getCacheTree(true);
show(tree);
}

3
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ReadDirCache.java

@ -46,7 +46,6 @@ package org.eclipse.jgit.pgm.debug;
import java.text.MessageFormat;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.pgm.CLIText;
import org.eclipse.jgit.pgm.TextBuiltin;
@ -56,7 +55,7 @@ class ReadDirCache extends TextBuiltin {
final int cnt = 100;
final long start = System.currentTimeMillis();
for (int i = 0; i < cnt; i++)
DirCache.read(db);
db.readDirCache();
final long end = System.currentTimeMillis();
out.print(" ");
out.println(MessageFormat.format(CLIText.get().averageMSPerRead, (end - start) / cnt));

3
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java

@ -62,7 +62,6 @@ import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.ObjectWritingException;
import org.eclipse.jgit.lib.Commit;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.LockFile;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectIdRef;
import org.eclipse.jgit.lib.ObjectWriter;
@ -76,6 +75,7 @@ import org.eclipse.jgit.lib.Tree;
import org.eclipse.jgit.pgm.CLIText;
import org.eclipse.jgit.pgm.TextBuiltin;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.storage.file.LockFile;
/**
* Recreates a repository from another one's commit graph.
@ -297,6 +297,7 @@ class RebuildCommitGraph extends TextBuiltin {
name, id));
}
} finally {
rw.release();
br.close();
}
return refs;

2
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowCacheTree.java

@ -54,7 +54,7 @@ import org.eclipse.jgit.pgm.TextBuiltin;
class ShowCacheTree extends TextBuiltin {
@Override
protected void run() throws Exception {
final DirCache cache = DirCache.read(db);
final DirCache cache = db.readDirCache();
final DirCacheTree tree = cache.getCacheTree(false);
if (tree == null)
throw die(CLIText.get().noTREESectionInIndex);

2
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowDirCache.java

@ -59,7 +59,7 @@ class ShowDirCache extends TextBuiltin {
final SimpleDateFormat fmt;
fmt = new SimpleDateFormat("yyyyMMdd,HHmmss.SSS");
final DirCache cache = DirCache.read(db);
final DirCache cache = db.readDirCache();
for (int i = 0; i < cache.getEntryCount(); i++) {
final DirCacheEntry ent = cache.getEntry(i);
final FileMode mode = FileMode.fromBits(ent.getRawMode());

127
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java

@ -0,0 +1,127 @@
/*
* Copyright (C) 2010, 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.pgm.debug;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.InflaterInputStream;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.StoredObjectRepresentationNotAvailableException;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.pgm.TextBuiltin;
import org.eclipse.jgit.revwalk.RevObject;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.storage.pack.BinaryDelta;
import org.eclipse.jgit.storage.pack.ObjectReuseAsIs;
import org.eclipse.jgit.storage.pack.ObjectToPack;
import org.eclipse.jgit.storage.pack.PackOutputStream;
import org.eclipse.jgit.storage.pack.PackWriter;
import org.eclipse.jgit.storage.pack.StoredObjectRepresentation;
import org.eclipse.jgit.util.TemporaryBuffer;
import org.kohsuke.args4j.Argument;
class ShowPackDelta extends TextBuiltin {
@Argument(index = 0)
private ObjectId objectId;
@Override
protected void run() throws Exception {
ObjectReader reader = db.newObjectReader();
RevObject obj = new RevWalk(reader).parseAny(objectId);
byte[] delta = getDelta(reader, obj);
// We're crossing our fingers that this will be a delta. Double
// check the size field in the header, it should match.
//
long size = reader.getObjectSize(obj, obj.getType());
try {
if (BinaryDelta.getResultSize(delta) != size)
throw die("Object " + obj.name() + " is not a delta");
} catch (ArrayIndexOutOfBoundsException bad) {
throw die("Object " + obj.name() + " is not a delta");
}
out.println(BinaryDelta.format(delta));
}
private byte[] getDelta(ObjectReader reader, RevObject obj)
throws IOException, MissingObjectException,
StoredObjectRepresentationNotAvailableException {
ObjectReuseAsIs asis = (ObjectReuseAsIs) reader;
ObjectToPack target = asis.newObjectToPack(obj);
PackWriter pw = new PackWriter(reader) {
@Override
public void select(ObjectToPack otp, StoredObjectRepresentation next) {
otp.select(next);
}
};
ByteArrayOutputStream buf = new ByteArrayOutputStream();
asis.selectObjectRepresentation(pw, target);
asis.copyObjectAsIs(new PackOutputStream(NullProgressMonitor.INSTANCE,
buf, pw), target);
// At this point the object header has no delta information,
// because it was output as though it were a whole object.
// Skip over the header and inflate.
//
byte[] bufArray = buf.toByteArray();
int ptr = 0;
while ((bufArray[ptr] & 0x80) != 0)
ptr++;
ptr++;
TemporaryBuffer.Heap raw = new TemporaryBuffer.Heap(bufArray.length);
InflaterInputStream inf = new InflaterInputStream(
new ByteArrayInputStream(bufArray, ptr, bufArray.length));
raw.copy(inf);
inf.close();
return raw.toByteArray();
}
}

2
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/WriteDirCache.java

@ -51,7 +51,7 @@ import org.eclipse.jgit.pgm.TextBuiltin;
class WriteDirCache extends TextBuiltin {
@Override
protected void run() throws Exception {
final DirCache cache = DirCache.read(db);
final DirCache cache = db.readDirCache();
if (!cache.lock())
throw die(CLIText.get().failedToLockIndex);
cache.read();

2
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/eclipse/Iplog.java

@ -51,7 +51,6 @@ import java.text.MessageFormat;
import org.eclipse.jgit.iplog.IpLogGenerator;
import org.eclipse.jgit.iplog.SimpleCookieManager;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.LockFile;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.pgm.CLIText;
import org.eclipse.jgit.pgm.Command;
@ -59,6 +58,7 @@ import org.eclipse.jgit.pgm.TextBuiltin;
import org.eclipse.jgit.revwalk.RevObject;
import org.eclipse.jgit.revwalk.RevTag;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.storage.file.LockFile;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option;

2
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/eclipse/Ipzilla.java

@ -91,7 +91,7 @@ class Ipzilla extends TextBuiltin {
}
if (output == null)
output = new File(db.getWorkDir(), IpLogMeta.IPLOG_CONFIG_FILE);
output = new File(db.getWorkTree(), IpLogMeta.IPLOG_CONFIG_FILE);
IpLogMeta meta = new IpLogMeta();
meta.syncCQs(output, ipzilla, username, password);

6
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/AbstractTreeIteratorHandler.java

@ -59,7 +59,7 @@ import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.WindowCursor;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.pgm.CLIText;
import org.eclipse.jgit.treewalk.AbstractTreeIterator;
import org.eclipse.jgit.treewalk.CanonicalTreeParser;
@ -121,9 +121,9 @@ public class AbstractTreeIteratorHandler extends
throw new CmdLineException(MessageFormat.format(CLIText.get().notATree, name));
final CanonicalTreeParser p = new CanonicalTreeParser();
final WindowCursor curs = new WindowCursor();
final ObjectReader curs = clp.getRepository().newObjectReader();
try {
p.reset(clp.getRepository(), clp.getRevWalk().parseTree(id), curs);
p.reset(curs, clp.getRevWalk().parseTree(id));
} catch (MissingObjectException e) {
throw new CmdLineException(MessageFormat.format(CLIText.get().notATree, name));
} catch (IncorrectObjectTypeException e) {

2
org.eclipse.jgit.test/META-INF/MANIFEST.MF

@ -29,6 +29,8 @@ Import-Package: junit.framework;version="[3.8.2,4.0.0)",
org.eclipse.jgit.revplot;version="[0.9.0,0.10.0)",
org.eclipse.jgit.revwalk;version="[0.9.0,0.10.0)",
org.eclipse.jgit.revwalk.filter;version="[0.9.0,0.10.0)",
org.eclipse.jgit.storage.file;version="[0.9.0,0.10.0)",
org.eclipse.jgit.storage.pack;version="[0.9.0,0.10.0)",
org.eclipse.jgit.transport;version="[0.9.0,0.10.0)",
org.eclipse.jgit.treewalk;version="[0.9.0,0.10.0)",
org.eclipse.jgit.treewalk.filter;version="[0.9.0,0.10.0)",

2
org.eclipse.jgit.test/exttst/org/eclipse/jgit/lib/T0007_GitIndexTest.java

@ -116,7 +116,7 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase {
protected void setUp() throws Exception {
super.setUp();
db = createWorkRepository();
trash = db.getWorkDir();
trash = db.getWorkTree();
}
public void testCreateEmptyIndex() throws Exception {

44
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/AddCommandTest.java

@ -78,7 +78,7 @@ public class AddCommandTest extends RepositoryTestCase {
}
public void testAddExistingSingleFile() throws IOException, NoFilepatternException {
File file = new File(db.getWorkDir(), "a.txt");
File file = new File(db.getWorkTree(), "a.txt");
file.createNewFile();
PrintWriter writer = new PrintWriter(file);
writer.print("content");
@ -98,8 +98,8 @@ public class AddCommandTest extends RepositoryTestCase {
}
public void testAddExistingSingleFileInSubDir() throws IOException, NoFilepatternException {
new File(db.getWorkDir(), "sub").mkdir();
File file = new File(db.getWorkDir(), "sub/a.txt");
new File(db.getWorkTree(), "sub").mkdir();
File file = new File(db.getWorkTree(), "sub/a.txt");
file.createNewFile();
PrintWriter writer = new PrintWriter(file);
writer.print("content");
@ -119,7 +119,7 @@ public class AddCommandTest extends RepositoryTestCase {
}
public void testAddExistingSingleFileTwice() throws IOException, NoFilepatternException {
File file = new File(db.getWorkDir(), "a.txt");
File file = new File(db.getWorkTree(), "a.txt");
file.createNewFile();
PrintWriter writer = new PrintWriter(file);
writer.print("content");
@ -143,7 +143,7 @@ public class AddCommandTest extends RepositoryTestCase {
}
public void testAddExistingSingleFileTwiceWithCommit() throws Exception {
File file = new File(db.getWorkDir(), "a.txt");
File file = new File(db.getWorkTree(), "a.txt");
file.createNewFile();
PrintWriter writer = new PrintWriter(file);
writer.print("content");
@ -169,7 +169,7 @@ public class AddCommandTest extends RepositoryTestCase {
}
public void testAddRemovedFile() throws Exception {
File file = new File(db.getWorkDir(), "a.txt");
File file = new File(db.getWorkTree(), "a.txt");
file.createNewFile();
PrintWriter writer = new PrintWriter(file);
writer.print("content");
@ -191,7 +191,7 @@ public class AddCommandTest extends RepositoryTestCase {
}
public void testAddRemovedCommittedFile() throws Exception {
File file = new File(db.getWorkDir(), "a.txt");
File file = new File(db.getWorkTree(), "a.txt");
file.createNewFile();
PrintWriter writer = new PrintWriter(file);
writer.print("content");
@ -217,20 +217,20 @@ public class AddCommandTest extends RepositoryTestCase {
public void testAddWithConflicts() throws Exception {
// prepare conflict
File file = new File(db.getWorkDir(), "a.txt");
File file = new File(db.getWorkTree(), "a.txt");
file.createNewFile();
PrintWriter writer = new PrintWriter(file);
writer.print("content");
writer.close();
File file2 = new File(db.getWorkDir(), "b.txt");
File file2 = new File(db.getWorkTree(), "b.txt");
file2.createNewFile();
writer = new PrintWriter(file2);
writer.print("content b");
writer.close();
ObjectWriter ow = new ObjectWriter(db);
DirCache dc = DirCache.lock(db);
DirCache dc = db.lockDirCache();
DirCacheBuilder builder = dc.builder();
addEntryToBuilder("b.txt", file2, ow, builder, 0);
@ -264,13 +264,13 @@ public class AddCommandTest extends RepositoryTestCase {
}
public void testAddTwoFiles() throws Exception {
File file = new File(db.getWorkDir(), "a.txt");
File file = new File(db.getWorkTree(), "a.txt");
file.createNewFile();
PrintWriter writer = new PrintWriter(file);
writer.print("content");
writer.close();
File file2 = new File(db.getWorkDir(), "b.txt");
File file2 = new File(db.getWorkTree(), "b.txt");
file2.createNewFile();
writer = new PrintWriter(file2);
writer.print("content b");
@ -287,14 +287,14 @@ public class AddCommandTest extends RepositoryTestCase {
}
public void testAddFolder() throws Exception {
new File(db.getWorkDir(), "sub").mkdir();
File file = new File(db.getWorkDir(), "sub/a.txt");
new File(db.getWorkTree(), "sub").mkdir();
File file = new File(db.getWorkTree(), "sub/a.txt");
file.createNewFile();
PrintWriter writer = new PrintWriter(file);
writer.print("content");
writer.close();
File file2 = new File(db.getWorkDir(), "sub/b.txt");
File file2 = new File(db.getWorkTree(), "sub/b.txt");
file2.createNewFile();
writer = new PrintWriter(file2);
writer.print("content b");
@ -311,20 +311,20 @@ public class AddCommandTest extends RepositoryTestCase {
}
public void testAddIgnoredFile() throws Exception {
new File(db.getWorkDir(), "sub").mkdir();
File file = new File(db.getWorkDir(), "sub/a.txt");
new File(db.getWorkTree(), "sub").mkdir();
File file = new File(db.getWorkTree(), "sub/a.txt");
file.createNewFile();
PrintWriter writer = new PrintWriter(file);
writer.print("content");
writer.close();
File ignoreFile = new File(db.getWorkDir(), ".gitignore");
File ignoreFile = new File(db.getWorkTree(), ".gitignore");
ignoreFile.createNewFile();
writer = new PrintWriter(ignoreFile);
writer.print("sub/b.txt");
writer.close();
File file2 = new File(db.getWorkDir(), "sub/b.txt");
File file2 = new File(db.getWorkTree(), "sub/b.txt");
file2.createNewFile();
writer = new PrintWriter(file2);
writer.print("content b");
@ -339,14 +339,14 @@ public class AddCommandTest extends RepositoryTestCase {
}
public void testAddWholeRepo() throws Exception {
new File(db.getWorkDir(), "sub").mkdir();
File file = new File(db.getWorkDir(), "sub/a.txt");
new File(db.getWorkTree(), "sub").mkdir();
File file = new File(db.getWorkTree(), "sub/a.txt");
file.createNewFile();
PrintWriter writer = new PrintWriter(file);
writer.print("content");
writer.close();
File file2 = new File(db.getWorkDir(), "sub/b.txt");
File file2 = new File(db.getWorkTree(), "sub/b.txt");
file2.createNewFile();
writer = new PrintWriter(file2);
writer.print("content b");

18
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java

@ -100,20 +100,20 @@ public class MergeCommandTest extends RepositoryTestCase {
addNewFileToIndex("file1");
RevCommit first = git.commit().setMessage("initial commit").call();
assertTrue(new File(db.getWorkDir(), "file1").exists());
assertTrue(new File(db.getWorkTree(), "file1").exists());
createBranch(first, "refs/heads/branch1");
addNewFileToIndex("file2");
RevCommit second = git.commit().setMessage("second commit").call();
assertTrue(new File(db.getWorkDir(), "file2").exists());
assertTrue(new File(db.getWorkTree(), "file2").exists());
checkoutBranch("refs/heads/branch1");
assertFalse(new File(db.getWorkDir(), "file2").exists());
assertFalse(new File(db.getWorkTree(), "file2").exists());
MergeResult result = git.merge().include(db.getRef(Constants.MASTER)).call();
assertTrue(new File(db.getWorkDir(), "file1").exists());
assertTrue(new File(db.getWorkDir(), "file2").exists());
assertTrue(new File(db.getWorkTree(), "file1").exists());
assertTrue(new File(db.getWorkTree(), "file2").exists());
assertEquals(MergeResult.MergeStatus.FAST_FORWARD, result.getMergeStatus());
assertEquals(second, result.getNewHead());
}
@ -132,8 +132,8 @@ public class MergeCommandTest extends RepositoryTestCase {
git.commit().setMessage("third commit").call();
checkoutBranch("refs/heads/branch1");
assertFalse(new File(db.getWorkDir(), "file2").exists());
assertFalse(new File(db.getWorkDir(), "file3").exists());
assertFalse(new File(db.getWorkTree(), "file2").exists());
assertFalse(new File(db.getWorkTree(), "file3").exists());
MergeCommand merge = git.merge();
merge.include(second.getId());
@ -152,7 +152,7 @@ public class MergeCommandTest extends RepositoryTestCase {
}
private void checkoutBranch(String branchName) throws Exception {
File workDir = db.getWorkDir();
File workDir = db.getWorkTree();
if (workDir != null) {
WorkDirCheckout workDirCheckout = new WorkDirCheckout(db,
workDir, db.mapCommit(Constants.HEAD).getTree(),
@ -176,7 +176,7 @@ public class MergeCommandTest extends RepositoryTestCase {
File writeTrashFile = writeTrashFile(filename, filename);
GitIndex index = db.getIndex();
Entry entry = index.add(db.getWorkDir(), writeTrashFile);
Entry entry = index.add(db.getWorkTree(), writeTrashFile);
entry.update(writeTrashFile);
index.write();
}

16
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java

@ -43,12 +43,15 @@
package org.eclipse.jgit.diff;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import junit.framework.TestCase;
import org.eclipse.jgit.lib.Constants;
public class SimilarityIndexTest extends TestCase {
public void testIndexing() {
public void testIndexingSmallObject() {
SimilarityIndex si = hash("" //
+ "A\n" //
+ "B\n" //
@ -67,6 +70,17 @@ public class SimilarityIndexTest extends TestCase {
assertEquals(2, si.count(si.findIndex(key_D)));
}
public void testIndexingLargeObject() throws IOException {
byte[] in = ("" //
+ "A\n" //
+ "B\n" //
+ "B\n" //
+ "B\n").getBytes("UTF-8");
SimilarityIndex si = new SimilarityIndex();
si.hash(new ByteArrayInputStream(in), in.length);
assertEquals(2, si.size());
}
public void testCommonScore_SameFiles() {
String text = "" //
+ "A\n" //

20
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java vendored

@ -54,7 +54,7 @@ public class DirCacheBasicTest extends RepositoryTestCase {
final File idx = new File(db.getDirectory(), "index");
assertFalse(idx.exists());
final DirCache dc = DirCache.read(db);
final DirCache dc = db.readDirCache();
assertNotNull(dc);
assertEquals(0, dc.getEntryCount());
}
@ -74,7 +74,7 @@ public class DirCacheBasicTest extends RepositoryTestCase {
assertFalse(idx.exists());
assertFalse(lck.exists());
final DirCache dc = DirCache.lock(db);
final DirCache dc = db.lockDirCache();
assertNotNull(dc);
assertFalse(idx.exists());
assertTrue(lck.exists());
@ -108,7 +108,7 @@ public class DirCacheBasicTest extends RepositoryTestCase {
assertFalse(idx.exists());
assertFalse(lck.exists());
final DirCache dc = DirCache.lock(db);
final DirCache dc = db.lockDirCache();
assertEquals(0, lck.length());
dc.write();
assertEquals(12 + 20, lck.length());
@ -124,7 +124,7 @@ public class DirCacheBasicTest extends RepositoryTestCase {
assertFalse(idx.exists());
assertFalse(lck.exists());
final DirCache dc = DirCache.lock(db);
final DirCache dc = db.lockDirCache();
assertEquals(0, lck.length());
dc.write();
assertEquals(12 + 20, lck.length());
@ -141,13 +141,13 @@ public class DirCacheBasicTest extends RepositoryTestCase {
assertFalse(idx.exists());
assertFalse(lck.exists());
{
final DirCache dc = DirCache.lock(db);
final DirCache dc = db.lockDirCache();
dc.write();
assertTrue(dc.commit());
assertTrue(idx.exists());
}
{
final DirCache dc = DirCache.read(db);
final DirCache dc = db.readDirCache();
assertEquals(0, dc.getEntryCount());
}
}
@ -158,13 +158,13 @@ public class DirCacheBasicTest extends RepositoryTestCase {
assertFalse(idx.exists());
assertFalse(lck.exists());
{
final DirCache dc = DirCache.lock(db);
final DirCache dc = db.lockDirCache();
dc.write();
assertTrue(dc.commit());
assertTrue(idx.exists());
}
{
final DirCache dc = DirCache.lock(db);
final DirCache dc = db.lockDirCache();
assertEquals(0, dc.getEntryCount());
assertTrue(idx.exists());
assertTrue(lck.exists());
@ -173,7 +173,7 @@ public class DirCacheBasicTest extends RepositoryTestCase {
}
public void testBuildThenClear() throws Exception {
final DirCache dc = DirCache.read(db);
final DirCache dc = db.readDirCache();
final String[] paths = { "a.", "a.b", "a/b", "a0b" };
final DirCacheEntry[] ents = new DirCacheEntry[paths.length];
@ -195,7 +195,7 @@ public class DirCacheBasicTest extends RepositoryTestCase {
}
public void testDetectUnmergedPaths() throws Exception {
final DirCache dc = DirCache.read(db);
final DirCache dc = db.readDirCache();
final DirCacheEntry[] ents = new DirCacheEntry[3];
ents[0] = new DirCacheEntry("a", 1);

2
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java vendored

@ -52,7 +52,7 @@ import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
public class DirCacheBuilderIteratorTest extends RepositoryTestCase {
public void testPathFilterGroup_DoesNotSkipTail() throws Exception {
final DirCache dc = DirCache.read(db);
final DirCache dc = db.readDirCache();
final FileMode mode = FileMode.REGULAR_FILE;
final String[] paths = { "a.", "a/b", "a/c", "a/d", "a0b" };

20
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderTest.java vendored

@ -52,7 +52,7 @@ import org.eclipse.jgit.lib.RepositoryTestCase;
public class DirCacheBuilderTest extends RepositoryTestCase {
public void testBuildEmpty() throws Exception {
{
final DirCache dc = DirCache.lock(db);
final DirCache dc = db.lockDirCache();
final DirCacheBuilder b = dc.builder();
assertNotNull(b);
b.finish();
@ -60,7 +60,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
assertTrue(dc.commit());
}
{
final DirCache dc = DirCache.read(db);
final DirCache dc = db.readDirCache();
assertEquals(0, dc.getEntryCount());
}
}
@ -86,7 +86,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
final int length = 1342;
final DirCacheEntry entOrig;
{
final DirCache dc = DirCache.lock(db);
final DirCache dc = db.lockDirCache();
final DirCacheBuilder b = dc.builder();
assertNotNull(b);
@ -113,7 +113,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
assertTrue(dc.commit());
}
{
final DirCache dc = DirCache.read(db);
final DirCache dc = db.readDirCache();
assertEquals(1, dc.getEntryCount());
final DirCacheEntry entRead = dc.getEntry(0);
@ -135,7 +135,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
final int length = 1342;
final DirCacheEntry entOrig;
{
final DirCache dc = DirCache.lock(db);
final DirCache dc = db.lockDirCache();
final DirCacheBuilder b = dc.builder();
assertNotNull(b);
@ -160,7 +160,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
assertFalse(new File(db.getDirectory(), "index.lock").exists());
}
{
final DirCache dc = DirCache.read(db);
final DirCache dc = db.readDirCache();
assertEquals(1, dc.getEntryCount());
final DirCacheEntry entRead = dc.getEntry(0);
@ -177,7 +177,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
public void testFindSingleFile() throws Exception {
final String path = "a-file-path";
final DirCache dc = DirCache.read(db);
final DirCache dc = db.readDirCache();
final DirCacheBuilder b = dc.builder();
assertNotNull(b);
@ -202,7 +202,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
}
public void testAdd_InGitSortOrder() throws Exception {
final DirCache dc = DirCache.read(db);
final DirCache dc = db.readDirCache();
final String[] paths = { "a.", "a.b", "a/b", "a0b" };
final DirCacheEntry[] ents = new DirCacheEntry[paths.length];
@ -226,7 +226,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
}
public void testAdd_ReverseGitSortOrder() throws Exception {
final DirCache dc = DirCache.read(db);
final DirCache dc = db.readDirCache();
final String[] paths = { "a.", "a.b", "a/b", "a0b" };
final DirCacheEntry[] ents = new DirCacheEntry[paths.length];
@ -250,7 +250,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
}
public void testBuilderClear() throws Exception {
final DirCache dc = DirCache.read(db);
final DirCache dc = db.readDirCache();
final String[] paths = { "a.", "a.b", "a/b", "a0b" };
final DirCacheEntry[] ents = new DirCacheEntry[paths.length];

2
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheFindTest.java vendored

@ -48,7 +48,7 @@ import org.eclipse.jgit.lib.RepositoryTestCase;
public class DirCacheFindTest extends RepositoryTestCase {
public void testEntriesWithin() throws Exception {
final DirCache dc = DirCache.read(db);
final DirCache dc = db.readDirCache();
final String[] paths = { "a.", "a/b", "a/c", "a/d", "a0b" };
final DirCacheEntry[] ents = new DirCacheEntry[paths.length];

16
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java vendored

@ -52,7 +52,7 @@ import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
public class DirCacheIteratorTest extends RepositoryTestCase {
public void testEmptyTree_NoTreeWalk() throws Exception {
final DirCache dc = DirCache.read(db);
final DirCache dc = db.readDirCache();
assertEquals(0, dc.getEntryCount());
final DirCacheIterator i = new DirCacheIterator(dc);
@ -60,7 +60,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
}
public void testEmptyTree_WithTreeWalk() throws Exception {
final DirCache dc = DirCache.read(db);
final DirCache dc = db.readDirCache();
assertEquals(0, dc.getEntryCount());
final TreeWalk tw = new TreeWalk(db);
@ -70,7 +70,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
}
public void testNoSubtree_NoTreeWalk() throws Exception {
final DirCache dc = DirCache.read(db);
final DirCache dc = db.readDirCache();
final String[] paths = { "a.", "a0b" };
final DirCacheEntry[] ents = new DirCacheEntry[paths.length];
@ -95,7 +95,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
}
public void testNoSubtree_WithTreeWalk() throws Exception {
final DirCache dc = DirCache.read(db);
final DirCache dc = db.readDirCache();
final String[] paths = { "a.", "a0b" };
final FileMode[] modes = { FileMode.EXECUTABLE_FILE, FileMode.GITLINK };
@ -128,7 +128,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
}
public void testSingleSubtree_NoRecursion() throws Exception {
final DirCache dc = DirCache.read(db);
final DirCache dc = db.readDirCache();
final String[] paths = { "a.", "a/b", "a/c", "a/d", "a0b" };
final DirCacheEntry[] ents = new DirCacheEntry[paths.length];
@ -172,7 +172,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
}
public void testSingleSubtree_Recursive() throws Exception {
final DirCache dc = DirCache.read(db);
final DirCache dc = db.readDirCache();
final FileMode mode = FileMode.REGULAR_FILE;
final String[] paths = { "a.", "a/b", "a/c", "a/d", "a0b" };
@ -207,7 +207,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
}
public void testTwoLevelSubtree_Recursive() throws Exception {
final DirCache dc = DirCache.read(db);
final DirCache dc = db.readDirCache();
final FileMode mode = FileMode.REGULAR_FILE;
final String[] paths = { "a.", "a/b", "a/c/e", "a/c/f", "a/d", "a0b" };
@ -241,7 +241,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
}
public void testTwoLevelSubtree_FilterPath() throws Exception {
final DirCache dc = DirCache.read(db);
final DirCache dc = db.readDirCache();
final FileMode mode = FileMode.REGULAR_FILE;
final String[] paths = { "a.", "a/b", "a/c/e", "a/c/f", "a/d", "a0b" };

4
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheLargePathTest.java vendored

@ -85,7 +85,7 @@ public class DirCacheLargePathTest extends RepositoryTestCase {
assertEquals(shortPath, shortEnt.getPathString());
{
final DirCache dc1 = DirCache.lock(db);
final DirCache dc1 = db.lockDirCache();
{
final DirCacheBuilder b = dc1.builder();
b.add(longEnt);
@ -97,7 +97,7 @@ public class DirCacheLargePathTest extends RepositoryTestCase {
assertSame(shortEnt, dc1.getEntry(1));
}
{
final DirCache dc2 = DirCache.read(db);
final DirCache dc2 = db.readDirCache();
assertEquals(2, dc2.getEntryCount());
assertNotSame(longEnt, dc2.getEntry(0));

14
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheTreeTest.java vendored

@ -51,12 +51,12 @@ import org.eclipse.jgit.lib.RepositoryTestCase;
public class DirCacheTreeTest extends RepositoryTestCase {
public void testEmptyCache_NoCacheTree() throws Exception {
final DirCache dc = DirCache.read(db);
final DirCache dc = db.readDirCache();
assertNull(dc.getCacheTree(false));
}
public void testEmptyCache_CreateEmptyCacheTree() throws Exception {
final DirCache dc = DirCache.read(db);
final DirCache dc = db.readDirCache();
final DirCacheTree tree = dc.getCacheTree(true);
assertNotNull(tree);
assertSame(tree, dc.getCacheTree(false));
@ -69,7 +69,7 @@ public class DirCacheTreeTest extends RepositoryTestCase {
}
public void testEmptyCache_Clear_NoCacheTree() throws Exception {
final DirCache dc = DirCache.read(db);
final DirCache dc = db.readDirCache();
final DirCacheTree tree = dc.getCacheTree(true);
assertNotNull(tree);
dc.clear();
@ -78,7 +78,7 @@ public class DirCacheTreeTest extends RepositoryTestCase {
}
public void testSingleSubtree() throws Exception {
final DirCache dc = DirCache.read(db);
final DirCache dc = db.readDirCache();
final String[] paths = { "a.", "a/b", "a/c", "a/d", "a0b" };
final DirCacheEntry[] ents = new DirCacheEntry[paths.length];
@ -115,7 +115,7 @@ public class DirCacheTreeTest extends RepositoryTestCase {
}
public void testTwoLevelSubtree() throws Exception {
final DirCache dc = DirCache.read(db);
final DirCache dc = db.readDirCache();
final String[] paths = { "a.", "a/b", "a/c/e", "a/c/f", "a/d", "a0b" };
final DirCacheEntry[] ents = new DirCacheEntry[paths.length];
@ -172,7 +172,7 @@ public class DirCacheTreeTest extends RepositoryTestCase {
* @throws IOException
*/
public void testWriteReadTree() throws CorruptObjectException, IOException {
final DirCache dc = DirCache.lock(db);
final DirCache dc = db.lockDirCache();
final String A = String.format("a%2000s", "a");
final String B = String.format("b%2000s", "b");
@ -188,7 +188,7 @@ public class DirCacheTreeTest extends RepositoryTestCase {
b.add(ents[i]);
b.commit();
DirCache read = DirCache.read(db);
DirCache read = db.readDirCache();
assertEquals(paths.length, read.getEntryCount());
assertEquals(1, read.getCacheTree(true).getChildCount());

18
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReadTreeTest.java

@ -45,11 +45,9 @@
*/
package org.eclipse.jgit.lib;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@ -131,13 +129,15 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
}
ObjectId genSha1(String data) {
InputStream is = new ByteArrayInputStream(data.getBytes());
ObjectWriter objectWriter = new ObjectWriter(db);
ObjectInserter w = db.newObjectInserter();
try {
return objectWriter.writeObject(Constants.OBJ_BLOB, data
.getBytes().length, is, true);
ObjectId id = w.insert(Constants.OBJ_BLOB, data.getBytes());
w.flush();
return id;
} catch (IOException e) {
fail(e.toString());
} finally {
w.release();
}
return null;
}
@ -623,7 +623,7 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
expectedValue = i.get(path);
assertNotNull("found unexpected file for path "
+ path + " in workdir", expectedValue);
File file = new File(db.getWorkDir(), path);
File file = new File(db.getWorkTree(), path);
assertTrue(file.exists());
if (file.isFile()) {
FileInputStream is = new FileInputStream(file);
@ -661,8 +661,8 @@ public abstract class ReadTreeTest extends RepositoryTestCase {
assertTrue("unexpected content for path " + path
+ " in index. Expected: <" + expectedValue + ">",
Arrays.equals(
db.openBlob(theIndex.getMembers()[j].getObjectId())
.getBytes(), i.get(path).getBytes()));
db.open(theIndex.getMembers()[j].getObjectId())
.getCachedBytes(), i.get(path).getBytes()));
}
}

4
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java

@ -70,7 +70,7 @@ public class ReflogConfigTest extends RepositoryTestCase {
// set the logAllRefUpdates parameter to true and check it
db.getConfig().setBoolean("core", null, "logallrefupdates", true);
assertTrue(db.getConfig().getCore().isLogAllRefUpdates());
assertTrue(db.getConfig().get(CoreConfig.KEY).isLogAllRefUpdates());
// do one commit and check that reflog size is increased to 1
addFileToTree(t, "i-am-another-file", "and this is other data in me\n");
@ -83,7 +83,7 @@ public class ReflogConfigTest extends RepositoryTestCase {
// set the logAllRefUpdates parameter to false and check it
db.getConfig().setBoolean("core", null, "logallrefupdates", false);
assertFalse(db.getConfig().getCore().isLogAllRefUpdates());
assertFalse(db.getConfig().get(CoreConfig.KEY).isLogAllRefUpdates());
// do one commit and check that reflog size is 2
addFileToTree(t, "i-am-anotheranother-file",

7
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java

@ -54,6 +54,7 @@ import java.io.InputStreamReader;
import java.io.Reader;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.storage.file.FileRepository;
/**
* Base class for most JGit unit tests.
@ -83,7 +84,7 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
protected File writeTrashFile(final String name, final String data)
throws IOException {
File path = new File(db.getWorkDir(), name);
File path = new File(db.getWorkTree(), name);
write(path, data);
return path;
}
@ -102,7 +103,7 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
}
/** Test repository, initialized for this test case. */
protected Repository db;
protected FileRepository db;
/** Working directory of {@link #db}. */
protected File trash;
@ -111,6 +112,6 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
protected void setUp() throws Exception {
super.setUp();
db = createWorkRepository();
trash = db.getWorkDir();
trash = db.getWorkTree();
}
}

2
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SampleDataRepositoryTestCase.java

@ -65,7 +65,7 @@ public abstract class SampleDataRepositoryTestCase extends RepositoryTestCase {
"pack-e6d07037cbcf13376308a0a995d1fa48f8f76aaa",
"pack-3280af9c07ee18a87705ef50b0cc4cd20266cf12"
};
final File packDir = new File(db.getObjectsDirectory(), "pack");
final File packDir = new File(db.getObjectDatabase().getDirectory(), "pack");
for (String n : packs) {
copyFile(JGitTestUtil.getTestResourceFile(n + ".pack"), new File(packDir, n + ".pack"));
copyFile(JGitTestUtil.getTestResourceFile(n + ".idx"), new File(packDir, n + ".idx"));

4
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/WorkDirCheckout_ReadTreeTest.java

@ -52,12 +52,12 @@ import java.util.HashMap;
public class WorkDirCheckout_ReadTreeTest extends ReadTreeTest {
private WorkDirCheckout wdc;
public void prescanTwoTrees(Tree head, Tree merge) throws IllegalStateException, IOException {
wdc = new WorkDirCheckout(db, db.getWorkDir(), head, db.getIndex(), merge);
wdc = new WorkDirCheckout(db, db.getWorkTree(), head, db.getIndex(), merge);
wdc.prescanTwoTrees();
}
public void checkout() throws IOException {
wdc = new WorkDirCheckout(db, db.getWorkDir(), theHead, db.getIndex(), theMerge);
wdc = new WorkDirCheckout(db, db.getWorkTree(), theHead, db.getIndex(), theMerge);
wdc.checkout();
}

28
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java

@ -44,7 +44,8 @@
package org.eclipse.jgit.merge;
import java.io.ByteArrayInputStream;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
import static org.eclipse.jgit.lib.Constants.OBJ_COMMIT;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheBuilder;
@ -53,7 +54,7 @@ import org.eclipse.jgit.lib.Commit;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectWriter;
import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.treewalk.TreeWalk;
@ -66,10 +67,10 @@ public class CherryPickTest extends RepositoryTestCase {
// Cherry-pick "T" onto "O". This shouldn't introduce "p-fail", which
// was created by "P", nor should it modify "a", which was done by "P".
//
final DirCache treeB = DirCache.read(db);
final DirCache treeO = DirCache.read(db);
final DirCache treeP = DirCache.read(db);
final DirCache treeT = DirCache.read(db);
final DirCache treeB = db.readDirCache();
final DirCache treeO = db.readDirCache();
final DirCache treeP = db.readDirCache();
final DirCache treeT = db.readDirCache();
{
final DirCacheBuilder b = treeB.builder();
final DirCacheBuilder o = treeO.builder();
@ -93,7 +94,7 @@ public class CherryPickTest extends RepositoryTestCase {
t.finish();
}
final ObjectWriter ow = new ObjectWriter(db);
final ObjectInserter ow = db.newObjectInserter();
final ObjectId B = commit(ow, treeB, new ObjectId[] {});
final ObjectId O = commit(ow, treeO, new ObjectId[] { B });
final ObjectId P = commit(ow, treeP, new ObjectId[] { B });
@ -128,15 +129,17 @@ public class CherryPickTest extends RepositoryTestCase {
.getObjectId(0));
}
private ObjectId commit(final ObjectWriter ow, final DirCache treeB,
private ObjectId commit(final ObjectInserter odi, final DirCache treeB,
final ObjectId[] parentIds) throws Exception {
final Commit c = new Commit(db);
c.setTreeId(treeB.writeTree(ow));
c.setTreeId(treeB.writeTree(odi));
c.setAuthor(new PersonIdent("A U Thor", "a.u.thor", 1L, 0));
c.setCommitter(c.getAuthor());
c.setParentIds(parentIds);
c.setMessage("Tree " + c.getTreeId().name());
return ow.writeCommit(c);
ObjectId id = odi.insert(OBJ_COMMIT, odi.format(c));
odi.flush();
return id;
}
private DirCacheEntry makeEntry(final String path, final FileMode mode)
@ -148,9 +151,8 @@ public class CherryPickTest extends RepositoryTestCase {
final String content) throws Exception {
final DirCacheEntry ent = new DirCacheEntry(path);
ent.setFileMode(mode);
final byte[] contentBytes = Constants.encode(content);
ent.setObjectId(new ObjectWriter(db).computeBlobSha1(
contentBytes.length, new ByteArrayInputStream(contentBytes)));
ent.setObjectId(new ObjectInserter.Formatter().idFor(OBJ_BLOB,
Constants.encode(content)));
return ent;
}
}

75
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java

@ -44,7 +44,9 @@
package org.eclipse.jgit.merge;
import java.io.ByteArrayInputStream;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
import static org.eclipse.jgit.lib.Constants.OBJ_COMMIT;
import java.io.IOException;
import org.eclipse.jgit.dircache.DirCache;
@ -54,7 +56,7 @@ import org.eclipse.jgit.lib.Commit;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectWriter;
import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.SampleDataRepositoryTestCase;
import org.eclipse.jgit.treewalk.TreeWalk;
@ -103,9 +105,9 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
}
public void testTrivialTwoWay_validSubtreeSort() throws Exception {
final DirCache treeB = DirCache.read(db);
final DirCache treeO = DirCache.read(db);
final DirCache treeT = DirCache.read(db);
final DirCache treeB = db.readDirCache();
final DirCache treeO = db.readDirCache();
final DirCache treeT = db.readDirCache();
{
final DirCacheBuilder b = treeB.builder();
final DirCacheBuilder o = treeO.builder();
@ -126,7 +128,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
t.finish();
}
final ObjectWriter ow = new ObjectWriter(db);
final ObjectInserter ow = db.newObjectInserter();
final ObjectId b = commit(ow, treeB, new ObjectId[] {});
final ObjectId o = commit(ow, treeO, new ObjectId[] { b });
final ObjectId t = commit(ow, treeT, new ObjectId[] { b });
@ -155,9 +157,9 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
}
public void testTrivialTwoWay_concurrentSubtreeChange() throws Exception {
final DirCache treeB = DirCache.read(db);
final DirCache treeO = DirCache.read(db);
final DirCache treeT = DirCache.read(db);
final DirCache treeB = db.readDirCache();
final DirCache treeO = db.readDirCache();
final DirCache treeT = db.readDirCache();
{
final DirCacheBuilder b = treeB.builder();
final DirCacheBuilder o = treeO.builder();
@ -177,7 +179,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
t.finish();
}
final ObjectWriter ow = new ObjectWriter(db);
final ObjectInserter ow = db.newObjectInserter();
final ObjectId b = commit(ow, treeB, new ObjectId[] {});
final ObjectId o = commit(ow, treeO, new ObjectId[] { b });
final ObjectId t = commit(ow, treeT, new ObjectId[] { b });
@ -202,9 +204,9 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
}
public void testTrivialTwoWay_conflictSubtreeChange() throws Exception {
final DirCache treeB = DirCache.read(db);
final DirCache treeO = DirCache.read(db);
final DirCache treeT = DirCache.read(db);
final DirCache treeB = db.readDirCache();
final DirCache treeO = db.readDirCache();
final DirCache treeT = db.readDirCache();
{
final DirCacheBuilder b = treeB.builder();
final DirCacheBuilder o = treeO.builder();
@ -224,7 +226,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
t.finish();
}
final ObjectWriter ow = new ObjectWriter(db);
final ObjectInserter ow = db.newObjectInserter();
final ObjectId b = commit(ow, treeB, new ObjectId[] {});
final ObjectId o = commit(ow, treeO, new ObjectId[] { b });
final ObjectId t = commit(ow, treeT, new ObjectId[] { b });
@ -235,9 +237,9 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
}
public void testTrivialTwoWay_leftDFconflict1() throws Exception {
final DirCache treeB = DirCache.read(db);
final DirCache treeO = DirCache.read(db);
final DirCache treeT = DirCache.read(db);
final DirCache treeB = db.readDirCache();
final DirCache treeO = db.readDirCache();
final DirCache treeT = db.readDirCache();
{
final DirCacheBuilder b = treeB.builder();
final DirCacheBuilder o = treeO.builder();
@ -256,7 +258,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
t.finish();
}
final ObjectWriter ow = new ObjectWriter(db);
final ObjectInserter ow = db.newObjectInserter();
final ObjectId b = commit(ow, treeB, new ObjectId[] {});
final ObjectId o = commit(ow, treeO, new ObjectId[] { b });
final ObjectId t = commit(ow, treeT, new ObjectId[] { b });
@ -267,9 +269,9 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
}
public void testTrivialTwoWay_rightDFconflict1() throws Exception {
final DirCache treeB = DirCache.read(db);
final DirCache treeO = DirCache.read(db);
final DirCache treeT = DirCache.read(db);
final DirCache treeB = db.readDirCache();
final DirCache treeO = db.readDirCache();
final DirCache treeT = db.readDirCache();
{
final DirCacheBuilder b = treeB.builder();
final DirCacheBuilder o = treeO.builder();
@ -288,7 +290,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
t.finish();
}
final ObjectWriter ow = new ObjectWriter(db);
final ObjectInserter ow = db.newObjectInserter();
final ObjectId b = commit(ow, treeB, new ObjectId[] {});
final ObjectId o = commit(ow, treeO, new ObjectId[] { b });
final ObjectId t = commit(ow, treeT, new ObjectId[] { b });
@ -299,9 +301,9 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
}
public void testTrivialTwoWay_leftDFconflict2() throws Exception {
final DirCache treeB = DirCache.read(db);
final DirCache treeO = DirCache.read(db);
final DirCache treeT = DirCache.read(db);
final DirCache treeB = db.readDirCache();
final DirCache treeO = db.readDirCache();
final DirCache treeT = db.readDirCache();
{
final DirCacheBuilder b = treeB.builder();
final DirCacheBuilder o = treeO.builder();
@ -318,7 +320,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
t.finish();
}
final ObjectWriter ow = new ObjectWriter(db);
final ObjectInserter ow = db.newObjectInserter();
final ObjectId b = commit(ow, treeB, new ObjectId[] {});
final ObjectId o = commit(ow, treeO, new ObjectId[] { b });
final ObjectId t = commit(ow, treeT, new ObjectId[] { b });
@ -329,9 +331,9 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
}
public void testTrivialTwoWay_rightDFconflict2() throws Exception {
final DirCache treeB = DirCache.read(db);
final DirCache treeO = DirCache.read(db);
final DirCache treeT = DirCache.read(db);
final DirCache treeB = db.readDirCache();
final DirCache treeO = db.readDirCache();
final DirCache treeT = db.readDirCache();
{
final DirCacheBuilder b = treeB.builder();
final DirCacheBuilder o = treeO.builder();
@ -348,7 +350,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
t.finish();
}
final ObjectWriter ow = new ObjectWriter(db);
final ObjectInserter ow = db.newObjectInserter();
final ObjectId b = commit(ow, treeB, new ObjectId[] {});
final ObjectId o = commit(ow, treeO, new ObjectId[] { b });
final ObjectId t = commit(ow, treeT, new ObjectId[] { b });
@ -363,15 +365,17 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
.getObjectId(0));
}
private ObjectId commit(final ObjectWriter ow, final DirCache treeB,
private ObjectId commit(final ObjectInserter odi, final DirCache treeB,
final ObjectId[] parentIds) throws Exception {
final Commit c = new Commit(db);
c.setTreeId(treeB.writeTree(ow));
c.setTreeId(treeB.writeTree(odi));
c.setAuthor(new PersonIdent("A U Thor", "a.u.thor", 1L, 0));
c.setCommitter(c.getAuthor());
c.setParentIds(parentIds);
c.setMessage("Tree " + c.getTreeId().name());
return ow.writeCommit(c);
ObjectId id = odi.insert(OBJ_COMMIT, odi.format(c));
odi.flush();
return id;
}
private DirCacheEntry makeEntry(final String path, final FileMode mode)
@ -383,9 +387,8 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
final String content) throws Exception {
final DirCacheEntry ent = new DirCacheEntry(path);
ent.setFileMode(mode);
final byte[] contentBytes = Constants.encode(content);
ent.setObjectId(new ObjectWriter(db).computeBlobSha1(
contentBytes.length, new ByteArrayInputStream(contentBytes)));
ent.setObjectId(new ObjectInserter.Formatter().idFor(OBJ_BLOB,
Constants.encode(content)));
return ent;
}
}

5
org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java

@ -47,18 +47,19 @@ import java.util.Date;
import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryTestCase;
/** Support for tests of the {@link RevWalk} class. */
public abstract class RevWalkTestCase extends RepositoryTestCase {
private TestRepository util;
private TestRepository<Repository> util;
protected RevWalk rw;
@Override
public void setUp() throws Exception {
super.setUp();
util = new TestRepository(db, createRevWalk());
util = new TestRepository<Repository>(db, createRevWalk());
rw = util.getRevWalk();
}

26
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConcurrentRepackTest.java → org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ConcurrentRepackTest.java

@ -42,7 +42,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.eclipse.jgit.lib;
package org.eclipse.jgit.storage.file;
import java.io.BufferedOutputStream;
import java.io.File;
@ -53,8 +53,17 @@ import java.util.Arrays;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.ObjectWriter;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.revwalk.RevObject;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.storage.pack.PackWriter;
public class ConcurrentRepackTest extends RepositoryTestCase {
public void setUp() throws Exception {
@ -125,10 +134,11 @@ public class ConcurrentRepackTest extends RepositoryTestCase {
// within the pack has been modified.
//
final RevObject o2 = writeBlob(eden, "o2");
final PackWriter pw = new PackWriter(eden, NullProgressMonitor.INSTANCE);
final PackWriter pw = new PackWriter(eden);
pw.addObject(o2);
pw.addObject(o1);
write(out1, pw);
pw.release();
// Try the old name, then the new name. The old name should cause the
// pack to reload when it opens and the index and pack mismatch.
@ -148,7 +158,7 @@ public class ConcurrentRepackTest extends RepositoryTestCase {
final File[] out1 = pack(eden, o1);
assertEquals(o1.name(), parse(o1).name());
final ObjectLoader load1 = db.openBlob(o1);
final ObjectLoader load1 = db.open(o1, Constants.OBJ_BLOB);
assertNotNull(load1);
final RevObject o2 = writeBlob(eden, "o2");
@ -163,7 +173,7 @@ public class ConcurrentRepackTest extends RepositoryTestCase {
// earlier still resolve the object, even though its underlying
// pack is gone, but the object still exists.
//
final ObjectLoader load2 = db.openBlob(o1);
final ObjectLoader load2 = db.open(o1, Constants.OBJ_BLOB);
assertNotNull(load2);
assertNotSame(load1, load2);
@ -189,7 +199,7 @@ public class ConcurrentRepackTest extends RepositoryTestCase {
private File[] pack(final Repository src, final RevObject... list)
throws IOException {
final PackWriter pw = new PackWriter(src, NullProgressMonitor.INSTANCE);
final PackWriter pw = new PackWriter(src);
for (final RevObject o : list) {
pw.addObject(o);
}
@ -199,17 +209,19 @@ public class ConcurrentRepackTest extends RepositoryTestCase {
final File idxFile = fullPackFileName(name, ".idx");
final File[] files = new File[] { packFile, idxFile };
write(files, pw);
pw.release();
return files;
}
private static void write(final File[] files, final PackWriter pw)
throws IOException {
final long begin = files[0].getParentFile().lastModified();
NullProgressMonitor m = NullProgressMonitor.INSTANCE;
OutputStream out;
out = new BufferedOutputStream(new FileOutputStream(files[0]));
try {
pw.writePack(out);
pw.writePack(m, m, out);
} finally {
out.close();
}
@ -245,7 +257,7 @@ public class ConcurrentRepackTest extends RepositoryTestCase {
}
private File fullPackFileName(final ObjectId name, final String suffix) {
final File packdir = new File(db.getObjectsDirectory(), "pack");
final File packdir = new File(db.getObjectDatabase().getDirectory(), "pack");
return new File(packdir, "pack-" + name.name() + suffix);
}

387
org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackFileTest.java

@ -0,0 +1,387 @@
/*
* Copyright (C) 2010, 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.file;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.security.MessageDigest;
import java.util.Arrays;
import java.util.zip.Deflater;
import org.eclipse.jgit.errors.LargeObjectException;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.junit.TestRng;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.ObjectStream;
import org.eclipse.jgit.revwalk.RevBlob;
import org.eclipse.jgit.storage.pack.DeltaEncoder;
import org.eclipse.jgit.transport.IndexPack;
import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.NB;
import org.eclipse.jgit.util.TemporaryBuffer;
public class PackFileTest extends LocalDiskRepositoryTestCase {
private TestRng rng;
private FileRepository repo;
private TestRepository<FileRepository> tr;
private WindowCursor wc;
protected void setUp() throws Exception {
super.setUp();
rng = new TestRng(getName());
repo = createBareRepository();
tr = new TestRepository<FileRepository>(repo);
wc = (WindowCursor) repo.newObjectReader();
}
protected void tearDown() throws Exception {
if (wc != null)
wc.release();
super.tearDown();
}
public void testWhole_SmallObject() throws Exception {
final int type = Constants.OBJ_BLOB;
byte[] data = rng.nextBytes(300);
RevBlob id = tr.blob(data);
tr.branch("master").commit().add("A", id).create();
tr.packAndPrune();
assertTrue("has blob", wc.has(id));
ObjectLoader ol = wc.open(id);
assertNotNull("created loader", ol);
assertEquals(type, ol.getType());
assertEquals(data.length, ol.getSize());
assertFalse("is not large", ol.isLarge());
assertTrue("same content", Arrays.equals(data, ol.getCachedBytes()));
ObjectStream in = ol.openStream();
assertNotNull("have stream", in);
assertEquals(type, in.getType());
assertEquals(data.length, in.getSize());
byte[] data2 = new byte[data.length];
IO.readFully(in, data2, 0, data.length);
assertTrue("same content", Arrays.equals(data2, data));
assertEquals("stream at EOF", -1, in.read());
in.close();
}
public void testWhole_LargeObject() throws Exception {
final int type = Constants.OBJ_BLOB;
byte[] data = rng.nextBytes(ObjectLoader.STREAM_THRESHOLD + 5);
RevBlob id = tr.blob(data);
tr.branch("master").commit().add("A", id).create();
tr.packAndPrune();
assertTrue("has blob", wc.has(id));
ObjectLoader ol = wc.open(id);
assertNotNull("created loader", ol);
assertEquals(type, ol.getType());
assertEquals(data.length, ol.getSize());
assertTrue("is large", ol.isLarge());
try {
ol.getCachedBytes();
fail("Should have thrown LargeObjectException");
} catch (LargeObjectException tooBig) {
assertEquals(id.name(), tooBig.getMessage());
}
ObjectStream in = ol.openStream();
assertNotNull("have stream", in);
assertEquals(type, in.getType());
assertEquals(data.length, in.getSize());
byte[] data2 = new byte[data.length];
IO.readFully(in, data2, 0, data.length);
assertTrue("same content", Arrays.equals(data2, data));
assertEquals("stream at EOF", -1, in.read());
in.close();
}
public void testDelta_SmallObjectChain() throws Exception {
ObjectInserter.Formatter fmt = new ObjectInserter.Formatter();
byte[] data0 = new byte[512];
Arrays.fill(data0, (byte) 0xf3);
ObjectId id0 = fmt.idFor(Constants.OBJ_BLOB, data0);
TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(64 * 1024);
packHeader(pack, 4);
objectHeader(pack, Constants.OBJ_BLOB, data0.length);
deflate(pack, data0);
byte[] data1 = clone(0x01, data0);
byte[] delta1 = delta(data0, data1);
ObjectId id1 = fmt.idFor(Constants.OBJ_BLOB, data1);
objectHeader(pack, Constants.OBJ_REF_DELTA, delta1.length);
id0.copyRawTo(pack);
deflate(pack, delta1);
byte[] data2 = clone(0x02, data1);
byte[] delta2 = delta(data1, data2);
ObjectId id2 = fmt.idFor(Constants.OBJ_BLOB, data2);
objectHeader(pack, Constants.OBJ_REF_DELTA, delta2.length);
id1.copyRawTo(pack);
deflate(pack, delta2);
byte[] data3 = clone(0x03, data2);
byte[] delta3 = delta(data2, data3);
ObjectId id3 = fmt.idFor(Constants.OBJ_BLOB, data3);
objectHeader(pack, Constants.OBJ_REF_DELTA, delta3.length);
id2.copyRawTo(pack);
deflate(pack, delta3);
digest(pack);
final byte[] raw = pack.toByteArray();
IndexPack ip = IndexPack.create(repo, new ByteArrayInputStream(raw));
ip.setFixThin(true);
ip.index(NullProgressMonitor.INSTANCE);
ip.renameAndOpenPack();
assertTrue("has blob", wc.has(id3));
ObjectLoader ol = wc.open(id3);
assertNotNull("created loader", ol);
assertEquals(Constants.OBJ_BLOB, ol.getType());
assertEquals(data3.length, ol.getSize());
assertFalse("is large", ol.isLarge());
assertNotNull(ol.getCachedBytes());
assertTrue(Arrays.equals(data3, ol.getCachedBytes()));
ObjectStream in = ol.openStream();
assertNotNull("have stream", in);
assertEquals(Constants.OBJ_BLOB, in.getType());
assertEquals(data3.length, in.getSize());
byte[] act = new byte[data3.length];
IO.readFully(in, act, 0, data3.length);
assertTrue("same content", Arrays.equals(act, data3));
assertEquals("stream at EOF", -1, in.read());
in.close();
}
public void testDelta_LargeObjectChain() throws Exception {
ObjectInserter.Formatter fmt = new ObjectInserter.Formatter();
byte[] data0 = new byte[ObjectLoader.STREAM_THRESHOLD + 5];
Arrays.fill(data0, (byte) 0xf3);
ObjectId id0 = fmt.idFor(Constants.OBJ_BLOB, data0);
TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(64 * 1024);
packHeader(pack, 4);
objectHeader(pack, Constants.OBJ_BLOB, data0.length);
deflate(pack, data0);
byte[] data1 = clone(0x01, data0);
byte[] delta1 = delta(data0, data1);
ObjectId id1 = fmt.idFor(Constants.OBJ_BLOB, data1);
objectHeader(pack, Constants.OBJ_REF_DELTA, delta1.length);
id0.copyRawTo(pack);
deflate(pack, delta1);
byte[] data2 = clone(0x02, data1);
byte[] delta2 = delta(data1, data2);
ObjectId id2 = fmt.idFor(Constants.OBJ_BLOB, data2);
objectHeader(pack, Constants.OBJ_REF_DELTA, delta2.length);
id1.copyRawTo(pack);
deflate(pack, delta2);
byte[] data3 = clone(0x03, data2);
byte[] delta3 = delta(data2, data3);
ObjectId id3 = fmt.idFor(Constants.OBJ_BLOB, data3);
objectHeader(pack, Constants.OBJ_REF_DELTA, delta3.length);
id2.copyRawTo(pack);
deflate(pack, delta3);
digest(pack);
final byte[] raw = pack.toByteArray();
IndexPack ip = IndexPack.create(repo, new ByteArrayInputStream(raw));
ip.setFixThin(true);
ip.index(NullProgressMonitor.INSTANCE);
ip.renameAndOpenPack();
assertTrue("has blob", wc.has(id3));
ObjectLoader ol = wc.open(id3);
assertNotNull("created loader", ol);
assertEquals(Constants.OBJ_BLOB, ol.getType());
assertEquals(data3.length, ol.getSize());
assertTrue("is large", ol.isLarge());
try {
ol.getCachedBytes();
fail("Should have thrown LargeObjectException");
} catch (LargeObjectException tooBig) {
assertEquals(id3.name(), tooBig.getMessage());
}
ObjectStream in = ol.openStream();
assertNotNull("have stream", in);
assertEquals(Constants.OBJ_BLOB, in.getType());
assertEquals(data3.length, in.getSize());
byte[] act = new byte[data3.length];
IO.readFully(in, act, 0, data3.length);
assertTrue("same content", Arrays.equals(act, data3));
assertEquals("stream at EOF", -1, in.read());
in.close();
}
public void testDelta_LargeInstructionStream() throws Exception {
ObjectInserter.Formatter fmt = new ObjectInserter.Formatter();
byte[] data0 = new byte[32];
Arrays.fill(data0, (byte) 0xf3);
ObjectId id0 = fmt.idFor(Constants.OBJ_BLOB, data0);
byte[] data3 = rng.nextBytes(ObjectLoader.STREAM_THRESHOLD + 5);
ByteArrayOutputStream tmp = new ByteArrayOutputStream();
DeltaEncoder de = new DeltaEncoder(tmp, data0.length, data3.length);
de.insert(data3, 0, data3.length);
byte[] delta3 = tmp.toByteArray();
assertTrue(delta3.length > ObjectLoader.STREAM_THRESHOLD);
TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(64 * 1024);
packHeader(pack, 2);
objectHeader(pack, Constants.OBJ_BLOB, data0.length);
deflate(pack, data0);
ObjectId id3 = fmt.idFor(Constants.OBJ_BLOB, data3);
objectHeader(pack, Constants.OBJ_REF_DELTA, delta3.length);
id0.copyRawTo(pack);
deflate(pack, delta3);
digest(pack);
final byte[] raw = pack.toByteArray();
IndexPack ip = IndexPack.create(repo, new ByteArrayInputStream(raw));
ip.setFixThin(true);
ip.index(NullProgressMonitor.INSTANCE);
ip.renameAndOpenPack();
assertTrue("has blob", wc.has(id3));
ObjectLoader ol = wc.open(id3);
assertNotNull("created loader", ol);
assertEquals(Constants.OBJ_BLOB, ol.getType());
assertEquals(data3.length, ol.getSize());
assertTrue("is large", ol.isLarge());
try {
ol.getCachedBytes();
fail("Should have thrown LargeObjectException");
} catch (LargeObjectException tooBig) {
assertEquals(id3.name(), tooBig.getMessage());
}
ObjectStream in = ol.openStream();
assertNotNull("have stream", in);
assertEquals(Constants.OBJ_BLOB, in.getType());
assertEquals(data3.length, in.getSize());
byte[] act = new byte[data3.length];
IO.readFully(in, act, 0, data3.length);
assertTrue("same content", Arrays.equals(act, data3));
assertEquals("stream at EOF", -1, in.read());
in.close();
}
private byte[] clone(int first, byte[] base) {
byte[] r = new byte[base.length];
System.arraycopy(base, 1, r, 1, r.length - 1);
r[0] = (byte) first;
return r;
}
private byte[] delta(byte[] base, byte[] dest) throws IOException {
ByteArrayOutputStream tmp = new ByteArrayOutputStream();
DeltaEncoder de = new DeltaEncoder(tmp, base.length, dest.length);
de.insert(dest, 0, 1);
de.copy(1, base.length - 1);
return tmp.toByteArray();
}
private void packHeader(TemporaryBuffer.Heap pack, int cnt)
throws IOException {
final byte[] hdr = new byte[8];
NB.encodeInt32(hdr, 0, 2);
NB.encodeInt32(hdr, 4, cnt);
pack.write(Constants.PACK_SIGNATURE);
pack.write(hdr, 0, 8);
}
private void objectHeader(TemporaryBuffer.Heap pack, int type, int sz)
throws IOException {
byte[] buf = new byte[8];
int nextLength = sz >>> 4;
buf[0] = (byte) ((nextLength > 0 ? 0x80 : 0x00) | (type << 4) | (sz & 0x0F));
sz = nextLength;
int n = 1;
while (sz > 0) {
nextLength >>>= 7;
buf[n++] = (byte) ((nextLength > 0 ? 0x80 : 0x00) | (sz & 0x7F));
sz = nextLength;
}
pack.write(buf, 0, n);
}
private void deflate(TemporaryBuffer.Heap pack, final byte[] content)
throws IOException {
final Deflater deflater = new Deflater();
final byte[] buf = new byte[128];
deflater.setInput(content, 0, content.length);
deflater.finish();
do {
final int n = deflater.deflate(buf, 0, buf.length);
if (n > 0)
pack.write(buf, 0, n);
} while (!deflater.finished());
deflater.end();
}
private void digest(TemporaryBuffer.Heap buf) throws IOException {
MessageDigest md = Constants.newMessageDigest();
md.update(buf.toByteArray());
buf.write(md.digest());
}
}

5
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/PackIndexTestCase.java → org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackIndexTestCase.java

@ -41,14 +41,15 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.eclipse.jgit.lib;
package org.eclipse.jgit.storage.file;
import java.io.File;
import java.util.Iterator;
import java.util.NoSuchElementException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.PackIndex.MutableEntry;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.storage.file.PackIndex.MutableEntry;
public abstract class PackIndexTestCase extends RepositoryTestCase {

3
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/PackIndexV1Test.java → org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackIndexV1Test.java

@ -43,11 +43,12 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.eclipse.jgit.lib;
package org.eclipse.jgit.storage.file;
import java.io.File;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.util.JGitTestUtil;
public class PackIndexV1Test extends PackIndexTestCase {

3
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/PackIndexV2Test.java → org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackIndexV2Test.java

@ -43,11 +43,12 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.eclipse.jgit.lib;
package org.eclipse.jgit.storage.file;
import java.io.File;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.util.JGitTestUtil;
public class PackIndexV2Test extends PackIndexTestCase {

5
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/PackReverseIndexTest.java → org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackReverseIndexTest.java

@ -42,10 +42,11 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.eclipse.jgit.lib;
package org.eclipse.jgit.storage.file;
import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.lib.PackIndex.MutableEntry;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.storage.file.PackIndex.MutableEntry;
import org.eclipse.jgit.util.JGitTestUtil;
public class PackReverseIndexTest extends RepositoryTestCase {

23
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/PackWriterTest.java → org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/PackWriterTest.java

@ -41,7 +41,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.eclipse.jgit.lib;
package org.eclipse.jgit.storage.file;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@ -59,9 +59,14 @@ import java.util.LinkedList;
import java.util.List;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.PackIndex.MutableEntry;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.SampleDataRepositoryTestCase;
import org.eclipse.jgit.lib.TextProgressMonitor;
import org.eclipse.jgit.revwalk.RevObject;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.storage.file.PackIndex.MutableEntry;
import org.eclipse.jgit.storage.pack.PackWriter;
import org.eclipse.jgit.transport.IndexPack;
import org.eclipse.jgit.util.JGitTestUtil;
@ -91,7 +96,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
packBase = new File(trash, "tmp_pack");
packFile = new File(trash, "tmp_pack.pack");
indexFile = new File(trash, "tmp_pack.idx");
writer = new PackWriter(db, new TextProgressMonitor());
writer = new PackWriter(db);
}
/**
@ -238,7 +243,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
* @throws IOException
*/
public void testWritePack2DeltasCRC32Copy() throws IOException {
final File packDir = new File(db.getObjectsDirectory(), "pack");
final File packDir = new File(db.getObjectDatabase().getDirectory(), "pack");
final File crc32Pack = new File(packDir,
"pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.pack");
final File crc32Idx = new File(packDir,
@ -476,17 +481,21 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
final Collection<ObjectId> uninterestings, final boolean thin,
final boolean ignoreMissingUninteresting)
throws MissingObjectException, IOException {
NullProgressMonitor m = NullProgressMonitor.INSTANCE;
writer.setThin(thin);
writer.setIgnoreMissingUninteresting(ignoreMissingUninteresting);
writer.preparePack(interestings, uninterestings);
writer.writePack(os);
writer.preparePack(m, interestings, uninterestings);
writer.writePack(m, m, os);
writer.release();
verifyOpenPack(thin);
}
private void createVerifyOpenPack(final Iterator<RevObject> objectSource)
throws MissingObjectException, IOException {
NullProgressMonitor m = NullProgressMonitor.INSTANCE;
writer.preparePack(objectSource);
writer.writePack(os);
writer.writePack(m, m, os);
writer.release();
verifyOpenPack(false);
}

6
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefDirectoryTest.java → org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefDirectoryTest.java

@ -41,7 +41,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.eclipse.jgit.lib;
package org.eclipse.jgit.storage.file;
import static org.eclipse.jgit.lib.Constants.HEAD;
import static org.eclipse.jgit.lib.Constants.R_HEADS;
@ -55,6 +55,10 @@ import java.util.Map;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefDatabase;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevTag;

31
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefUpdateTest.java → org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefUpdateTest.java

@ -43,7 +43,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.eclipse.jgit.lib;
package org.eclipse.jgit.storage.file;
import java.io.File;
import java.io.IOException;
@ -51,9 +51,22 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefRename;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.SampleDataRepositoryTestCase;
import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.jgit.storage.file.LockFile;
import org.eclipse.jgit.storage.file.RefDirectory;
import org.eclipse.jgit.storage.file.RefDirectoryUpdate;
import org.eclipse.jgit.storage.file.ReflogReader;
public class RefUpdateTest extends SampleDataRepositoryTestCase {
@ -103,14 +116,14 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
assertNotSame(newid, r.getObjectId());
assertSame(ObjectId.class, r.getObjectId().getClass());
assertEquals(newid.copy(), r.getObjectId());
List<org.eclipse.jgit.lib.ReflogReader.Entry> reverseEntries1 = db.getReflogReader("refs/heads/abc").getReverseEntries();
org.eclipse.jgit.lib.ReflogReader.Entry entry1 = reverseEntries1.get(0);
List<org.eclipse.jgit.storage.file.ReflogReader.Entry> reverseEntries1 = db.getReflogReader("refs/heads/abc").getReverseEntries();
org.eclipse.jgit.storage.file.ReflogReader.Entry entry1 = reverseEntries1.get(0);
assertEquals(1, reverseEntries1.size());
assertEquals(ObjectId.zeroId(), entry1.getOldId());
assertEquals(r.getObjectId(), entry1.getNewId());
assertEquals(new PersonIdent(db).toString(), entry1.getWho().toString());
assertEquals("", entry1.getComment());
List<org.eclipse.jgit.lib.ReflogReader.Entry> reverseEntries2 = db.getReflogReader("HEAD").getReverseEntries();
List<org.eclipse.jgit.storage.file.ReflogReader.Entry> reverseEntries2 = db.getReflogReader("HEAD").getReverseEntries();
assertEquals(0, reverseEntries2.size());
}
@ -326,7 +339,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
// the branch HEAD referred to is left untouched
assertEquals(pid, db.resolve("refs/heads/master"));
ReflogReader reflogReader = new ReflogReader(db, "HEAD");
org.eclipse.jgit.lib.ReflogReader.Entry e = reflogReader.getReverseEntries().get(0);
org.eclipse.jgit.storage.file.ReflogReader.Entry e = reflogReader.getReverseEntries().get(0);
assertEquals(pid, e.getOldId());
assertEquals(ppid, e.getNewId());
assertEquals("GIT_COMMITTER_EMAIL", e.getWho().getEmailAddress());
@ -355,7 +368,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
// the branch HEAD referred to is left untouched
assertNull(db.resolve("refs/heads/unborn"));
ReflogReader reflogReader = new ReflogReader(db, "HEAD");
org.eclipse.jgit.lib.ReflogReader.Entry e = reflogReader.getReverseEntries().get(0);
org.eclipse.jgit.storage.file.ReflogReader.Entry e = reflogReader.getReverseEntries().get(0);
assertEquals(ObjectId.zeroId(), e.getOldId());
assertEquals(ppid, e.getNewId());
assertEquals("GIT_COMMITTER_EMAIL", e.getWho().getEmailAddress());
@ -664,7 +677,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
// Create new Repository instance, to reread caches and make sure our
// assumptions are persistent.
Repository ndb = new Repository(db.getDirectory());
Repository ndb = new FileRepository(db.getDirectory());
assertEquals(rb2, ndb.resolve("refs/heads/new/name"));
assertNull(ndb.resolve("refs/heads/b"));
}
@ -677,9 +690,9 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
ObjectId oldHeadId = db.resolve(Constants.HEAD);
writeReflog(db, oldfromId, oldfromId, "Just a message",
fromName);
List<org.eclipse.jgit.lib.ReflogReader.Entry> oldFromLog = db
List<org.eclipse.jgit.storage.file.ReflogReader.Entry> oldFromLog = db
.getReflogReader(fromName).getReverseEntries();
List<org.eclipse.jgit.lib.ReflogReader.Entry> oldHeadLog = oldHeadId != null ? db
List<org.eclipse.jgit.storage.file.ReflogReader.Entry> oldHeadLog = oldHeadId != null ? db
.getReflogReader(Constants.HEAD).getReverseEntries() : null;
assertTrue("internal check, we have a log", new File(db.getDirectory(),

7
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogReaderTest.java → org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ReflogReaderTest.java

@ -42,7 +42,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.eclipse.jgit.lib;
package org.eclipse.jgit.storage.file;
import java.io.File;
import java.io.FileNotFoundException;
@ -51,7 +51,10 @@ import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.List;
import org.eclipse.jgit.lib.ReflogReader.Entry;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.SampleDataRepositoryTestCase;
import org.eclipse.jgit.storage.file.ReflogReader.Entry;
public class ReflogReaderTest extends SampleDataRepositoryTestCase {

86
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositorySetupWorkDirTest.java → org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RepositorySetupWorkDirTest.java

@ -42,12 +42,17 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.eclipse.jgit.lib;
package org.eclipse.jgit.storage.file;
import java.io.File;
import java.io.IOException;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.errors.NoWorkTreeException;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Repository;
/**
* Tests for setting up the working directory when creating a Repository
@ -57,12 +62,12 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase {
public void testIsBare_CreateRepositoryFromArbitraryGitDir()
throws Exception {
File gitDir = getFile("workdir");
assertTrue(new Repository(gitDir).isBare());
assertTrue(new FileRepository(gitDir).isBare());
}
public void testNotBare_CreateRepositoryFromDotGitGitDir() throws Exception {
File gitDir = getFile("workdir", Constants.DOT_GIT);
Repository repo = new Repository(gitDir);
Repository repo = new FileRepository(gitDir);
assertFalse(repo.isBare());
assertWorkdirPath(repo, "workdir");
assertGitdirPath(repo, "workdir", Constants.DOT_GIT);
@ -71,14 +76,14 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase {
public void testWorkdirIsParentDir_CreateRepositoryFromDotGitGitDir()
throws Exception {
File gitDir = getFile("workdir", Constants.DOT_GIT);
Repository repo = new Repository(gitDir);
String workdir = repo.getWorkDir().getName();
Repository repo = new FileRepository(gitDir);
String workdir = repo.getWorkTree().getName();
assertEquals(workdir, "workdir");
}
public void testNotBare_CreateRepositoryFromWorkDirOnly() throws Exception {
File workdir = getFile("workdir", "repo");
Repository repo = new Repository(null, workdir);
FileRepository repo = new FileRepositoryBuilder().setWorkTree(workdir).build();
assertFalse(repo.isBare());
assertWorkdirPath(repo, "workdir", "repo");
assertGitdirPath(repo, "workdir", "repo", Constants.DOT_GIT);
@ -87,7 +92,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase {
public void testWorkdirIsDotGit_CreateRepositoryFromWorkDirOnly()
throws Exception {
File workdir = getFile("workdir", "repo");
Repository repo = new Repository(null, workdir);
FileRepository repo = new FileRepositoryBuilder().setWorkTree(workdir).build();
assertGitdirPath(repo, "workdir", "repo", Constants.DOT_GIT);
}
@ -96,7 +101,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase {
File gitDir = getFile("workdir", "repoWithConfig");
File workTree = getFile("workdir", "treeRoot");
setWorkTree(gitDir, workTree);
Repository repo = new Repository(gitDir, null);
FileRepository repo = new FileRepositoryBuilder().setGitDir(gitDir).build();
assertFalse(repo.isBare());
assertWorkdirPath(repo, "workdir", "treeRoot");
assertGitdirPath(repo, "workdir", "repoWithConfig");
@ -106,7 +111,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase {
throws Exception {
File gitDir = getFile("workdir", "repoWithConfig");
setBare(gitDir, true);
Repository repo = new Repository(gitDir, null);
FileRepository repo = new FileRepositoryBuilder().setGitDir(gitDir).build();
assertTrue(repo.isBare());
}
@ -114,7 +119,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase {
throws Exception {
File gitDir = getFile("workdir", "repoWithBareConfigTrue", "child");
setBare(gitDir, false);
Repository repo = new Repository(gitDir, null);
FileRepository repo = new FileRepositoryBuilder().setGitDir(gitDir).build();
assertWorkdirPath(repo, "workdir", "repoWithBareConfigTrue");
}
@ -122,27 +127,18 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase {
throws Exception {
File gitDir = getFile("workdir", "repoWithBareConfigFalse", "child");
setBare(gitDir, false);
Repository repo = new Repository(gitDir, null);
FileRepository repo = new FileRepositoryBuilder().setGitDir(gitDir).build();
assertFalse(repo.isBare());
assertWorkdirPath(repo, "workdir", "repoWithBareConfigFalse");
assertGitdirPath(repo, "workdir", "repoWithBareConfigFalse", "child");
}
public void testNotBare_MakeBareUnbareBySetWorkdir() throws Exception {
File gitDir = getFile("gitDir");
Repository repo = new Repository(gitDir);
repo.setWorkDir(getFile("workingDir"));
assertFalse(repo.isBare());
assertWorkdirPath(repo, "workingDir");
assertGitdirPath(repo, "gitDir");
}
public void testExceptionThrown_BareRepoGetWorkDir() throws Exception {
File gitDir = getFile("workdir");
try {
new Repository(gitDir).getWorkDir();
fail("Expected IllegalStateException missing");
} catch (IllegalStateException e) {
new FileRepository(gitDir).getWorkTree();
fail("Expected NoWorkTreeException missing");
} catch (NoWorkTreeException e) {
// expected
}
}
@ -150,9 +146,9 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase {
public void testExceptionThrown_BareRepoGetIndex() throws Exception {
File gitDir = getFile("workdir");
try {
new Repository(gitDir).getIndex();
fail("Expected IllegalStateException missing");
} catch (IllegalStateException e) {
new FileRepository(gitDir).getIndex();
fail("Expected NoWorkTreeException missing");
} catch (NoWorkTreeException e) {
// expected
}
}
@ -160,9 +156,9 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase {
public void testExceptionThrown_BareRepoGetIndexFile() throws Exception {
File gitDir = getFile("workdir");
try {
new Repository(gitDir).getIndexFile();
fail("Expected Exception missing");
} catch (IllegalStateException e) {
new FileRepository(gitDir).getIndexFile();
fail("Expected NoWorkTreeException missing");
} catch (NoWorkTreeException e) {
// expected
}
}
@ -176,20 +172,28 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase {
return result;
}
private void setBare(File gitDir, boolean bare) throws IOException {
Repository repo = new Repository(gitDir, null);
repo.getConfig().setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
private void setBare(File gitDir, boolean bare) throws IOException,
ConfigInvalidException {
FileBasedConfig cfg = configFor(gitDir);
cfg.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
ConfigConstants.CONFIG_KEY_BARE, bare);
repo.getConfig().save();
cfg.save();
}
private void setWorkTree(File gitDir, File workTree) throws IOException,
ConfigInvalidException {
String path = workTree.getAbsolutePath();
FileBasedConfig cfg = configFor(gitDir);
cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null,
ConfigConstants.CONFIG_KEY_WORKTREE, path);
cfg.save();
}
private void setWorkTree(File gitDir, File workTree) throws IOException {
Repository repo = new Repository(gitDir, null);
repo.getConfig()
.setString(ConfigConstants.CONFIG_CORE_SECTION, null,
ConfigConstants.CONFIG_KEY_WORKTREE,
workTree.getAbsolutePath());
repo.getConfig().save();
private FileBasedConfig configFor(File gitDir) throws IOException,
ConfigInvalidException {
FileBasedConfig cfg = new FileBasedConfig(new File(gitDir, "config"));
cfg.load();
return cfg;
}
private void assertGitdirPath(Repository repo, String... expected)
@ -202,7 +206,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase {
private void assertWorkdirPath(Repository repo, String... expected)
throws IOException {
File exp = getFile(expected).getCanonicalFile();
File act = repo.getWorkDir().getCanonicalFile();
File act = repo.getWorkTree().getCanonicalFile();
assertEquals("Wrong working Directory", exp, act);
}
}

106
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java → org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_Basic.java

@ -43,7 +43,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.eclipse.jgit.lib;
package org.eclipse.jgit.storage.file;
import java.io.ByteArrayInputStream;
import java.io.File;
@ -53,7 +53,23 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import org.eclipse.jgit.JGitText;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.Commit;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileTreeEntry;
import org.eclipse.jgit.lib.ObjectDatabase;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectWriter;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.SampleDataRepositoryTestCase;
import org.eclipse.jgit.lib.Tag;
import org.eclipse.jgit.lib.Tree;
import org.eclipse.jgit.lib.TreeEntry;
import org.eclipse.jgit.lib.WriteTree;
public class T0003_Basic extends SampleDataRepositoryTestCase {
public void test001_Initalize() {
@ -80,11 +96,11 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
public void test000_openRepoBadArgs() throws IOException {
try {
new Repository(null, null);
new FileRepositoryBuilder().build();
fail("Must pass either GIT_DIR or GIT_WORK_TREE");
} catch (IllegalArgumentException e) {
assertEquals(
"Either GIT_DIR or GIT_WORK_TREE must be passed to Repository constructor",
JGitText.get().eitherGitDirOrWorkTreeRequired,
e.getMessage());
}
}
@ -97,16 +113,16 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
*/
public void test000_openrepo_default_gitDirSet() throws IOException {
File repo1Parent = new File(trash.getParentFile(), "r1");
Repository repo1initial = new Repository(new File(repo1Parent, Constants.DOT_GIT));
Repository repo1initial = new FileRepository(new File(repo1Parent, Constants.DOT_GIT));
repo1initial.create();
repo1initial.close();
File theDir = new File(repo1Parent, Constants.DOT_GIT);
Repository r = new Repository(theDir, null);
FileRepository r = new FileRepositoryBuilder().setGitDir(theDir).build();
assertEqualsPath(theDir, r.getDirectory());
assertEqualsPath(repo1Parent, r.getWorkDir());
assertEqualsPath(repo1Parent, r.getWorkTree());
assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
assertEqualsPath(new File(theDir, "objects"), r.getObjectsDirectory());
assertEqualsPath(new File(theDir, "objects"), r.getObjectDatabase().getDirectory());
}
/**
@ -117,16 +133,17 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
*/
public void test000_openrepo_default_gitDirAndWorkTreeSet() throws IOException {
File repo1Parent = new File(trash.getParentFile(), "r1");
Repository repo1initial = new Repository(new File(repo1Parent, Constants.DOT_GIT));
Repository repo1initial = new FileRepository(new File(repo1Parent, Constants.DOT_GIT));
repo1initial.create();
repo1initial.close();
File theDir = new File(repo1Parent, Constants.DOT_GIT);
Repository r = new Repository(theDir, repo1Parent.getParentFile());
FileRepository r = new FileRepositoryBuilder().setGitDir(theDir)
.setWorkTree(repo1Parent.getParentFile()).build();
assertEqualsPath(theDir, r.getDirectory());
assertEqualsPath(repo1Parent.getParentFile(), r.getWorkDir());
assertEqualsPath(repo1Parent.getParentFile(), r.getWorkTree());
assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
assertEqualsPath(new File(theDir, "objects"), r.getObjectsDirectory());
assertEqualsPath(new File(theDir, "objects"), r.getObjectDatabase().getDirectory());
}
/**
@ -137,16 +154,16 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
*/
public void test000_openrepo_default_workDirSet() throws IOException {
File repo1Parent = new File(trash.getParentFile(), "r1");
Repository repo1initial = new Repository(new File(repo1Parent, Constants.DOT_GIT));
Repository repo1initial = new FileRepository(new File(repo1Parent, Constants.DOT_GIT));
repo1initial.create();
repo1initial.close();
File theDir = new File(repo1Parent, Constants.DOT_GIT);
Repository r = new Repository(null, repo1Parent);
FileRepository r = new FileRepositoryBuilder().setWorkTree(repo1Parent).build();
assertEqualsPath(theDir, r.getDirectory());
assertEqualsPath(repo1Parent, r.getWorkDir());
assertEqualsPath(repo1Parent, r.getWorkTree());
assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
assertEqualsPath(new File(theDir, "objects"), r.getObjectsDirectory());
assertEqualsPath(new File(theDir, "objects"), r.getObjectDatabase().getDirectory());
}
/**
@ -159,7 +176,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
File repo1Parent = new File(trash.getParentFile(), "r1");
File workdir = new File(trash.getParentFile(), "rw");
workdir.mkdir();
Repository repo1initial = new Repository(new File(repo1Parent, Constants.DOT_GIT));
FileRepository repo1initial = new FileRepository(new File(repo1Parent, Constants.DOT_GIT));
repo1initial.create();
repo1initial.getConfig().setString("core", null, "worktree",
workdir.getAbsolutePath());
@ -167,11 +184,11 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
repo1initial.close();
File theDir = new File(repo1Parent, Constants.DOT_GIT);
Repository r = new Repository(theDir, null);
FileRepository r = new FileRepositoryBuilder().setGitDir(theDir).build();
assertEqualsPath(theDir, r.getDirectory());
assertEqualsPath(workdir, r.getWorkDir());
assertEqualsPath(workdir, r.getWorkTree());
assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
assertEqualsPath(new File(theDir, "objects"), r.getObjectsDirectory());
assertEqualsPath(new File(theDir, "objects"), r.getObjectDatabase().getDirectory());
}
/**
@ -184,7 +201,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
File repo1Parent = new File(trash.getParentFile(), "r1");
File workdir = new File(trash.getParentFile(), "rw");
workdir.mkdir();
Repository repo1initial = new Repository(new File(repo1Parent, Constants.DOT_GIT));
FileRepository repo1initial = new FileRepository(new File(repo1Parent, Constants.DOT_GIT));
repo1initial.create();
repo1initial.getConfig()
.setString("core", null, "worktree", "../../rw");
@ -192,11 +209,11 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
repo1initial.close();
File theDir = new File(repo1Parent, Constants.DOT_GIT);
Repository r = new Repository(theDir, null);
FileRepository r = new FileRepositoryBuilder().setGitDir(theDir).build();
assertEqualsPath(theDir, r.getDirectory());
assertEqualsPath(workdir, r.getWorkDir());
assertEqualsPath(workdir, r.getWorkTree());
assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
assertEqualsPath(new File(theDir, "objects"), r.getObjectsDirectory());
assertEqualsPath(new File(theDir, "objects"), r.getObjectDatabase().getDirectory());
}
/**
@ -210,18 +227,21 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
File repo1Parent = new File(trash.getParentFile(), "r1");
File indexFile = new File(trash, "idx");
File objDir = new File(trash, "../obj");
File[] altObjDirs = new File[] { db.getObjectsDirectory() };
Repository repo1initial = new Repository(new File(repo1Parent, Constants.DOT_GIT));
File altObjDir = db.getObjectDatabase().getDirectory();
Repository repo1initial = new FileRepository(new File(repo1Parent, Constants.DOT_GIT));
repo1initial.create();
repo1initial.close();
File theDir = new File(repo1Parent, Constants.DOT_GIT);
Repository r = new Repository(theDir, null, objDir, altObjDirs,
indexFile);
FileRepository r = new FileRepositoryBuilder() //
.setGitDir(theDir).setObjectDirectory(objDir) //
.addAlternateObjectDirectory(altObjDir) //
.setIndexFile(indexFile) //
.build();
assertEqualsPath(theDir, r.getDirectory());
assertEqualsPath(theDir.getParentFile(), r.getWorkDir());
assertEqualsPath(theDir.getParentFile(), r.getWorkTree());
assertEqualsPath(indexFile, r.getIndexFile());
assertEqualsPath(objDir, r.getObjectsDirectory());
assertEqualsPath(objDir, r.getObjectDatabase().getDirectory());
assertNotNull(r.mapCommit("6db9c2ebf75590eef973081736730a9ea169a0c4"));
// Must close or the default repo pack files created by this test gets
// locked via the alternate object directories on Windows.
@ -283,7 +303,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
}
public void test005_ReadSimpleConfig() {
final RepositoryConfig c = db.getConfig();
final Config c = db.getConfig();
assertNotNull(c);
assertEquals("0", c.getString("core", null, "repositoryformatversion"));
assertEquals("0", c.getString("CoRe", null, "REPOSITORYFoRmAtVeRsIoN"));
@ -294,8 +314,8 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
public void test006_ReadUglyConfig() throws IOException,
ConfigInvalidException {
final RepositoryConfig c = db.getConfig();
final File cfg = new File(db.getDirectory(), "config");
final FileBasedConfig c = new FileBasedConfig(cfg);
final FileWriter pw = new FileWriter(cfg);
final String configStr = " [core];comment\n\tfilemode = yes\n"
+ "[user]\n"
@ -321,9 +341,9 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
}
public void test007_Open() throws IOException {
final Repository db2 = new Repository(db.getDirectory());
final FileRepository db2 = new FileRepository(db.getDirectory());
assertEquals(db.getDirectory(), db2.getDirectory());
assertEquals(db.getObjectsDirectory(), db2.getObjectsDirectory());
assertEquals(db.getObjectDatabase().getDirectory(), db2.getObjectDatabase().getDirectory());
assertNotSame(db.getConfig(), db2.getConfig());
}
@ -337,7 +357,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
pw.close();
try {
new Repository(db.getDirectory());
new FileRepository(db.getDirectory());
fail("incorrectly opened a bad repository");
} catch (IOException ioe) {
assertTrue(ioe.getMessage().indexOf("format") > 0);
@ -345,11 +365,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
}
}
public void test009_CreateCommitOldFormat() throws IOException,
ConfigInvalidException {
writeTrashFile(".git/config", "[core]\n" + "legacyHeaders=1\n");
db.getConfig().load();
public void test009_CreateCommitOldFormat() throws IOException {
final Tree t = new Tree(db);
final FileTreeEntry f = t.addFile("i-am-a-file");
writeTrashFile(f.getName(), "and this is the data in me\n");
@ -369,8 +385,10 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
assertEquals(cmtid, c.getCommitId());
// Verify the commit we just wrote is in the correct format.
final XInputStream xis = new XInputStream(new FileInputStream(db
.toFile(cmtid)));
ObjectDatabase odb = db.getObjectDatabase();
assertTrue("is ObjectDirectory", odb instanceof ObjectDirectory);
final XInputStream xis = new XInputStream(new FileInputStream(
((ObjectDirectory) odb).fileFor(cmtid)));
try {
assertEquals(0x78, xis.readUInt8());
assertEquals(0x9c, xis.readUInt8());
@ -724,10 +742,10 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
assertEquals("", Repository.stripWorkDir(relBase, relNonFile));
assertEquals("", Repository.stripWorkDir(absBase, absNonFile));
assertEquals("", Repository.stripWorkDir(db.getWorkDir(), db.getWorkDir()));
assertEquals("", Repository.stripWorkDir(db.getWorkTree(), db.getWorkTree()));
File file = new File(new File(db.getWorkDir(), "subdir"), "File.java");
assertEquals("subdir/File.java", Repository.stripWorkDir(db.getWorkDir(), file));
File file = new File(new File(db.getWorkTree(), "subdir"), "File.java");
assertEquals("subdir/File.java", Repository.stripWorkDir(db.getWorkTree(), file));
}

15
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0004_PackReader.java → org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0004_PackReader.java

@ -44,11 +44,15 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.eclipse.jgit.lib;
package org.eclipse.jgit.storage.file;
import java.io.File;
import java.io.IOException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.SampleDataRepositoryTestCase;
import org.eclipse.jgit.util.JGitTestUtil;
public class T0004_PackReader extends SampleDataRepositoryTestCase {
@ -59,15 +63,14 @@ public class T0004_PackReader extends SampleDataRepositoryTestCase {
public void test003_lookupCompressedObject() throws IOException {
final PackFile pr;
final ObjectId id;
final PackedObjectLoader or;
final ObjectLoader or;
id = ObjectId.fromString("902d5476fa249b7abc9d84c611577a81381f0327");
pr = new PackFile(TEST_IDX, TEST_PACK);
or = pr.get(new WindowCursor(), id);
or = pr.get(new WindowCursor(null), id);
assertNotNull(or);
assertEquals(Constants.OBJ_TREE, or.getType());
assertEquals(35, or.getSize());
assertEquals(7736, or.getObjectOffset());
pr.close();
}
@ -76,11 +79,9 @@ public class T0004_PackReader extends SampleDataRepositoryTestCase {
final ObjectLoader or;
id = ObjectId.fromString("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259");
or = db.openObject(id);
or = db.open(id);
assertNotNull(or);
assertTrue(or instanceof PackedObjectLoader);
assertEquals(Constants.OBJ_BLOB, or.getType());
assertEquals(18009, or.getSize());
assertEquals(516, ((PackedObjectLoader) or).getObjectOffset());
}
}

534
org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/UnpackedObjectTest.java

@ -0,0 +1,534 @@
/*
* Copyright (C) 2010, 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.file;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.zip.DeflaterOutputStream;
import org.eclipse.jgit.JGitText;
import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.errors.LargeObjectException;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.junit.TestRng;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.ObjectStream;
import org.eclipse.jgit.util.IO;
public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
private TestRng rng;
private FileRepository repo;
private WindowCursor wc;
protected void setUp() throws Exception {
super.setUp();
rng = new TestRng(getName());
repo = createBareRepository();
wc = (WindowCursor) repo.newObjectReader();
}
protected void tearDown() throws Exception {
if (wc != null)
wc.release();
super.tearDown();
}
public void testStandardFormat_SmallObject() throws Exception {
final int type = Constants.OBJ_BLOB;
byte[] data = rng.nextBytes(300);
byte[] gz = compressStandardFormat(type, data);
ObjectId id = ObjectId.zeroId();
ObjectLoader ol = UnpackedObject.open(new ByteArrayInputStream(gz),
path(id), id, wc);
assertNotNull("created loader", ol);
assertEquals(type, ol.getType());
assertEquals(data.length, ol.getSize());
assertFalse("is not large", ol.isLarge());
assertTrue("same content", Arrays.equals(data, ol.getCachedBytes()));
ObjectStream in = ol.openStream();
assertNotNull("have stream", in);
assertEquals(type, in.getType());
assertEquals(data.length, in.getSize());
byte[] data2 = new byte[data.length];
IO.readFully(in, data2, 0, data.length);
assertTrue("same content", Arrays.equals(data2, data));
assertEquals("stream at EOF", -1, in.read());
in.close();
}
public void testStandardFormat_LargeObject() throws Exception {
final int type = Constants.OBJ_BLOB;
byte[] data = rng.nextBytes(ObjectLoader.STREAM_THRESHOLD + 5);
ObjectId id = new ObjectInserter.Formatter().idFor(type, data);
write(id, compressStandardFormat(type, data));
ObjectLoader ol;
{
FileInputStream fs = new FileInputStream(path(id));
try {
ol = UnpackedObject.open(fs, path(id), id, wc);
} finally {
fs.close();
}
}
assertNotNull("created loader", ol);
assertEquals(type, ol.getType());
assertEquals(data.length, ol.getSize());
assertTrue("is large", ol.isLarge());
try {
ol.getCachedBytes();
fail("Should have thrown LargeObjectException");
} catch (LargeObjectException tooBig) {
assertEquals(id.name(), tooBig.getMessage());
}
ObjectStream in = ol.openStream();
assertNotNull("have stream", in);
assertEquals(type, in.getType());
assertEquals(data.length, in.getSize());
byte[] data2 = new byte[data.length];
IO.readFully(in, data2, 0, data.length);
assertTrue("same content", Arrays.equals(data2, data));
assertEquals("stream at EOF", -1, in.read());
in.close();
}
public void testStandardFormat_NegativeSize() throws Exception {
ObjectId id = ObjectId.zeroId();
byte[] data = rng.nextBytes(300);
try {
byte[] gz = compressStandardFormat("blob", "-1", data);
UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
fail("Did not throw CorruptObjectException");
} catch (CorruptObjectException coe) {
assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
id.name(), JGitText.get().corruptObjectNegativeSize), coe
.getMessage());
}
}
public void testStandardFormat_InvalidType() throws Exception {
ObjectId id = ObjectId.zeroId();
byte[] data = rng.nextBytes(300);
try {
byte[] gz = compressStandardFormat("not.a.type", "1", data);
UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
fail("Did not throw CorruptObjectException");
} catch (CorruptObjectException coe) {
assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
id.name(), JGitText.get().corruptObjectInvalidType), coe
.getMessage());
}
}
public void testStandardFormat_NoHeader() throws Exception {
ObjectId id = ObjectId.zeroId();
byte[] data = {};
try {
byte[] gz = compressStandardFormat("", "", data);
UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
fail("Did not throw CorruptObjectException");
} catch (CorruptObjectException coe) {
assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
id.name(), JGitText.get().corruptObjectNoHeader), coe
.getMessage());
}
}
public void testStandardFormat_GarbageAfterSize() throws Exception {
ObjectId id = ObjectId.zeroId();
byte[] data = rng.nextBytes(300);
try {
byte[] gz = compressStandardFormat("blob", "1foo", data);
UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
fail("Did not throw CorruptObjectException");
} catch (CorruptObjectException coe) {
assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
id.name(), JGitText.get().corruptObjectGarbageAfterSize),
coe.getMessage());
}
}
public void testStandardFormat_SmallObject_CorruptZLibStream()
throws Exception {
ObjectId id = ObjectId.zeroId();
byte[] data = rng.nextBytes(300);
try {
byte[] gz = compressStandardFormat(Constants.OBJ_BLOB, data);
for (int i = 5; i < gz.length; i++)
gz[i] = 0;
UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
fail("Did not throw CorruptObjectException");
} catch (CorruptObjectException coe) {
assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
id.name(), JGitText.get().corruptObjectBadStream), coe
.getMessage());
}
}
public void testStandardFormat_SmallObject_TruncatedZLibStream()
throws Exception {
ObjectId id = ObjectId.zeroId();
byte[] data = rng.nextBytes(300);
try {
byte[] gz = compressStandardFormat(Constants.OBJ_BLOB, data);
byte[] tr = new byte[gz.length - 1];
System.arraycopy(gz, 0, tr, 0, tr.length);
UnpackedObject.open(new ByteArrayInputStream(tr), path(id), id, wc);
fail("Did not throw CorruptObjectException");
} catch (CorruptObjectException coe) {
assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
id.name(), JGitText.get().corruptObjectBadStream), coe
.getMessage());
}
}
public void testStandardFormat_SmallObject_TrailingGarbage()
throws Exception {
ObjectId id = ObjectId.zeroId();
byte[] data = rng.nextBytes(300);
try {
byte[] gz = compressStandardFormat(Constants.OBJ_BLOB, data);
byte[] tr = new byte[gz.length + 1];
System.arraycopy(gz, 0, tr, 0, gz.length);
UnpackedObject.open(new ByteArrayInputStream(tr), path(id), id, wc);
fail("Did not throw CorruptObjectException");
} catch (CorruptObjectException coe) {
assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
id.name(), JGitText.get().corruptObjectBadStream), coe
.getMessage());
}
}
public void testStandardFormat_LargeObject_CorruptZLibStream()
throws Exception {
final int type = Constants.OBJ_BLOB;
byte[] data = rng.nextBytes(ObjectLoader.STREAM_THRESHOLD + 5);
ObjectId id = new ObjectInserter.Formatter().idFor(type, data);
byte[] gz = compressStandardFormat(type, data);
gz[gz.length - 1] = 0;
gz[gz.length - 2] = 0;
write(id, gz);
ObjectLoader ol;
{
FileInputStream fs = new FileInputStream(path(id));
try {
ol = UnpackedObject.open(fs, path(id), id, wc);
} finally {
fs.close();
}
}
try {
byte[] tmp = new byte[data.length];
InputStream in = ol.openStream();
try {
IO.readFully(in, tmp, 0, tmp.length);
} finally {
in.close();
}
fail("Did not throw CorruptObjectException");
} catch (CorruptObjectException coe) {
assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
id.name(), JGitText.get().corruptObjectBadStream), coe
.getMessage());
}
}
public void testStandardFormat_LargeObject_TruncatedZLibStream()
throws Exception {
final int type = Constants.OBJ_BLOB;
byte[] data = rng.nextBytes(ObjectLoader.STREAM_THRESHOLD + 5);
ObjectId id = new ObjectInserter.Formatter().idFor(type, data);
byte[] gz = compressStandardFormat(type, data);
byte[] tr = new byte[gz.length - 1];
System.arraycopy(gz, 0, tr, 0, tr.length);
write(id, tr);
ObjectLoader ol;
{
FileInputStream fs = new FileInputStream(path(id));
try {
ol = UnpackedObject.open(fs, path(id), id, wc);
} finally {
fs.close();
}
}
byte[] tmp = new byte[data.length];
InputStream in = ol.openStream();
IO.readFully(in, tmp, 0, tmp.length);
try {
in.close();
fail("close did not throw CorruptObjectException");
} catch (CorruptObjectException coe) {
assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
id.name(), JGitText.get().corruptObjectBadStream), coe
.getMessage());
}
}
public void testStandardFormat_LargeObject_TrailingGarbage()
throws Exception {
final int type = Constants.OBJ_BLOB;
byte[] data = rng.nextBytes(ObjectLoader.STREAM_THRESHOLD + 5);
ObjectId id = new ObjectInserter.Formatter().idFor(type, data);
byte[] gz = compressStandardFormat(type, data);
byte[] tr = new byte[gz.length + 1];
System.arraycopy(gz, 0, tr, 0, gz.length);
write(id, tr);
ObjectLoader ol;
{
FileInputStream fs = new FileInputStream(path(id));
try {
ol = UnpackedObject.open(fs, path(id), id, wc);
} finally {
fs.close();
}
}
byte[] tmp = new byte[data.length];
InputStream in = ol.openStream();
IO.readFully(in, tmp, 0, tmp.length);
try {
in.close();
fail("close did not throw CorruptObjectException");
} catch (CorruptObjectException coe) {
assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
id.name(), JGitText.get().corruptObjectBadStream), coe
.getMessage());
}
}
public void testPackFormat_SmallObject() throws Exception {
final int type = Constants.OBJ_BLOB;
byte[] data = rng.nextBytes(300);
byte[] gz = compressPackFormat(type, data);
ObjectId id = ObjectId.zeroId();
ObjectLoader ol = UnpackedObject.open(new ByteArrayInputStream(gz),
path(id), id, wc);
assertNotNull("created loader", ol);
assertEquals(type, ol.getType());
assertEquals(data.length, ol.getSize());
assertFalse("is not large", ol.isLarge());
assertTrue("same content", Arrays.equals(data, ol.getCachedBytes()));
ObjectStream in = ol.openStream();
assertNotNull("have stream", in);
assertEquals(type, in.getType());
assertEquals(data.length, in.getSize());
byte[] data2 = new byte[data.length];
IO.readFully(in, data2, 0, data.length);
assertTrue("same content", Arrays.equals(data, ol.getCachedBytes()));
in.close();
}
public void testPackFormat_LargeObject() throws Exception {
final int type = Constants.OBJ_BLOB;
byte[] data = rng.nextBytes(ObjectLoader.STREAM_THRESHOLD + 5);
ObjectId id = new ObjectInserter.Formatter().idFor(type, data);
write(id, compressPackFormat(type, data));
ObjectLoader ol;
{
FileInputStream fs = new FileInputStream(path(id));
try {
ol = UnpackedObject.open(fs, path(id), id, wc);
} finally {
fs.close();
}
}
assertNotNull("created loader", ol);
assertEquals(type, ol.getType());
assertEquals(data.length, ol.getSize());
assertTrue("is large", ol.isLarge());
try {
ol.getCachedBytes();
fail("Should have thrown LargeObjectException");
} catch (LargeObjectException tooBig) {
assertEquals(id.name(), tooBig.getMessage());
}
ObjectStream in = ol.openStream();
assertNotNull("have stream", in);
assertEquals(type, in.getType());
assertEquals(data.length, in.getSize());
byte[] data2 = new byte[data.length];
IO.readFully(in, data2, 0, data.length);
assertTrue("same content", Arrays.equals(data2, data));
assertEquals("stream at EOF", -1, in.read());
in.close();
}
public void testPackFormat_DeltaNotAllowed() throws Exception {
ObjectId id = ObjectId.zeroId();
byte[] data = rng.nextBytes(300);
try {
byte[] gz = compressPackFormat(Constants.OBJ_OFS_DELTA, data);
UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
fail("Did not throw CorruptObjectException");
} catch (CorruptObjectException coe) {
assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
id.name(), JGitText.get().corruptObjectInvalidType), coe
.getMessage());
}
try {
byte[] gz = compressPackFormat(Constants.OBJ_REF_DELTA, data);
UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
fail("Did not throw CorruptObjectException");
} catch (CorruptObjectException coe) {
assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
id.name(), JGitText.get().corruptObjectInvalidType), coe
.getMessage());
}
try {
byte[] gz = compressPackFormat(Constants.OBJ_TYPE_5, data);
UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
fail("Did not throw CorruptObjectException");
} catch (CorruptObjectException coe) {
assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
id.name(), JGitText.get().corruptObjectInvalidType), coe
.getMessage());
}
try {
byte[] gz = compressPackFormat(Constants.OBJ_EXT, data);
UnpackedObject.open(new ByteArrayInputStream(gz), path(id), id, wc);
fail("Did not throw CorruptObjectException");
} catch (CorruptObjectException coe) {
assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
id.name(), JGitText.get().corruptObjectInvalidType), coe
.getMessage());
}
}
private byte[] compressStandardFormat(int type, byte[] data)
throws IOException {
String typeString = Constants.typeString(type);
String length = String.valueOf(data.length);
return compressStandardFormat(typeString, length, data);
}
private byte[] compressStandardFormat(String type, String length,
byte[] data) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
DeflaterOutputStream d = new DeflaterOutputStream(out);
d.write(Constants.encodeASCII(type));
d.write(' ');
d.write(Constants.encodeASCII(length));
d.write(0);
d.write(data);
d.finish();
return out.toByteArray();
}
private byte[] compressPackFormat(int type, byte[] data) throws IOException {
byte[] hdr = new byte[64];
int rawLength = data.length;
int nextLength = rawLength >>> 4;
hdr[0] = (byte) ((nextLength > 0 ? 0x80 : 0x00) | (type << 4) | (rawLength & 0x0F));
rawLength = nextLength;
int n = 1;
while (rawLength > 0) {
nextLength >>>= 7;
hdr[n++] = (byte) ((nextLength > 0 ? 0x80 : 0x00) | (rawLength & 0x7F));
rawLength = nextLength;
}
final ByteArrayOutputStream out = new ByteArrayOutputStream();
out.write(hdr, 0, n);
DeflaterOutputStream d = new DeflaterOutputStream(out);
d.write(data);
d.finish();
return out.toByteArray();
}
private File path(ObjectId id) {
return repo.getObjectDatabase().fileFor(id);
}
private void write(ObjectId id, byte[] data) throws IOException {
File path = path(id);
path.getParentFile().mkdirs();
FileOutputStream out = new FileOutputStream(path);
try {
out.write(data);
} finally {
out.close();
}
}
}

19
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/WindowCacheGetTest.java → org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/WindowCacheGetTest.java

@ -41,7 +41,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.eclipse.jgit.lib;
package org.eclipse.jgit.storage.file;
import java.io.BufferedReader;
import java.io.FileInputStream;
@ -51,6 +51,10 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.SampleDataRepositoryTestCase;
import org.eclipse.jgit.util.JGitTestUtil;
import org.eclipse.jgit.util.MutableInteger;
@ -73,9 +77,9 @@ public class WindowCacheGetTest extends SampleDataRepositoryTestCase {
final TestObject o = new TestObject();
o.id = ObjectId.fromString(parts[0]);
o.setType(parts[1]);
o.rawSize = Integer.parseInt(parts[2]);
// parts[2] is the inflate size
// parts[3] is the size-in-pack
o.offset = Long.parseLong(parts[4]);
// parts[4] is the offset in the pack
toLoad.add(o);
}
} finally {
@ -122,12 +126,9 @@ public class WindowCacheGetTest extends SampleDataRepositoryTestCase {
private void doCacheTests() throws IOException {
for (final TestObject o : toLoad) {
final ObjectLoader or = db.openObject(o.id);
final ObjectLoader or = db.open(o.id, o.type);
assertNotNull(or);
assertTrue(or instanceof PackedObjectLoader);
assertEquals(o.type, or.getType());
assertEquals(o.rawSize, or.getRawSize());
assertEquals(o.offset, ((PackedObjectLoader) or).getObjectOffset());
}
}
@ -136,10 +137,6 @@ public class WindowCacheGetTest extends SampleDataRepositoryTestCase {
int type;
int rawSize;
long offset;
void setType(final String typeStr) throws CorruptObjectException {
final byte[] typeRaw = Constants.encode(typeStr + " ");
final MutableInteger ptr = new MutableInteger();

4
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/WindowCacheReconfigureTest.java → org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/WindowCacheReconfigureTest.java

@ -41,7 +41,9 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.eclipse.jgit.lib;
package org.eclipse.jgit.storage.file;
import org.eclipse.jgit.lib.RepositoryTestCase;
public class WindowCacheReconfigureTest extends RepositoryTestCase {
public void testConfigureCache_PackedGitLimit_0() {

2
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/XInputStream.java → org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/XInputStream.java

@ -41,7 +41,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.eclipse.jgit.lib;
package org.eclipse.jgit.storage.file;
import java.io.BufferedInputStream;
import java.io.EOFException;

228
org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/pack/DeltaIndexTest.java

@ -0,0 +1,228 @@
/*
* Copyright (C) 2010, 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.pack;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
import junit.framework.TestCase;
import org.eclipse.jgit.junit.TestRng;
import org.eclipse.jgit.lib.Constants;
public class DeltaIndexTest extends TestCase {
private TestRng rng;
private ByteArrayOutputStream actDeltaBuf;
private ByteArrayOutputStream expDeltaBuf;
private DeltaEncoder expDeltaEnc;
private byte[] src;
private byte[] dst;
private ByteArrayOutputStream dstBuf;
protected void setUp() throws Exception {
super.setUp();
rng = new TestRng(getName());
actDeltaBuf = new ByteArrayOutputStream();
expDeltaBuf = new ByteArrayOutputStream();
expDeltaEnc = new DeltaEncoder(expDeltaBuf, 0, 0);
dstBuf = new ByteArrayOutputStream();
}
public void testInsertWholeObject_Length12() throws IOException {
src = rng.nextBytes(12);
insert(src);
doTest();
}
public void testCopyWholeObject_Length128() throws IOException {
src = rng.nextBytes(128);
copy(0, 128);
doTest();
}
public void testCopyWholeObject_Length123() throws IOException {
src = rng.nextBytes(123);
copy(0, 123);
doTest();
}
public void testCopyZeros_Length128() throws IOException {
src = new byte[2048];
copy(0, src.length);
doTest();
// The index should be smaller than expected due to the chain
// being truncated. Without truncation we would expect to have
// more than 3584 bytes used.
//
assertEquals(2636, new DeltaIndex(src).getIndexSize());
}
public void testShuffleSegments() throws IOException {
src = rng.nextBytes(128);
copy(64, 64);
copy(0, 64);
doTest();
}
public void testInsertHeadMiddle() throws IOException {
src = rng.nextBytes(1024);
insert("foo");
copy(0, 512);
insert("yet more fooery");
copy(0, 512);
doTest();
}
public void testInsertTail() throws IOException {
src = rng.nextBytes(1024);
copy(0, 512);
insert("bar");
doTest();
}
public void testIndexSize() {
src = rng.nextBytes(1024);
DeltaIndex di = new DeltaIndex(src);
assertEquals(1860, di.getIndexSize());
assertEquals("DeltaIndex[2 KiB]", di.toString());
}
public void testLimitObjectSize_Length12InsertFails() throws IOException {
src = rng.nextBytes(12);
dst = src;
DeltaIndex di = new DeltaIndex(src);
assertFalse(di.encode(actDeltaBuf, dst, src.length));
}
public void testLimitObjectSize_Length130InsertFails() throws IOException {
src = rng.nextBytes(130);
dst = rng.nextBytes(130);
DeltaIndex di = new DeltaIndex(src);
assertFalse(di.encode(actDeltaBuf, dst, src.length));
}
public void testLimitObjectSize_Length130CopyOk() throws IOException {
src = rng.nextBytes(130);
copy(0, 130);
dst = dstBuf.toByteArray();
DeltaIndex di = new DeltaIndex(src);
assertTrue(di.encode(actDeltaBuf, dst, dst.length));
byte[] actDelta = actDeltaBuf.toByteArray();
byte[] expDelta = expDeltaBuf.toByteArray();
assertEquals(BinaryDelta.format(expDelta, false), //
BinaryDelta.format(actDelta, false));
}
public void testLimitObjectSize_Length130CopyFails() throws IOException {
src = rng.nextBytes(130);
copy(0, 130);
dst = dstBuf.toByteArray();
// The header requires 4 bytes for these objects, so a target length
// of 5 is bigger than the copy instruction and should cause an abort.
//
DeltaIndex di = new DeltaIndex(src);
assertFalse(di.encode(actDeltaBuf, dst, 5));
assertEquals(4, actDeltaBuf.size());
}
public void testLimitObjectSize_InsertFrontFails() throws IOException {
src = rng.nextBytes(130);
insert("eight");
copy(0, 130);
dst = dstBuf.toByteArray();
// The header requires 4 bytes for these objects, so a target length
// of 5 is bigger than the copy instruction and should cause an abort.
//
DeltaIndex di = new DeltaIndex(src);
assertFalse(di.encode(actDeltaBuf, dst, 5));
assertEquals(4, actDeltaBuf.size());
}
private void copy(int offset, int len) throws IOException {
dstBuf.write(src, offset, len);
expDeltaEnc.copy(offset, len);
}
private void insert(String text) throws IOException {
insert(Constants.encode(text));
}
private void insert(byte[] text) throws IOException {
dstBuf.write(text);
expDeltaEnc.insert(text);
}
private void doTest() throws IOException {
dst = dstBuf.toByteArray();
DeltaIndex di = new DeltaIndex(src);
di.encode(actDeltaBuf, dst);
byte[] actDelta = actDeltaBuf.toByteArray();
byte[] expDelta = expDeltaBuf.toByteArray();
assertEquals(BinaryDelta.format(expDelta, false), //
BinaryDelta.format(actDelta, false));
assertTrue("delta is not empty", actDelta.length > 0);
assertEquals(src.length, BinaryDelta.getBaseSize(actDelta));
assertEquals(dst.length, BinaryDelta.getResultSize(actDelta));
assertTrue(Arrays.equals(dst, BinaryDelta.apply(src, actDelta)));
}
}

273
org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/pack/DeltaStreamTest.java

@ -0,0 +1,273 @@
/*
* Copyright (C) 2010, 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.pack;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import junit.framework.TestCase;
import org.eclipse.jgit.JGitText;
import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.junit.TestRng;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.util.IO;
public class DeltaStreamTest extends TestCase {
private TestRng rng;
private ByteArrayOutputStream deltaBuf;
private DeltaEncoder deltaEnc;
private byte[] base;
private byte[] data;
private int dataPtr;
private byte[] delta;
protected void setUp() throws Exception {
super.setUp();
rng = new TestRng(getName());
deltaBuf = new ByteArrayOutputStream();
}
public void testCopy_SingleOp() throws IOException {
init((1 << 16) + 1, (1 << 8) + 1);
copy(0, data.length);
assertValidState();
}
public void testCopy_MaxSize() throws IOException {
int max = (0xff << 16) + (0xff << 8) + 0xff;
init(1 + max, max);
copy(1, max);
assertValidState();
}
public void testCopy_64k() throws IOException {
init(0x10000 + 2, 0x10000 + 1);
copy(1, 0x10000);
copy(0x10001, 1);
assertValidState();
}
public void testCopy_Gap() throws IOException {
init(256, 8);
copy(4, 4);
copy(128, 4);
assertValidState();
}
public void testCopy_OutOfOrder() throws IOException {
init((1 << 16) + 1, (1 << 16) + 1);
copy(1 << 8, 1 << 8);
copy(0, data.length - dataPtr);
assertValidState();
}
public void testInsert_SingleOp() throws IOException {
init((1 << 16) + 1, 2);
insert("hi");
assertValidState();
}
public void testInsertAndCopy() throws IOException {
init(8, 512);
insert(new byte[127]);
insert(new byte[127]);
insert(new byte[127]);
insert(new byte[125]);
copy(2, 6);
assertValidState();
}
public void testSkip() throws IOException {
init(32, 15);
copy(2, 2);
insert("ab");
insert("cd");
copy(4, 4);
copy(0, 2);
insert("efg");
assertValidState();
for (int p = 0; p < data.length; p++) {
byte[] act = new byte[data.length];
System.arraycopy(data, 0, act, 0, p);
DeltaStream in = open();
IO.skipFully(in, p);
assertEquals(data.length - p, in.read(act, p, data.length - p));
assertEquals(-1, in.read());
assertTrue("skipping " + p, Arrays.equals(data, act));
}
// Skip all the way to the end should still recognize EOF.
DeltaStream in = open();
IO.skipFully(in, data.length);
assertEquals(-1, in.read());
assertEquals(0, in.skip(1));
// Skip should not open the base as we move past it, but it
// will open when we need to start copying data from it.
final boolean[] opened = new boolean[1];
in = new DeltaStream(new ByteArrayInputStream(delta)) {
@Override
protected long getBaseSize() throws IOException {
return base.length;
}
@Override
protected InputStream openBase() throws IOException {
opened[0] = true;
return new ByteArrayInputStream(base);
}
};
IO.skipFully(in, 7);
assertFalse("not yet open", opened[0]);
assertEquals(data[7], in.read());
assertTrue("now open", opened[0]);
}
public void testIncorrectBaseSize() throws IOException {
init(4, 4);
copy(0, 4);
assertValidState();
DeltaStream in = new DeltaStream(new ByteArrayInputStream(delta)) {
@Override
protected long getBaseSize() throws IOException {
return 128;
}
@Override
protected InputStream openBase() throws IOException {
return new ByteArrayInputStream(base);
}
};
try {
in.read(new byte[4]);
fail("did not throw an exception");
} catch (CorruptObjectException e) {
assertEquals(JGitText.get().baseLengthIncorrect, e.getMessage());
}
in = new DeltaStream(new ByteArrayInputStream(delta)) {
@Override
protected long getBaseSize() throws IOException {
return 4;
}
@Override
protected InputStream openBase() throws IOException {
return new ByteArrayInputStream(new byte[0]);
}
};
try {
in.read(new byte[4]);
fail("did not throw an exception");
} catch (CorruptObjectException e) {
assertEquals(JGitText.get().baseLengthIncorrect, e.getMessage());
}
}
private void init(int baseSize, int dataSize) throws IOException {
base = rng.nextBytes(baseSize);
data = new byte[dataSize];
deltaEnc = new DeltaEncoder(deltaBuf, baseSize, dataSize);
}
private void copy(int offset, int len) throws IOException {
System.arraycopy(base, offset, data, dataPtr, len);
deltaEnc.copy(offset, len);
assertEquals(deltaBuf.size(), deltaEnc.getSize());
dataPtr += len;
}
private void insert(String text) throws IOException {
insert(Constants.encode(text));
}
private void insert(byte[] text) throws IOException {
System.arraycopy(text, 0, data, dataPtr, text.length);
deltaEnc.insert(text);
assertEquals(deltaBuf.size(), deltaEnc.getSize());
dataPtr += text.length;
}
private void assertValidState() throws IOException {
assertEquals("test filled example result", data.length, dataPtr);
delta = deltaBuf.toByteArray();
assertEquals(base.length, BinaryDelta.getBaseSize(delta));
assertEquals(data.length, BinaryDelta.getResultSize(delta));
assertTrue(Arrays.equals(data, BinaryDelta.apply(base, delta)));
byte[] act = new byte[data.length];
DeltaStream in = open();
assertEquals(data.length, in.getSize());
assertEquals(data.length, in.read(act));
assertEquals(-1, in.read());
assertTrue(Arrays.equals(data, act));
}
private DeltaStream open() throws IOException {
return new DeltaStream(new ByteArrayInputStream(delta)) {
@Override
protected long getBaseSize() throws IOException {
return base.length;
}
@Override
protected InputStream openBase() throws IOException {
return new ByteArrayInputStream(base);
}
};
}
}

4
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java

@ -148,12 +148,12 @@ public class BundleWriterTest extends SampleDataRepositoryTestCase {
throws FileNotFoundException, IOException {
final BundleWriter bw;
bw = new BundleWriter(db, NullProgressMonitor.INSTANCE);
bw = new BundleWriter(db);
bw.include(name, ObjectId.fromString(anObjectToInclude));
if (assume != null)
bw.assume(assume);
final ByteArrayOutputStream out = new ByteArrayOutputStream();
bw.writeBundle(out);
bw.writeBundle(NullProgressMonitor.INSTANCE, out);
return out.toByteArray();
}

2
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/IndexPackTest.java

@ -58,10 +58,10 @@ import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.PackFile;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.lib.TextProgressMonitor;
import org.eclipse.jgit.revwalk.RevBlob;
import org.eclipse.jgit.storage.file.PackFile;
import org.eclipse.jgit.util.JGitTestUtil;
import org.eclipse.jgit.util.NB;
import org.eclipse.jgit.util.TemporaryBuffer;

34
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackRefFilterTest.java

@ -56,7 +56,6 @@ import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectDirectory;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.Ref;
@ -64,6 +63,7 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevBlob;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.storage.file.ObjectDirectory;
import org.eclipse.jgit.util.NB;
import org.eclipse.jgit.util.TemporaryBuffer;
@ -176,7 +176,7 @@ public class ReceivePackRefFilterTest extends LocalDiskRepositoryTestCase {
// Verify the only storage of b is our packed delta above.
//
ObjectDirectory od = (ObjectDirectory) src.getObjectDatabase();
assertTrue("has b", od.hasObject(b));
assertTrue("has b", src.hasObject(b));
assertFalse("b not loose", od.fileFor(b).exists());
// Now use b but in a different commit than what is hidden.
@ -255,7 +255,7 @@ public class ReceivePackRefFilterTest extends LocalDiskRepositoryTestCase {
}
public void testUsingHiddenDeltaBaseFails() throws Exception {
final TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(64);
final TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024);
packHeader(pack, 1);
pack.write((Constants.OBJ_REF_DELTA) << 4 | 4);
b.copyRawTo(pack);
@ -292,18 +292,18 @@ public class ReceivePackRefFilterTest extends LocalDiskRepositoryTestCase {
public void testUsingHiddenCommonBlobFails() throws Exception {
// Try to use the 'b' blob that is hidden.
//
TestRepository s = new TestRepository(src);
TestRepository<Repository> s = new TestRepository<Repository>(src);
RevCommit N = s.commit().parent(B).add("q", s.blob("b")).create();
// But don't include it in the pack.
//
final TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(64);
final TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024);
packHeader(pack, 2);
copy(pack, src.openObject(N));
copy(pack,src.openObject(s.parseBody(N).getTree()));
copy(pack, src.open(N));
copy(pack,src.open(s.parseBody(N).getTree()));
digest(pack);
final TemporaryBuffer.Heap inBuf = new TemporaryBuffer.Heap(256);
final TemporaryBuffer.Heap inBuf = new TemporaryBuffer.Heap(1024);
final PacketLineOut inPckLine = new PacketLineOut(inBuf);
inPckLine.writeString(ObjectId.zeroId().name() + ' ' + N.name() + ' '
+ "refs/heads/s" + '\0'
@ -333,19 +333,19 @@ public class ReceivePackRefFilterTest extends LocalDiskRepositoryTestCase {
public void testUsingUnknownBlobFails() throws Exception {
// Try to use the 'n' blob that is not on the server.
//
TestRepository s = new TestRepository(src);
TestRepository<Repository> s = new TestRepository<Repository>(src);
RevBlob n = s.blob("n");
RevCommit N = s.commit().parent(B).add("q", n).create();
// But don't include it in the pack.
//
final TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(64);
final TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024);
packHeader(pack, 2);
copy(pack, src.openObject(N));
copy(pack,src.openObject(s.parseBody(N).getTree()));
copy(pack, src.open(N));
copy(pack,src.open(s.parseBody(N).getTree()));
digest(pack);
final TemporaryBuffer.Heap inBuf = new TemporaryBuffer.Heap(256);
final TemporaryBuffer.Heap inBuf = new TemporaryBuffer.Heap(1024);
final PacketLineOut inPckLine = new PacketLineOut(inBuf);
inPckLine.writeString(ObjectId.zeroId().name() + ' ' + N.name() + ' '
+ "refs/heads/s" + '\0'
@ -373,18 +373,18 @@ public class ReceivePackRefFilterTest extends LocalDiskRepositoryTestCase {
}
public void testUsingUnknownTreeFails() throws Exception {
TestRepository s = new TestRepository(src);
TestRepository<Repository> s = new TestRepository<Repository>(src);
RevCommit N = s.commit().parent(B).add("q", s.blob("a")).create();
RevTree t = s.parseBody(N).getTree();
// Don't include the tree in the pack.
//
final TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(64);
final TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024);
packHeader(pack, 1);
copy(pack, src.openObject(N));
copy(pack, src.open(N));
digest(pack);
final TemporaryBuffer.Heap inBuf = new TemporaryBuffer.Heap(256);
final TemporaryBuffer.Heap inBuf = new TemporaryBuffer.Heap(1024);
final PacketLineOut inPckLine = new PacketLineOut(inBuf);
inPckLine.writeString(ObjectId.zeroId().name() + ' ' + N.name() + ' '
+ "refs/heads/s" + '\0'

4
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java

@ -48,7 +48,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import org.eclipse.jgit.lib.RepositoryConfig;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.SampleDataRepositoryTestCase;
public class TransportTest extends SampleDataRepositoryTestCase {
@ -59,7 +59,7 @@ public class TransportTest extends SampleDataRepositoryTestCase {
@Override
public void setUp() throws Exception {
super.setUp();
final RepositoryConfig config = db.getConfig();
final Config config = db.getConfig();
remoteConfig = new RemoteConfig(config, "test");
remoteConfig.addURI(new URIish("http://everyones.loves.git/u/2"));
transport = null;

4
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/AbstractTreeIteratorTest.java

@ -51,7 +51,7 @@ import junit.framework.TestCase;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.ObjectReader;
public class AbstractTreeIteratorTest extends TestCase {
@ -73,7 +73,7 @@ public class AbstractTreeIteratorTest extends TestCase {
}
@Override
public AbstractTreeIterator createSubtreeIterator(Repository repo)
public AbstractTreeIterator createSubtreeIterator(ObjectReader reader)
throws IncorrectObjectTypeException, IOException {
return null;
}

7
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/EmptyTreeIteratorTest.java

@ -44,6 +44,7 @@
package org.eclipse.jgit.treewalk;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.RepositoryTestCase;
public class EmptyTreeIteratorTest extends RepositoryTestCase {
@ -55,7 +56,8 @@ public class EmptyTreeIteratorTest extends RepositoryTestCase {
public void testCreateSubtreeIterator() throws Exception {
final EmptyTreeIterator etp = new EmptyTreeIterator();
final AbstractTreeIterator sub = etp.createSubtreeIterator(db);
final ObjectReader reader = db.newObjectReader();
final AbstractTreeIterator sub = etp.createSubtreeIterator(reader);
assertNotNull(sub);
assertTrue(sub.first());
assertTrue(sub.eof());
@ -106,7 +108,8 @@ public class EmptyTreeIteratorTest extends RepositoryTestCase {
called[0] = true;
}
};
parent.createSubtreeIterator(db).stopWalk();
final ObjectReader reader = db.newObjectReader();
parent.createSubtreeIterator(reader).stopWalk();
assertTrue(called[0]);
}
}

4
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java

@ -49,6 +49,7 @@ import java.security.MessageDigest;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.util.RawParseUtils;
@ -124,7 +125,8 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
assertFalse(top.eof());
assertEquals(FileMode.TREE.getBits(), top.mode);
final AbstractTreeIterator sub = top.createSubtreeIterator(db);
final ObjectReader reader = db.newObjectReader();
final AbstractTreeIterator sub = top.createSubtreeIterator(reader);
assertTrue(sub instanceof FileTreeIterator);
final FileTreeIterator subfti = (FileTreeIterator) sub;
assertTrue(sub.first());

16
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/NameConflictTreeWalkTest.java

@ -66,8 +66,8 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase {
private static final FileMode EXECUTABLE_FILE = FileMode.EXECUTABLE_FILE;
public void testNoDF_NoGap() throws Exception {
final DirCache tree0 = DirCache.read(db);
final DirCache tree1 = DirCache.read(db);
final DirCache tree0 = db.readDirCache();
final DirCache tree1 = db.readDirCache();
{
final DirCacheBuilder b0 = tree0.builder();
final DirCacheBuilder b1 = tree1.builder();
@ -97,8 +97,8 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase {
}
public void testDF_NoGap() throws Exception {
final DirCache tree0 = DirCache.read(db);
final DirCache tree1 = DirCache.read(db);
final DirCache tree0 = db.readDirCache();
final DirCache tree1 = db.readDirCache();
{
final DirCacheBuilder b0 = tree0.builder();
final DirCacheBuilder b1 = tree1.builder();
@ -128,8 +128,8 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase {
}
public void testDF_GapByOne() throws Exception {
final DirCache tree0 = DirCache.read(db);
final DirCache tree1 = DirCache.read(db);
final DirCache tree0 = db.readDirCache();
final DirCache tree1 = db.readDirCache();
{
final DirCacheBuilder b0 = tree0.builder();
final DirCacheBuilder b1 = tree1.builder();
@ -160,8 +160,8 @@ public class NameConflictTreeWalkTest extends RepositoryTestCase {
}
public void testDF_SkipsSeenSubtree() throws Exception {
final DirCache tree0 = DirCache.read(db);
final DirCache tree1 = DirCache.read(db);
final DirCache tree0 = db.readDirCache();
final DirCache tree1 = db.readDirCache();
{
final DirCacheBuilder b0 = tree0.builder();
final DirCacheBuilder b1 = tree1.builder();

6
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/PostOrderTreeWalkTest.java

@ -86,7 +86,7 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
}
public void testNoPostOrder() throws Exception {
final DirCache tree = DirCache.read(db);
final DirCache tree = db.readDirCache();
{
final DirCacheBuilder b = tree.builder();
@ -115,7 +115,7 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
}
public void testWithPostOrder_EnterSubtree() throws Exception {
final DirCache tree = DirCache.read(db);
final DirCache tree = db.readDirCache();
{
final DirCacheBuilder b = tree.builder();
@ -150,7 +150,7 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
}
public void testWithPostOrder_NoEnterSubtree() throws Exception {
final DirCache tree = DirCache.read(db);
final DirCache tree = db.readDirCache();
{
final DirCacheBuilder b = tree.builder();

30
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTestCase.java

@ -43,6 +43,8 @@
package org.eclipse.jgit.treewalk.filter;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
@ -52,17 +54,17 @@ import org.eclipse.jgit.dircache.DirCacheBuilder;
import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectWriter;
import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.treewalk.TreeWalk;
public class PathSuffixFilterTestCase extends RepositoryTestCase {
public void testNonRecursiveFiltering() throws IOException {
final ObjectWriter ow = new ObjectWriter(db);
final ObjectId aSth = ow.writeBlob("a.sth".getBytes());
final ObjectId aTxt = ow.writeBlob("a.txt".getBytes());
final DirCache dc = DirCache.read(db);
final ObjectInserter odi = db.newObjectInserter();
final ObjectId aSth = odi.insert(OBJ_BLOB, "a.sth".getBytes());
final ObjectId aTxt = odi.insert(OBJ_BLOB, "a.txt".getBytes());
final DirCache dc = db.readDirCache();
final DirCacheBuilder builder = dc.builder();
final DirCacheEntry aSthEntry = new DirCacheEntry("a.sth");
aSthEntry.setFileMode(FileMode.REGULAR_FILE);
@ -73,7 +75,8 @@ public class PathSuffixFilterTestCase extends RepositoryTestCase {
builder.add(aSthEntry);
builder.add(aTxtEntry);
builder.finish();
final ObjectId treeId = dc.writeTree(ow);
final ObjectId treeId = dc.writeTree(odi);
odi.flush();
final TreeWalk tw = new TreeWalk(db);
@ -92,12 +95,12 @@ public class PathSuffixFilterTestCase extends RepositoryTestCase {
}
public void testRecursiveFiltering() throws IOException {
final ObjectWriter ow = new ObjectWriter(db);
final ObjectId aSth = ow.writeBlob("a.sth".getBytes());
final ObjectId aTxt = ow.writeBlob("a.txt".getBytes());
final ObjectId bSth = ow.writeBlob("b.sth".getBytes());
final ObjectId bTxt = ow.writeBlob("b.txt".getBytes());
final DirCache dc = DirCache.read(db);
final ObjectInserter odi = db.newObjectInserter();
final ObjectId aSth = odi.insert(OBJ_BLOB, "a.sth".getBytes());
final ObjectId aTxt = odi.insert(OBJ_BLOB, "a.txt".getBytes());
final ObjectId bSth = odi.insert(OBJ_BLOB, "b.sth".getBytes());
final ObjectId bTxt = odi.insert(OBJ_BLOB, "b.txt".getBytes());
final DirCache dc = db.readDirCache();
final DirCacheBuilder builder = dc.builder();
final DirCacheEntry aSthEntry = new DirCacheEntry("a.sth");
aSthEntry.setFileMode(FileMode.REGULAR_FILE);
@ -116,7 +119,8 @@ public class PathSuffixFilterTestCase extends RepositoryTestCase {
builder.add(bSthEntry);
builder.add(bTxtEntry);
builder.finish();
final ObjectId treeId = dc.writeTree(ow);
final ObjectId treeId = dc.writeTree(odi);
odi.flush();
final TreeWalk tw = new TreeWalk(db);

3
org.eclipse.jgit/META-INF/MANIFEST.MF

@ -9,6 +9,7 @@ Export-Package: org.eclipse.jgit;version="0.9.0",
org.eclipse.jgit.api;version="0.9.0",
org.eclipse.jgit.diff;version="0.9.0",
org.eclipse.jgit.dircache;version="0.9.0",
org.eclipse.jgit.events;version="0.9.0",
org.eclipse.jgit.errors;version="0.9.0",
org.eclipse.jgit.fnmatch;version="0.9.0",
org.eclipse.jgit.ignore;version="0.9.0",
@ -19,6 +20,8 @@ Export-Package: org.eclipse.jgit;version="0.9.0",
org.eclipse.jgit.revplot;version="0.9.0",
org.eclipse.jgit.revwalk;version="0.9.0",
org.eclipse.jgit.revwalk.filter;version="0.9.0",
org.eclipse.jgit.storage.file;version="0.9.0",
org.eclipse.jgit.storage.pack;version="0.9.0",
org.eclipse.jgit.transport;version="0.9.0",
org.eclipse.jgit.treewalk;version="0.9.0",
org.eclipse.jgit.treewalk.filter;version="0.9.0",

4
org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties

@ -127,7 +127,7 @@ duplicateAdvertisementsOf=duplicate advertisements of {0}
duplicateRef=Duplicate ref: {0}
duplicateRemoteRefUpdateIsIllegal=Duplicate remote ref update is illegal. Affected remote name: {0}
duplicateStagesNotAllowed=Duplicate stages not allowed
eitherGIT_DIRorGIT_WORK_TREEmustBePassed=Either GIT_DIR or GIT_WORK_TREE must be passed to Repository constructor
eitherGitDirOrWorkTreeRequired=One of setGitDir or setWorkTree must be called.
emptyPathNotPermitted=Empty path not permitted.
encryptionError=Encryption error: {0}
endOfFileInEscape=End of file in escape
@ -224,6 +224,7 @@ mergeStrategyAlreadyExistsAsDefault=Merge strategy "{0}" already exists as a def
mergeStrategyDoesNotSupportHeads=merge strategy {0} does not support {1} heads to be merged into HEAD
mergeUsingStrategyResultedInDescription=Merge using strategy {0} resulted in: {1}. {2}
missingAccesskey=Missing accesskey.
missingDeltaBase=delta base
missingForwardImageInGITBinaryPatch=Missing forward-image in GIT binary patch
missingObject=Missing {0} {1}
missingPrerequisiteCommits=missing prerequisite commits:
@ -304,6 +305,7 @@ renamesAlreadyFound=Renames have already been found.
renamesFindingByContent=Finding renames by content similarity
renamesFindingExact=Finding exact renames
repositoryAlreadyExists=Repository already exists: {0}
repositoryConfigFileInvalid=Repository config file {0} invalid {1}
repositoryIsRequired=Repository is required.
repositoryNotFound=repository not found: {0}
repositoryState_applyMailbox=Apply mailbox

4
org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java

@ -187,7 +187,7 @@ public class JGitText extends TranslationBundle {
/***/ public String duplicateRef;
/***/ public String duplicateRemoteRefUpdateIsIllegal;
/***/ public String duplicateStagesNotAllowed;
/***/ public String eitherGIT_DIRorGIT_WORK_TREEmustBePassed;
/***/ public String eitherGitDirOrWorkTreeRequired;
/***/ public String emptyPathNotPermitted;
/***/ public String encryptionError;
/***/ public String endOfFileInEscape;
@ -284,6 +284,7 @@ public class JGitText extends TranslationBundle {
/***/ public String mergeStrategyDoesNotSupportHeads;
/***/ public String mergeUsingStrategyResultedInDescription;
/***/ public String missingAccesskey;
/***/ public String missingDeltaBase;
/***/ public String missingForwardImageInGITBinaryPatch;
/***/ public String missingObject;
/***/ public String missingPrerequisiteCommits;
@ -363,6 +364,7 @@ public class JGitText extends TranslationBundle {
/***/ public String renamesFindingByContent;
/***/ public String renamesFindingExact;
/***/ public String repositoryAlreadyExists;
/***/ public String repositoryConfigFileInvalid;
/***/ public String repositoryIsRequired;
/***/ public String repositoryNotFound;
/***/ public String repositoryState_applyMailbox;

4
org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java

@ -127,7 +127,7 @@ public class AddCommand extends GitCommand<DirCache> {
addAll = true;
try {
dc = DirCache.lock(repo);
dc = repo.lockDirCache();
ObjectWriter ow = new ObjectWriter(repo);
DirCacheIterator c;
@ -147,7 +147,7 @@ public class AddCommand extends GitCommand<DirCache> {
while (tw.next()) {
String path = tw.getPathString();
final File file = new File(repo.getWorkDir(), path);
final File file = new File(repo.getWorkTree(), path);
WorkingTreeIterator f = tw.getTree(1, WorkingTreeIterator.class);
if (tw.getTree(0, DirCacheIterator.class) == null &&
f != null && f.isEntryIgnored()) {

58
org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java

@ -54,13 +54,13 @@ import org.eclipse.jgit.errors.UnmergedPathException;
import org.eclipse.jgit.lib.Commit;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectWriter;
import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
@ -139,14 +139,14 @@ public class CommitCommand extends GitCommand<RevCommit> {
parents.add(0, headId);
// lock the index
DirCache index = DirCache.lock(repo);
DirCache index = repo.lockDirCache();
try {
ObjectWriter repoWriter = new ObjectWriter(repo);
// Write the index as tree to the object database. This may fail
// for example when the index contains unmerged pathes
ObjectInserter odi = repo.newObjectInserter();
try {
// Write the index as tree to the object database. This may
// fail for example when the index contains unmerged paths
// (unresolved conflicts)
ObjectId indexTreeId = index.writeTree(repoWriter);
ObjectId indexTreeId = index.writeTree(odi);
// Create a Commit object, populate it and write it
Commit commit = new Commit(repo);
@ -156,37 +156,49 @@ public class CommitCommand extends GitCommand<RevCommit> {
commit.setParentIds(parents.toArray(new ObjectId[] {}));
commit.setTreeId(indexTreeId);
ObjectId commitId = repoWriter.writeCommit(commit);
ObjectId commitId = odi.insert(Constants.OBJ_COMMIT, odi
.format(commit));
odi.flush();
RevCommit revCommit = new RevWalk(repo).parseCommit(commitId);
RevWalk revWalk = new RevWalk(repo);
try {
RevCommit revCommit = revWalk.parseCommit(commitId);
RefUpdate ru = repo.updateRef(Constants.HEAD);
ru.setNewObjectId(commitId);
ru.setRefLogMessage("commit : " + revCommit.getShortMessage(),
false);
ru.setRefLogMessage("commit : "
+ revCommit.getShortMessage(), false);
ru.setExpectedOldObjectId(headId);
Result rc = ru.update();
switch (rc) {
case NEW:
case FAST_FORWARD:
case FAST_FORWARD: {
setCallable(false);
if (state == RepositoryState.MERGING_RESOLVED) {
File meta = repo.getDirectory();
if (state == RepositoryState.MERGING_RESOLVED
&& meta != null) {
// Commit was successful. Now delete the files
// used for merge commits
new File(repo.getDirectory(), Constants.MERGE_HEAD)
.delete();
new File(repo.getDirectory(), Constants.MERGE_MSG)
.delete();
new File(meta, Constants.MERGE_HEAD).delete();
new File(meta, Constants.MERGE_MSG).delete();
}
return revCommit;
}
case REJECTED:
case LOCK_FAILURE:
throw new ConcurrentRefUpdateException(
JGitText.get().couldNotLockHEAD, ru.getRef(), rc);
throw new ConcurrentRefUpdateException(JGitText
.get().couldNotLockHEAD, ru.getRef(), rc);
default:
throw new JGitInternalException(MessageFormat.format(
JGitText.get().updatingRefFailed
, Constants.HEAD, commitId.toString(), rc));
throw new JGitInternalException(MessageFormat
.format(JGitText.get().updatingRefFailed,
Constants.HEAD,
commitId.toString(), rc));
}
} finally {
revWalk.release();
}
} finally {
odi.release();
}
} finally {
index.unlock();

6
org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java

@ -119,6 +119,7 @@ public class MergeCommand extends GitCommand<MergeResult> {
// Check for FAST_FORWARD, ALREADY_UP_TO_DATE
RevWalk revWalk = new RevWalk(repo);
try {
RevCommit headCommit = revWalk.lookupCommit(head.getObjectId());
Ref ref = commits.get(0);
@ -151,6 +152,9 @@ public class MergeCommand extends GitCommand<MergeResult> {
mergeStrategy,
JGitText.get().onlyAlreadyUpToDateAndFastForwardMergesAreAvailable);
}
} finally {
revWalk.release();
}
} catch (IOException e) {
throw new JGitInternalException(
MessageFormat.format(
@ -163,7 +167,7 @@ public class MergeCommand extends GitCommand<MergeResult> {
RevCommit newHeadCommit) throws IOException, CheckoutConflictException {
GitIndex index = repo.getIndex();
File workDir = repo.getWorkDir();
File workDir = repo.getWorkTree();
if (workDir != null) {
WorkDirCheckout workDirCheckout = new WorkDirCheckout(repo,
workDir, headCommit.asCommit(revWalk).getTree(), index,

47
org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java

@ -50,20 +50,24 @@ import static org.eclipse.jgit.lib.FileMode.GITLINK;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import org.eclipse.jgit.JGitText;
import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.errors.LargeObjectException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.AbbreviatedObjectId;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.CoreConfig;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.patch.FileHeader;
import org.eclipse.jgit.patch.HunkHeader;
import org.eclipse.jgit.patch.FileHeader.PatchType;
import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.QuotedString;
import org.eclipse.jgit.util.io.DisabledOutputStream;
@ -83,6 +87,8 @@ public class DiffFormatter {
private RawText.Factory rawTextFactory = RawText.FACTORY;
private long bigFileThreshold = 50 * 1024 * 1024;
/**
* Create a new formatter with a default level of context.
*
@ -110,6 +116,9 @@ public class DiffFormatter {
*/
public void setRepository(Repository repository) {
db = repository;
CoreConfig cfg = db.getConfig().get(CoreConfig.KEY);
bigFileThreshold = cfg.getStreamFileThreshold();
}
/**
@ -157,6 +166,19 @@ public class DiffFormatter {
rawTextFactory = type;
}
/**
* Set the maximum file size that should be considered for diff output.
* <p>
* Text files that are larger than this size will not have a difference
* generated during output.
*
* @param bigFileThreshold
* the limit, in bytes.
*/
public void setBigFileThreshold(long bigFileThreshold) {
this.bigFileThreshold = bigFileThreshold;
}
/**
* Flush the underlying output stream of this formatter.
*
@ -318,9 +340,32 @@ public class DiffFormatter {
if (db == null)
throw new IllegalStateException(JGitText.get().repositoryIsRequired);
if (id.isComplete()) {
ObjectLoader ldr = db.openObject(id.toObjectId());
ObjectLoader ldr = db.open(id.toObjectId());
if (!ldr.isLarge())
return ldr.getCachedBytes();
long sz = ldr.getSize();
if (sz < bigFileThreshold && sz < Integer.MAX_VALUE) {
byte[] buf;
try {
buf = new byte[(int) sz];
} catch (OutOfMemoryError noMemory) {
LargeObjectException e;
e = new LargeObjectException(id.toObjectId());
e.initCause(noMemory);
throw e;
}
InputStream in = ldr.openStream();
try {
IO.readFully(in, buf, 0, buf.length);
} finally {
in.close();
}
return buf;
}
}
return new byte[] {};

8
org.eclipse.jgit/src/org/eclipse/jgit/diff/RenameDetector.java

@ -57,6 +57,7 @@ import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.lib.AbbreviatedObjectId;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.lib.Repository;
@ -294,14 +295,19 @@ public class RenameDetector {
return;
if (getRenameLimit() == 0 || cnt <= getRenameLimit()) {
ObjectReader reader = repo.newObjectReader();
try {
SimilarityRenameDetector d;
d = new SimilarityRenameDetector(repo, deleted, added);
d = new SimilarityRenameDetector(reader, deleted, added);
d.setRenameScore(getRenameScore());
d.compute(pm);
deleted = d.getLeftOverSources();
added = d.getLeftOverDestinations();
entries.addAll(d.getMatches());
} finally {
reader.release();
}
} else {
overRenameLimit = true;
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save