aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
Commit message (Collapse)AuthorAgeFilesLines
* Externalize strings from JGitSasa Zivkov2010-05-195-16/+23
| | | | | | | | | | | | | | | The strings are externalized into the root resource bundles. The resource bundles are stored under the new "resources" source folder to get proper maven build. Strings from tests are, in general, not externalized. Only in cases where it was necessary to make the test pass the strings were externalized. This was typically necessary in cases where e.getMessage() was used in assert and the exception message was slightly changed due to reuse of the externalized strings. Change-Id: Ic0f29c80b9a54fcec8320d8539a3e112852a1f7b Signed-off-by: Sasa Zivkov <sasa.zivkov@sap.com>
* Reduce size of PackedObjectLoader by dropping long to intShawn O. Pearce2010-05-151-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | Rather than keep track of both the position of the object, and the position of its data, just keep track of the number of bytes used by the object's header in the pack. This shaves 4 bytes out of the size of the PackedObjectLoader instances. We also can defer the addition instruction to the materialize() operation, avoiding it entirely if the caller never actually uses the loader. This may be relevant for PackWriter invocations, where only 1 loader gets chosen for a given object, even though the object may appear on disk in more than one pack file. Error reporting is now simplified, as we can rely on the object offset rather than its data offset. This is the value displayed by pack debugging tools like `git verify-pack -v`, so its better to use that in our own errors. Because nobody needs getDataOffset() now, we can drop that from the public API. Change-Id: Ic639c0d5a722315f4f5c8ffda6e26643d90e5f42 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* Add builder-style API to jgit and Commit & Log cmdChristian Halstrick2010-05-101-0/+117
| | | | | | | | | | | | | | | | | Added a new package org.eclipse.jgit.api and a builder-style API for jgit. Added also the first implementation for two git commands: Commit and Log. This API is intended to be used by external components when functionalities of the standard git commands are required. It will also help to ease writing JGit tests. For internal usages this API may often not be optimal because the git commands are doing much more than required or they expect parameters of an unappropriate type. Change-Id: I71ac4839ab9d2f848307eba9252090c586b4146b Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
* Added MERGING_RESOLVED repository stateChristian Halstrick2010-05-081-0/+20
| | | | | | | | | | | | | | | | | | | | | | | | | The repository state tells in which state the repo is and also which actions are currently allowed. The state MERGING is telling that a commit is not possible. But this is only true in the case of unmerged paths in the index. When we are merging but have resolved all conflicts then we are in a special state: We are still merging (means the next commit should have multiple parents) but a commit is now allowed. Since the MERGING state "canCommit()" cannot be enhanced to return true/false based on the index state (MERGING is an enum value which does not have a reference to the repository its state it is representing) I had to introduce a new state MERGING_RESOLVED. This new state will report that a commit is possible. CAUTION: there might be the chance that users of jgit previously blindly did a plain commit (with only one parent) when the RepositoryState allowed them to do so. With this change these users will now be confronted with a RepositoryState which says a commit is possible but before they can commit they'll have to check the MERGE_MESSAGE and MERGE_HEAD files and use the info from these files. Change-Id: I0a885e2fe8c85049fb23722351ab89cf2c81a431 Signed-off-by: Christian Halstrick <christian.halstrick@sap.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* Fix FooterLine.matches(FooterKey) on same length keysShawn O. Pearce2010-05-041-0/+20
| | | | | | | | | | | | | | If two keys are the same length, but don't share the same sequence of characters, we were incorrectly claiming they still matched due to a bug in the for loop condition. I used the wrong variable and the loop never executed, resulting in equality anytime the two keys being compared were the same length. Use the proper local variable to loop through the arrays, and add a JUnit test to verify equality works as expected. Change-Id: I4a02400e65a9b2e0da925b05a2cc4b579e1dd33a Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* Fix ReceivePackRefFilterTest on WindowsShawn O. Pearce2010-04-271-0/+9
| | | | | | | | | | | | The pack files were left open after the test ended, which meant we could not delete them automatically when the test was over. Make sure we close the repositories (and thus their underlying packs) before the tear down finishes. Bug: 310367 Change-Id: I4d2703efa4b2e0c347ea4f4475777899cf71073e Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* ReceivePack: Clarify the check reachable optionShawn O. Pearce2010-04-161-6/+6
| | | | | | | | | | | | | | | | | | | This option was mis-named from day 1. Its not checking that the objects provided by the client are reachable, its actually doing a scan to prove that objects referenced by the client are already reachable through another reference on the server, or were sent as part of the pack from the client. Rename it checkReferencedObjectsAreReachable, since we really are trying to validate that objects referenced by the client's actions are reachable to the client. We also need to ensure we run checkConnectivity() anytime this is enabled, even if the caller didn't turn on fsck for object formats. Otherwise the check would be completely bypassed. Change-Id: Ic352ddb0ca8464d407c6da5c83573093e018af19 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* ReceivePack: fix ensureProvidedObjectsVisible on thin packsShawn O. Pearce2010-04-161-0/+477
| | | | | | | | | | | | | | | | If ensureProvidedObjectsVisible is enabled we expected any trees or blobs directly reachable from an advertised reference to be marked with UNINTERESTING. Unfortunately ObjectWalk doesn't bother setting this until the traversal is complete. Even then it won't necessarily set it on every tree if the corresponding commit wasn't popped. When we are going to check the base objects for the received pack, ensure the UNINTERESTING flag gets carried into every immediately reachable tree or blob, because these are the ones that the client might try to use as delta bases in a thin pack. Change-Id: I5d5fdcf07e25ac9fc360e79a25dff491925e4101 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* IndexPack: Correct thin pack fix using less than 20 bytesShawn O. Pearce2010-04-161-0/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | | If we need to append less than 20 bytes in order to fix a thin pack and make it complete, we need to set the length of our file back to the actual number of bytes used because the original SHA-1 footer was not completely overwritten. That extra data will confuse the header and footer fixup logic when it tries to read to the end of the file. This isn't a very common case to occur, which is why we've never seen it before. Getting a delta that requires a whole object which uses less than 20 bytes in pack representation is really hard. Generally a delta generator won't make these, because the delta would be bigger than simply deflating the whole object. I only managed to do this with a hand-crafted pack file where a 1 byte delta was pointed to a 1 byte whole object. Normally we try really hard to avoid truncating, because its typically not safe across network filesystems. But the odds of this occurring are very low. This truncation is done on a file we have open for writing, will append more content onto, and is a temporary file that we won't move into position for others to see until we've validated its SHA-1 is sane. I don't think the truncate on NFS issue is something we need to worry about here. Change-Id: I102b9637dfd048dc833c050890d142f43c1e75ae Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* Make parsing of PersonIdent from raw byte array fault-tolerant.Marc Strapetz2010-03-231-0/+100
| | | | | | RawParseUtils.parsePersonIdent handles now those invalid byte sequences which would result in IndexOutOfBoundsException and returns null in this case.
* Merge branch 'push-sideband' into stable-0.7Shawn O. Pearce2010-03-123-47/+112
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * push-sideband: Reuse the line buffer between strings in PacketLineIn http.server: Use TemporaryBuffer and compress some responses Reduce multi-level buffered streams in transport code Fix smart HTTP client buffer alignment Use "ERR message" for early ReceivePack problems Catch and report "ERR message" during remote advertisements Wait for EOF on stderr before finishing SSH channel Capture non-progress side band #2 messages and put in result ReceivePack: Enable side-band-64k capability for status reports Use more restrictive patterns for sideband progress scraping Prefix remote progress tasks with "remote: " Decode side-band channel number as unsigned integer Refactor SideBandInputStream construction Refactor SideBandOutputStream to be buffered Change-Id: Ic9689e64e8c87971f2fd402cb619082309d5587f
| * Reduce multi-level buffered streams in transport codeShawn O. Pearce2010-03-121-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some transports actually provide stream buffering on their own, without needing to be wrapped up inside of a BufferedInputStream in order to smooth out system calls to read or write. A great example of this is the JSch SSH client, or the Apache MINA SSHD server. Both use custom buffering to packetize the streams into the encrypted SSH channel, and wrapping them up inside of a BufferedInputStream or BufferedOutputStream is relatively pointless. Our SideBandOutputStream implementation also provides some fairly large buffering, equal to one complete side-band packet on the main data channel. Wrapping that inside of a BufferedOutputStream just to smooth out small writes from PackWriter causes extra data copies, and provides no advantage. We can save some memory and some CPU cycles by letting PackWriter dump directly into the SideBandOutputStream's internal buffer array. Instead we push the buffering streams down to be as close to the network socket (or operating system pipe) as possible. This allows us to smooth out the smaller reads/writes from pkt-line messages during advertisement and negotation, but avoid copying altogether when the stream switches to larger writes over a side band channel. Change-Id: I2f6f16caee64783c77d3dd1b2a41b3cc0c64c159 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
| * Refactor SideBandOutputStream to be bufferedShawn O. Pearce2010-03-122-43/+106
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Instead of relying on our callers to wrap us up inside of a BufferedOutputStream and using the proper block sizing, do the buffering directly inside of SideBandOutputStream. This ensures we don't get large write-throughs from BufferedOutputStream that might overflow the configured packet size. The constructor of SideBandOutputStream is also beefed up to check its arguments and ensure they are within acceptable ranges for the current side-band protocol. Change-Id: Ic14567327d03c9e972f9734b8228178bc448867d Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* | Fix NLS to build under Java 5Shawn O. Pearce2010-03-122-17/+17
| | | | | | | | | | | | | | | | | | The tests were using a Locale.ROOT constant which was introduced in Java 6. However, we need to retain Java 5 support. Change-Id: I75c5648fcfc728a9aea2e839d2ad0320f5cf742f Signed-off-by: Shawn O. Pearce <spearce@spearce.org> CC: Sasa Zivkov <sasa.zivkov@sap.com>
* | Provide NLS support in JGit.Sasa Zivkov2010-03-1110-0/+462
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The support for NLS relies on java.util API to load a standard ResourceBundle and then uses java reflection API to inject localized strings into public String fields of the corresponding instance of TranslationBundle. Locale setting is supported per thread to enable concurrent threads to use different locales. This is useful when JGit runs in a server context where (error) messages might need to differ per-request to suit the user's preference. Change-Id: Ie0e63a0d7bb74eaad495dbe8248595d8a3a76883 Signed-off-by: Sasa Zivkov <sasa.zivkov@sap.com>
* | Fix TimeoutInputStreamTest, TimeoutOutputStreamTest assertionsShawn O. Pearce2010-02-102-4/+4
|/ | | | | | | | | | If the build server is really busy, we might wait longer than 250 ms before being interrupted, simply because one of our threads couldn't be scheduled onto a CPU. Don't make that cause a test failure. Instead tolerate longer than expected waits, but not shorter waits. Change-Id: I64511eec24b49e33928451e4c8b8c124eddaf0c2 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* Don't allow DirCacheEntry with mode of 0Shawn O. Pearce2010-02-037-14/+213
| | | | | | | | | | | | | | | | | | | | | | | A 0 file mode in a DirCacheEntry is not a valid mode. To C git such a value indicates the record should not be present. We already were catching this bad state and exceptioning out when writing tree objects to disk, but we did not fail when writing the dircache back to disk. This allowed JGit applications to create a dircache file which C git would not like to read. Instead of checking the mode during writes, we now check during mutation. This allows application bugs to be detected sooner and closer to the cause site. It also allows us to avoid checking most of the records which we read in from disk, as we can assume these are formatted correctly. Some of our unit tests were not setting the FileMode on their test entry, so they had to be updated to use REGULAR_FILE. Change-Id: Ie412053c390b737c0ece57b8e063e4355ee32437 Originally: http://thread.gmane.org/gmane.comp.version-control.git/128214/focus=128213 Signed-off-by: Shawn O. Pearce <spearce@spearce.org> CC: Adam W. Hawks <awhawks@writeme.com>
* Fix ObjectWalk corruption when skipping over empty treesShawn O. Pearce2010-02-021-0/+44
| | | | | | | | | | | | | | | | | | | The supplied test case comes out of the example tree identified by Robert de Wilde and Ilari on #git: $ git ls-tree -rt a54f1a85ebf6a7f53aa60a45a1be33f8b078fb7e 040000 tree bfe058ad536cdb12e127cde63b01472c960ea105 A 040000 tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 A/A 040000 tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 A/B 100644 blob abbbfafe3129f85747aba7bfac992af77134c607 B In this tree, "B" was being skipped because "A/A" as an empty tree was immediately followed by "A/B", also an empty tree, but the ObjectWalk broke out too early and never visited "B". Bug: 286653 Change-Id: I25bcb0bc99d0cbbbdd9c2bd625ad6a691a6d0335 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* Correctly skip over unrecognized optional dircache extensionsShawn O. Pearce2010-02-021-0/+29
| | | | | | | | | | | | | | | | | | | We didn't skip the correct number of bytes when we skipped over an unrecognized but optional dircache extension. We missed skipping the 8 byte header that makes up the extension's name and length. We also didn't include the skipped extension's payload as part of our index checksum, resuting in a checksum failure when the index was done reading. So ensure we always scan through a skipped section and include it in the checksum computation. Add a test case for a currently unsupported index extension, 'ZZZZ', to verify we can still read the DirCache object even though we don't know what 'ZZZZ' is supposed to mean. Bug: 301287 Change-Id: I4bdde94576fffe826d0782483fd98cab1ea628fa Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* Remove RepositoryTestCase from DirCacheCGitCompatabilityTestShawn O. Pearce2010-02-021-3/+5
| | | | | | | | | This test doesn't actually depend upon the large data set we have in the RepositoryTestCase, so drop that from the dependency and use the more simple LocalDiskRepositoryTestCase instead. Change-Id: I0fd4affe1dd5ec86e8c3253db42df11d3b612e36 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* Merge "Add unsetSection to Config to remove an entire block"Robin Rosenberg2010-01-281-0/+41
|\
| * Add unsetSection to Config to remove an entire blockShawn O. Pearce2010-01-291-0/+41
| | | | | | | | | | | | | | | | | | The unsetSection method can be used to delete an entire configuration block, such as a [branch ""] or [remote ""] section in a file. Change-Id: I93390c9b2187eb1b0d51353518feaed83bed2aad Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
* | Merge "Relax ObjectChecker to permit missing tagger lines"Robin Rosenberg2010-01-282-29/+49
|\ \ | |/ |/|
| * Relax ObjectChecker to permit missing tagger linesShawn O. Pearce2010-01-232-29/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Annotated tags created with C Git versions before the introduction of c818566 ([PATCH] Update tags to record who made them, 2005-07-14), do not have a "tagger" line present in the object header. This line did not appear in C Git until v0.99.1~9. Ancient projects such as the Linux kernel contain such tags, for example Linux 2.6.12 is older than when this feature first appeared in C Git. Linux v2.6.13-rc4 in late July 2005 is the first kernel version tag to actually contain a tagger line. It is therefore acceptable for the header to be missing, and for the RevTag.getTaggerIdent() method to return null. Since the Javadoc for getTaggerIdent() already explained that the identity may be null, we just need to test that this is true when the header is missing, and allow the ObjectChecker to pass anyway. Change-Id: I34ba82e0624a0d1a7edcf62ffba72260af6f7e5d See: http://code.google.com/p/gerrit/issues/detail?id=399 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* | Don't confuse empty configuration variables with booleansShawn O. Pearce2010-01-231-1/+30
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | Config was confusing the following two variables when writing the file back to text format: [my] empty = enabled When parsed, we say that my.empty has 1 value, null, and my.enabled is an empty string value that in boolean context should be evaluated as true. Saving this configuration file back to text format was ignoring the null value for my.empty, producing a completely different file than what Config read: [my] empty enabled Instead handle the writing differently to ensure the original format is output. New tests cases cover the expected behavior and return values from accessor methods. Change-Id: Id37379ce20cb27e3330923cf989444dd9f2bdd96 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* Merge branch 'ref-abstract'Shawn O. Pearce2010-01-2311-90/+2328
|\ | | | | | | | | | | | | | | | | | | | | * ref-abstract: Optimize RefAdvertiser performance by avoiding sorting branch: Add -m option to rename a branch Replace writeSymref with RefUpdate.link Rewrite reference handling to be abstract and accurate Create new RefList and RefMap utility types Change-Id: If43aacf5aa4013edbd0a6e84d84c4f9e94de5be0
| * Replace writeSymref with RefUpdate.linkShawn O. Pearce2010-01-232-12/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | By using RefUpdate for symbolic reference creation we can reuse the logic related to updating the reflog with the event, without needing to expose something such as the legacy ReflogWriter class (which we no longer have). Applications using writeSymref must update their code to use the new pattern of changing the reference through the updateRef method: String refName = "refs/heads/master"; RefUpdate u = repository.updateRef(Constants.HEAD); u.setRefLogMessage("checkout: moving to " + refName, false); switch (u.link(refName)) { case NEW: case FORCED: case NO_CHANGE: // A successful update of the reference break; default: // Handle the failure, e.g. for older behavior throw new IOException(u.getResult()); } Change-Id: I1093e1ec2970147978a786cfdd0a75d0aebf8010 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
| * Rewrite reference handling to be abstract and accurateShawn O. Pearce2010-01-2311-81/+1481
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit actually does three major changes to the way references are handled within JGit. Unfortunately they were easier to do as a single massive commit than to break them up into smaller units. Disambiguate symbolic references: --------------------------------- Reporting a symbolic reference such as HEAD as though it were any other normal reference like refs/heads/master causes subtle programming errors. We have been bitten by this error on several occasions, as have some downstream applications written by myself. Instead of reporting HEAD as a reference whose name differs from its "original name", report it as an actual SymbolicRef object that the application can test the type and examine the target of. With this change, Ref is now an abstract type with different subclasses for the different types. In the classical example of "HEAD" being a symbolic reference to branch "refs/heads/master", the Repository.getAllRefs() method will now return: Map<String, Ref> all = repository.getAllRefs(); SymbolicRef HEAD = (SymbolicRef) all.get("HEAD"); ObjectIdRef master = (ObjectIdRef) all.get("refs/heads/master"); assertSame(master, HEAD.getTarget()); assertSame(master.getObjectId(), HEAD.getObjectId()); assertEquals("HEAD", HEAD.getName()); assertEquals("refs/heads/master", master.getName()); A nice side-effect of this change is the storage type of the symbolic reference is no longer ambiguous with the storge type of the underlying reference it targets. In the above example, if master was only available in the packed-refs file, then the following is also true: assertSame(Ref.Storage.LOOSE, HEAD.getStorage()); assertSame(Ref.Storage.PACKED, master.getStorage()); (Prior to this change we returned the ambiguous storage of LOOSE_PACKED for HEAD, which was confusing since it wasn't actually true on disk). Another nice side-effect of this change is all intermediate symbolic references are preserved, and are therefore visible to the application when they walk the target chain. We can now correctly inspect chains of symbolic references. As a result of this change the Ref.getOrigName() method has been removed from the API. Applications should identify a symbolic reference by testing for isSymbolic() and not by using an arcane string comparsion between properties. Abstract the RefDatabase storage: --------------------------------- RefDatabase is now abstract, similar to ObjectDatabase, and a new concrete implementation called RefDirectory is used for the traditional on-disk storage layout. In the future we plan to support additional implementations, such as a pure in-memory RefDatabase for unit testing purposes. Optimize RefDirectory: ---------------------- The implementation of the in-memory reference cache, reading, and update routines has been completely rewritten. Much of the code was heavily borrowed or cribbed from the prior implementation, so copyright notices have been left intact as much as possible. The RefDirectory cache no longer confuses symbolic references with normal references. This permits the cache to resolve the value of a symbolic reference as late as possible, ensuring it is always current, without needing to maintain reverse pointers. The cache is now 2 sorted RefLists, rather than 3 HashMaps. Using sorted lists allows the implementation to reduce the in-memory footprint when storing many refs. Using specialized types for the elements allows the code to avoid additional map lookups for auxiliary stat information. To improve scan time during getRefs(), the lists are returned via a copy-on-write contract. Most callers of getRefs() do not modify the returned collections, so the copy-on-write semantics improves access on repositories with a large number of packed references. Iterator traversals of the returned Map<String,Ref> are performed using a simple merge-join of the two cache lists, ensuring we can perform the entire traversal in linear time as a function of the number of references: O(PackedRefs + LooseRefs). Scans of the loose reference space to update the cache run in O(LooseRefs log LooseRefs) time, as the directory contents are sorted before being merged against the in-memory cache. Since the majority of stable references are kept packed, there typically are only a handful of reference names to be sorted, so the sorting cost should not be very high. Locking is reduced during getRefs() by taking advantage of the copy-on-write semantics of the improved cache data structure. This permits concurrent readers to pull back references without blocking each other. If there is contention updating the cache during a scan, one or more updates are simply skipped and will get picked up again in a future scan. Writing to the $GIT_DIR/packed-refs during reference delete is now fully atomic. The file is locked, reparsed fresh, and written back out if a change is necessary. This avoids all race conditions with concurrent external updates of the packed-refs file. The RefLogWriter class has been fully folded into RefDirectory and is therefore deleted. Maintaining the reference's log is the responsiblity of the database implementation, and not all implementations will use java.io for access. Future work still remains to be done to abstract the ReflogReader class away from local disk IO. Change-Id: I26b9287c45a4b2d2be35ba2849daa316f5eec85d Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
| * Create new RefList and RefMap utility typesShawn O. Pearce2010-01-222-0/+813
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These types can be used by RefDatabase implementations to manage the collection. A RefList stores items sorted by their name, and is an immutable type using copy-on-write semantics to perform modifications to the collection. Binary search is used to locate an existing item by name, or to locate the proper insertion position if an item does not exist. A RefMap can merge up to 3 RefList collections at once during its entry iteration, allowing items in the resolved or loose RefList to override items by the same name in the packed RefList. The RefMap's goal is O(log N) lookup time, and O(N) iteration time, which is suitable for returning from a RefDatabase. By relying on the immutable RefList we might be able to make map construction nearly constant, making Repository.getAllRefs() an inexpensive operation if the caches are current. Since modification is not common, changes require up to O(N + log N) time to copy the internal list and collapse or expand the list's array. As most changes are made to the loose collection and not the packed collection, in practice most changes would require less than the full O(N) time, due to a significantly smaller N in the loose list. Almost complete test coverage is included in the corresponding unit tests. A handful of methods on RefMap are not tested in this change, as writing the proper test depends on a future refactoring of how the Ref class represents symbolic reference names. Change-Id: Ic2095274000336556f719edd75a5c5dd6dd1d857 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* | Introduce a named constant for the .git directory.Robin Rosenberg2010-01-151-14/+14
|/ | | | | | | | | | | Not all occurrences of ".git" are replaced by this constant, only those where it actually refers to the directory with that name, i.e not the ".git" directory suffix. Asserts and comment are also excluded from replacement. Change-Id: I65a9da89aedd53817f2ea3eaab4f9c2bed35d7ee Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
* Refactor TemporaryBuffer to support reuse in other contextsShawn O. Pearce2010-01-121-13/+25
| | | | | | | | | | | | | | | | Later we are going to add support for smart HTTP, which requires us to buffer at least some of the request created by a client before we ship it to the server. For many requests, we can fit it completely into a 1 MiB buffer, but if it doesn't we can drop back to using the chunked transfer encoding to send an unknown stream length. Rather than recoding the block based memory buffer, we refactor the local file overflow strategy into a subclass, allowing the HTTP client code to replace this portion of the logic with its own approach to start the chunked encoding request. Change-Id: Iac61ea1017b14e0ad3c4425efc3d75718b71bb8e Signed-off-by: Shawn O. Pearce <sop@google.com>
* Implement multi_ack_detailed protocol extensionShawn O. Pearce2010-01-121-0/+33
| | | | | | | | | | The multi_ack_detailed extension breaks out the "ACK %s continue" status code into "ACK %s common" and "ACK %s ready" states, making it easier to discover which objects are truely common, and which objects are simply on a chain the server doesn't care learning about. Change-Id: Ie8e907424cfbbba84996ca205d49eacf339f9d04 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* Abstract out utility functions for creating test commitsShawn O. Pearce2010-01-128-102/+54
| | | | | | | | | These routines create a fairly clean DSL for writing out the structure of a repository in a test case. Abstract them into a helper class that we can reuse in other test environments. Change-Id: I55cce3d557e1a28afe2fdf37b3a5b67e2651c9f1 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* Move TestRng to our JUnit helper packageShawn O. Pearce2010-01-122-67/+2
| | | | | | | | Other test suites may find this useful, especially when trying to defeat the pack file compression with random data files. Change-Id: Ic00a4ac626af7a1c94d18ee99305e295b267b1a3 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* Merge branch 'cq-diff'Shawn O. Pearce2010-01-066-0/+714
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Per CQ 3559 "JGit - Eugene Myers O(ND) difference algorithm" we have approval to check this into our master branch. * cq-diff: Add file content merge algorithm Add performance tests for MyersDiff Add javadoc comments, remove unused code, shift comments to correct place Fixed MyersDiff to be able to handle more than 100k Fix some warnings regarding unnecessary imports and accessing static methods Add the "jgit diff" command Prepare RawText for diff-index and diff-files Add a test class for Myers' diff algorithm Add Myers' algorithm to generate diff scripts Add set to IntList Conflicts: org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java Change-Id: Ia8e98d81ba1ab52f84d0258a40e6ef5eece9a5b1 CC: Christian Halstrick <christian.halstrick@sap.com>
| * Add file content merge algorithmChristian Halstrick2010-01-061-0/+187
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Adds the file content merge alorithm and tests for merge to jgit. The merge algorithm: - Gets as input parameters the common base, the two new contents called "ours" and "theirs". - Computes the Edits from base to ours and from base to theirs with the help of MyersDiff. - Iterates over the edits. - Independent edits from ours or from theirs will just be applied to the result. - For conflicting edits we first harmonize the ranges of the edits so that in the end we have exactly two edits starting and ending at the same points in the common base. Then we write the two conclicting contents into the result stream. Change-Id: I411862393e7bf416b6f33ca55ec5af608ff4663 Signed-off-by: Christian Halstrick <christian.halstrick@sap.com> [sp: Fixed up two awkard comments in documentation.] Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
| * Add performance tests for MyersDiffChristian Halstrick2009-11-053-0/+397
| | | | | | | | | | | | | | | | | | | | | | Add some tests which make sure that the diff algorithm really behaves in the promised O(N*D) manner. This tests compute diffs between multiple big chunks of data, measure time for computing the diffs and fail if the measured times are off O(N*D) by more than a factor 10 Signed-off-by: Christian Halstrick <christian.halstrick@sap.com> Change-Id: I8e1e0be60299472828718371b231f1d8a9dc21a7 Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
| * Add a test class for Myers' diff algorithmJohannes Schindelin2009-10-061-0/+109
| | | | | | | | | | | | | | | | Bug: 291083 Eclipse-CQ: 3559 Change-Id: I5a10946637438052e7596489b9f9de3a0c6b2066 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
| * Add set to IntListJohannes Schindelin2009-10-061-0/+21
| | | | | | | | | | | | | | | | | | | | Some applications may wish to modify an int list. Bug: 291083 Eclipse-CQ: 3559 Change-Id: Iea871443ec661230aec92397229f1eda6c74216f Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* | UnionInputStream: combines sequential InputStreams into oneShawn O. Pearce2010-01-041-0/+217
| | | | | | | | | | | | | | | | | | | | | | | | The UnionInputStream utility class combines multiple sequential InputStreams so they appear to the caller as a single stream with no gaps. This can be used to concentate streams coming from multiple independent HTTP connections (for example). The companion unit test covers the class's full functionality. Change-Id: I0676c7b5e082a5886bf0e8f43f9fd6c46a666228 Signed-off-by: Shawn O. Pearce <sop@google.com>
* | Recognize Git repository environment variablesRobin Rosenberg2009-12-281-1/+156
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This makes the jgit command line behave like the C Git implementation in the respect. These variables are not recognized in the core, though we add support to do the overrides there. Hence other users of the JGit library, like the Eclipse plugin and others, will not be affected. GIT_DIR The location of the ".git" directory. GIT_WORK_TREE The location of the work tree. GIT_INDEX_FILE The location of the index file. GIT_CEILING_DIRECTORIES A colon (semicolon on Windows) separated list of paths that which JGit will not cross when looking for the .git directory. GIT_OBJECT_DIRECTORY The location of the objects directory under which objects are stored. GIT_ALTERNATE_OBJECT_DIRECTORIES A colon (semicolon on Windows) separated list of object directories to search for objects. In addition to these we support the core.worktree config setting when the git directory is set deliberately instead of being found. Change-Id: I2b9bceb13c0f66b25e9e3cefd2e01534a286e04c Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* | Add support for creating detached headsRobin Rosenberg2009-12-281-0/+58
| | | | | | | | | | | | | | | | | | | | An extra flag when creating a RefUpdate object allows the caller to destroy the symref and replace it with an object ref, a.k.a. detached HEAD. Change-Id: Ia88d48eab1eb4861ebfa39e3be9258c3824a19db Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* | Method to get a 'humanish' name from a pathMykola Nikishov2009-12-191-0/+122
| | | | | | | | | | | | Change-Id: Iec0688232bd59d4626111d77633109918e8e1df3 Signed-off-by: Mykola Nikishov <mn@mn.com.ua> Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
* | Only import the sample data packs on tests that need themShawn O. Pearce2009-11-0216-40/+97
| | | | | | | | | | | | | | | | | | | | | | Not all of our test cases really require the sample data packs, and we are better off not using them because its hard to see exactly what condition a test is testing when looking only at the Java code. Clarify the dependency by only making the packs available when there is a real need for it. Change-Id: Id8a76ee7ee1f7efba585be4bed19a8fb5b3b3585 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* | Move T0007_Index to exttstShawn O. Pearce2009-11-021-455/+0
| | | | | | | | | | | | | | | | | | | | This test depends upon the external git binary, and this isn't really a pure Java test like our module tries to claim itself is. So we move it out to exttst with other tests that require additional external resources and/or executable code. Change-Id: Ic9be0280c8bb50a5768336c64de794eb0a492b3d Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* | Refactor RepositoryTestCase to use LocalDiskRepository insteadShawn O. Pearce2009-11-029-359/+73
| | | | | | | | | | Change-Id: I07014d1b8cc2fab0761d644a12e4ae04f0adf3ef Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* | Move pure IO utility functions to a utility class of its own.Robin Rosenberg2009-10-312-9/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | According the javadoc, and implied by the name of the class, NB is about network byte order. The purpose of moving the IO only, and non-byte order related functions to another class is to make it easier for new contributors to understand that they can use these functions in general and it's also makes it easier to understand where to put new IO related utility functions Change-Id: I4a9f6b39d5564bc8a694b366e7ff3cc758c5181b Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* | Remove trailing whitespace at end of lineAlex Blewitt2009-10-3111-118/+118
| | | | | | | | | | | | | | | | | | As discussed on the egit-dev mailing list, we prefer not to have trailing whitespace in our source code. Correct all currently offending lines by trimming them. Change-Id: I002b1d1980071084c0bc53242c8f5900970e6845 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* | Make the default encoding when reading commits UTF-8Constantine Plotnikov2009-10-081-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | When reading commits the system default encoding was used if no encoding was specified in the commit. The patch modifies the test to add a check that commit message was encoded correctly (the test fails on old implementation if system encoding is not UTF-8) and fixes Commit.decode() method to use UTF-8 if encoding is not specified in the commit object. Change-Id: I27101da3c2eb6edd0c4a9e4c0523e48b286e3cd5 Signed-off-by: Constantine Plotnikov <constantine.plotnikov@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* | Remove a duplicate test from T0003_BasicRobin Rosenberg2009-10-071-10/+0
|/ | | | | | | | | In the pre-historic commit 6d87484b4dee5671a38e64a8e4990dff40a4874f two tests became identical. Remove one of them. Change-Id: I6182ecd4db0162d87a5f4577005b2bf4d5e8c89f Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>