Commit Graph

760 Commits

Author SHA1 Message Date
Matthias Sohn 4b3c0f8aba Prepare 2.2.0 builds
Change-Id: I386ba70541d644e58661d26713b309371e0f9257
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2012-09-19 09:10:12 +02:00
Matthias Sohn 555ad1f93c Merge branch 'stable-2.1'
* stable-2.1:
  Prepare for 2.1 maintenance changes
  JGit v2.1.0.201209190230-r
  Introduce "never" as parseable date
  Introduce ParseExceptions for GitDateParser
  Support config param "gc.pruneexpire"

Change-Id: If149d7f968a3425d9425f6ba9ce135a8341776a7
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2012-09-19 09:02:31 +02:00
Matthias Sohn 54c4eb69ac Prepare for 2.1 maintenance changes
Change-Id: I436f36a7c6dc86916eb4cde038b27f9fb183465a
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2012-09-19 09:00:33 +02:00
Matthias Sohn c466bc2ddf JGit v2.1.0.201209190230-r
Change-Id: I9f94bce9a25644575a068c8fa459f74e06b02030
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2012-09-19 08:56:17 +02:00
Robin Rosenberg 1f19d0a834 Merge "Fix resolving expression with ~ and ^ than extends beyond history" 2012-09-18 18:00:38 -04:00
Dave Borowitz 70ae16d708 Fix resolving expression with ~ and ^ than extends beyond history
resolve("foo~X") where X is greater than the distance from foo to the
root should return null, but 2a2362fb introduced a bug causing it to
either return resolve("foo") or NPE. Add a test for the correct
behavior.

Also add an analogous test for foo^X where X is greater than the
number of parents (which was not broken by that commit).

Change-Id: Ic580081ece57c8c2df29b652897b425ecb34e11f
2012-09-18 19:51:57 +02:00
Robin Rosenberg e0a3091af7 Introduce "never" as parseable date
For configuration parameter like "gc.pruneexpire" we need to understand
the value "never". Never is handled as a date so far into the future
that it will never happen. The actual value currently used is the
constant GitDateParser.NEVER.

Change-Id: I7744eaee9bf5026da517151c212c88325c348d6c
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
2012-09-18 19:23:17 +02:00
Christian Halstrick 84e171fbab Introduce ParseExceptions for GitDateParser
Instead of just returning null when something was not parseable we
should throw a real ParseException. This allows us to distinguish
between specifications which are unparseable and those which represent
no date (e.g. "never")

Change-Id: Ib3c1aa64b65ed0e0270791a365f2fa72ab78a3f4
2012-09-17 22:41:06 +02:00
Sasa Zivkov a551493240 Additional unit tests for the GC
Change-Id: Id5b578f7040c6c896ab9386a6b5ed62b0f495ed5
Signed-off-by: Sasa Zivkov <sasa.zivkov@sap.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2012-09-16 23:57:18 +02:00
Robin Rosenberg d92287bcc2 Use assertEquals instead of == for literal primitives
Change-Id: I8449695ecc94a423369a7644a6ec93cf0cacef5d
2012-09-16 00:23:51 +02:00
Robin Rosenberg a7b0641b96 Use assertTrue/False instead of equals with boolean literals
This include replacing assertTrue(!..) with assertFalse()

Change-Id: Idecd8018641454e10127d82ea3ddda3f671489ef
2012-09-16 00:23:23 +02:00
Robin Rosenberg cd23b214bf cleanup: use assertArrayEquals for assertion on arrays
Change-Id: I1df945011f8e5f03959b693d3564fe357e707f91
2012-09-03 22:37:58 +02:00
Robin Rosenberg 476e1d2ff1 cleanup: Prefer assertEquals over assertTrue(....equals(...))
That is the common style and yields better diagnostics on failure.

Change-Id: I831a55615a812734af0912a5d6bbfd1edc75308e
2012-09-03 22:37:57 +02:00
Christian Halstrick 32e952fefd Merge "Support branches with name 'config'" 2012-09-03 08:15:31 -04:00
Matthias Sohn 9d3110e72d Merge "Add tests for more coverage of CheckoutCommand" 2012-09-03 02:52:41 -04:00
Robin Stocker 11533f5d1d Add tests for more coverage of CheckoutCommand
Change-Id: Id3ab5f56f88d7e9636c71b30258c268a75fc422e
Signed-off-by: Robin Stocker <robin@nibor.org>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2012-09-03 08:44:28 +02:00
Robin Stocker 51c20b27ac DirCacheCheckout: Fix handling of files not in index
When a file is not in the index and neither contents nor mode differ
between "head" and "merge", the index state should be kept. If they
differ, a checkout conflict should occur. This is described in Git's
git-read-tree.txt.

JGit used to replace the index state with "merge" in both of the above
cases.

A confusing effect of this was that when one removed a file and then did
a rebase, the file silently reappeared again.

The changes to dir/file conflict handling are a consequence of this
change, as the index handling change made tests in DirCacheCheckoutTest
break. I compared these cases to C Git and the new behavior there also
matches what C Git does.

Bug: 387390
Change-Id: I5beb781f12172a68f98c67d4c8029eb51ceae62d
Signed-off-by: Robin Stocker <robin@nibor.org>
2012-09-01 13:29:00 +02:00
Robin Rosenberg 0a9e010e14 Create an input stream that transforms LF to CRLF
The transformation is the same as AutoCRLFOutputStream does, but
the direction is reversed. The tests are reused, but the implementation
derives somewhat from the EolCanonicalizingInputStream.

This stream will be used to compare blobs with LF line endings with
worktree data that has CRLF line endings.

Bug: 387501
Change-Id: I80d96e453e7f780dd464a89778de124cf35384e1
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2012-09-01 09:56:51 +02:00
Christian Halstrick abd60101b6 Implement a parser for dates
In order to parse user specified strings containing date and time info
a thread-safe parser is implemented. This is needed for example to
interpret configuration parameters (e.g. gc.pruneexpire where need to
parse strings like "2 weeks ago"). The parser is thread-safe by caching
SimpleDateFormat instances in a ThreadLocal cache.

Native git has a parser called approxidate which is able to interpret a
huge number of formats ("1 year ago", "tea time", ...). Ideally JGit
should be able to parse the same strings as native git but for now this
parser understands the following subset:

"now"
"yesterday"
"(x) years|months|weeks|days|hours|minutes|seconds ago"
"yyyy-MM-dd HH:mm:ss Z" (ISO)
"EEE, dd MMM yyyy HH:mm:ss Z" (RFC)
"yyyy-MM-dd"
"yyyy.MM.dd"
"MM/dd/yyyy"
"dd.MM.yyyy"
"EEE MMM dd HH:mm:ss yyyy Z" (DEFAULT)
"EEE MMM dd HH:mm:ss yyyy" (LOCAL)

Change-Id: Iccb66dadb60da13104e73140e53d5e2de068369c
2012-08-28 19:33:42 +10:00
Robin Rosenberg 5e21a8916c Merge changes I98df46ce,Ifb815a12,I051a1724
* changes:
  Support [<ref>]@{upstream} revision syntax
  Support parsing previous checkout as a revision expresion.
  Allow a @ without branch in revision syntax
2012-08-21 17:34:45 -04:00
Matthias Sohn 812796023c Merge changes I4f73487b,I1d1ed122
* changes:
  The Git API's only likes /, not \ in paths
  Skip a test that cannot be verified on Windows
2012-08-21 16:59:42 -04:00
Robin Rosenberg c4bc9c709a The Git API's only likes /, not \ in paths
Therefore this test fails on Windows

Change-Id: I4f73487b720ea1479e95108344f1dc3711106408
2012-08-21 19:43:59 +02:00
Robin Rosenberg f72b26f2d3 Skip a test that cannot be verified on Windows
Change-Id: I1d1ed122c714f39ca7fb557224756205274804eb
2012-08-21 19:43:47 +02:00
Christian Halstrick 252727c4fc Support branches with name 'config'
JGit was not able to lookup refs which had the name of files which exist
in the .git folder. When JGit was looking up a ref named X it has a
fixed set of directories where it searched for files named X
(ignore packed refs for now). First directory to search for is .git. In
case of the ref named 'config' it searched there for this file, found it
(it's the .git/config file with the repo configuration in it), parsed
it, found it is an invalid ref and stopped searching. It never looked
for a file .git/refs/heads/config.

I changed JGit in a way that when it finds a file in GIT_DIR which
corresponds to a ref name and if this file doesn't contain a valid ref
then it will ignore the InvalidObjectIdException and continue searching.

Change-Id: Ic26a329fb1624a5b2b2494c78bac4bd76817c100
Bug: 381574
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
Signed-off-by: Stefan Lay <stefan.lay@sap.com>
2012-08-21 15:10:02 +02:00
Matthias Sohn 376a741d8f Teach BranchTrackingStatus to handle tracking of local branches
EGit wasn't able to decorate local branches tracking another local
branch with number of commits the checked out local branch differs from
the other local branch it's tracking.

Bug: 376970 
Change-Id: I74e932d5eacd74dbf6b0dffcfc65ba3222a8250e
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2012-08-18 00:29:45 +02:00
Robin Stocker 5854ca091a Improve ours/theirs conflict markers for rebase, cherry-pick
On conflicts in rebase or cherry-pick, the conflict markers were like
this:

    <<<<<<< OURS
    a
    =======
    b
    >>>>>>> THEIRS

This is technically correct, but it could be better.

It's especially confusing during a rebase, where the meaning of
OURS/THEIRS is not obvious. The intuition is that "ours" is the commits
that "I" did before the rebase, but it's the other way around because of
the way rebase works. See various bug reports and stackoverflow
discussions.

With this change, in the case of a cherry-pick while on master, the
markers will be like this:

    <<<<<<< master
    a
    =======
    b
    >>>>>>> bad1dea Message of the commit I'm cherry-picking

In the case of a "git rebase master":

    <<<<<<< Upstream, based on master
    a
    =======
    b
    >>>>>>> b161dea Message of a commit I'm rebasing

It's not "master" because that would only be correct for the first
cherry-pick during a rebase, after that, it's master + already
cherry-picked commits.

And in the case of a "git pull --rebase":

    <<<<<<< Upstream, based on branch 'master' of git@example.org:repo
    a
    =======
    b
    >>>>>>> b161dea Message of a commit I'm rebasing

Bug: 336819
Change-Id: I1333a8dd170bb0077f491962013485efb6f2a926
Signed-off-by: Robin Stocker <robin@nibor.org>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2012-08-18 00:11:45 +02:00
Robin Rosenberg 342de38e57 Fix idOffset when the working tree iterator matches a dircache entry
idOffset is not zero when idBuffer comes from blob in the dircache

Change-Id: Iff768422cba140a5d6a776e2c627b852f079c1da
2012-08-15 20:20:48 +02:00
Christian Halstrick 02113f7411 Merge "Allow JGit to read C Git rebase state" 2012-08-13 09:43:42 -04:00
Robin Rosenberg 993fcac2d3 Allow JGit to read C Git rebase state
C Git prefixes the time stamp in the author script with a "@"

Change-Id: I140b29519acc101da78296eef562368fc6b61135
2012-08-07 16:49:45 +02:00
Matthias Sohn e9c811d0d0 Allow detection of case insensitive file systems
Change-Id: I03f59d07bcc3338ef8d392cbd940799186ca03bd
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
2012-08-06 21:34:57 +02:00
Jevgeni Zelenkov 803debd7be Ensure a directory exists before trying to create/merge a file into it.
Since git doesn't keep track of empty directories, they should be
created first. Test case included demonstrates that using
StashApplyCommand(). Bugfix is applied to the DirCacheCheckout class,
because StashApplyCommand() uses it internally to apply a stash.

Change-Id: Iac259229ef919f9e92e7e51a671d877172bb88a8
Signed-off-by: Jevgeni Zelenkov <jevgeni.zelenkov@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2012-08-06 08:59:28 +02:00
Robin Rosenberg d08b35532a Merge "Fix PlotCommit for commits with duplicate parents" 2012-08-05 06:51:27 -04:00
Robin Rosenberg b2f911bb69 Fix PlotCommit for commits with duplicate parents
JGit allows to create commits which have duplicate parents: e.g. a
commit X has first parent Y and second parent Y. Such commits are not
handled correctly by PlotCommit leading to wrong display of the history
in EGit. In such cases there is a never ending passing line drawn beside
all commits younger than the commit with duplicate parents. This commit
fixes this by explicitly checking for duplicate parents.

In a different commit we should fix JGit not to create commits with
duplicate parents. I think native git also doesn't allow such commits,
although history display in native git (gitk, git log --graph) is not
damaged by such commits.

Change-Id: Ie3019ef613a507023958bea27b1badc3b8950279
2012-08-05 12:50:06 +02:00
Robin Rosenberg 0ec1db820d Merge "Fix resolving of relative file URIs in TransportLocal" 2012-07-29 18:31:39 -04:00
Robin Rosenberg 958a517c86 Merge "Garbage collector for FileRepositories" 2012-07-29 10:16:22 -04:00
Christian Halstrick 4c3f017a77 Garbage collector for FileRepositories
Implements a garbage collector for FileRepositories. Main ideas are
copied from the garbage collector for DFS based repos
(DfsGarbageCollector). Added functionalities are
- pruning loose objects
- handling of the index
- packing refs
- handling of reflogs (objects referenced from reflog will not be
pruned/)

These are features of a GC which are not handled in this change and
which should come with subsequent changes:
- unpacking packed objects into loose objects (to support that pruning
packed objects doesn't delete them until they are older than two weeks)
- expiration of reflogs
- support for configuration parameters (e.g. gc.pruneExpire)

Change-Id: I14ea5cb7e0fd1b5c50b994fd77f4e05bfbb9d911
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
2012-07-29 15:43:50 +02:00
Robin Stocker beee7b86af Fix resolving of relative file URIs in TransportLocal
A configured remote url like "../repo" works with C Git.

In JGit, it only worked if Java's current working directory happened to
be the local repository working directory.

Change-Id: I33ba3f81b37d03cf17ca7ae25a90774a27e7e02b
Signed-off-by: Robin Stocker <robin@nibor.org>
2012-07-27 12:05:13 +02:00
Christian Halstrick 778fdfaec1 Again teach ResolveMerger to create more correct DirCacheEntry's
Currently, after a merge/cherry-pick/rebase, all index entries are
smudged as the ResolveMerger never sets entry lengths and/or
modification times. This change teaches it to re-set them at least for
things it did not touch. The other entries are then repaired when the
index is persisted, or entries are checked out.

The first attempt to get this in was commit
3ea694c252 which has been reverted.
Since then some fixes to ResolveMerger and a few more tests have
been added which check situations where the index is not matching
HEAD before we merge.

Change-Id: I648fda30846615b3bf688c34274c6cf4bc857832
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
Also-by: Markus Duft <markus.duft@salomon.at>
2012-07-26 16:20:38 +02:00
Shawn Pearce 955b024995 Revert "Teach ResolveMerger to create more correct DirCacheEntry's"
This reverts commit 3ea694c252

Merges with unmodified subtrees are broken with this commit present.
Back it out until a fixed version can be supplied.
2012-07-24 20:07:48 -04:00
Robin Rosenberg c010c93694 Support [<ref>]@{upstream} revision syntax
Resolves into a ref name corresponding to the named (or current)
branch's upstream ref.

Change-Id: I98df46cedb498724cf14343fbb168f24ff667929
2012-07-20 08:29:10 +02:00
Robin Rosenberg 2a2362fbb3 Support parsing previous checkout as a revision expresion.
Repository.resolve can only return an ObjectId and will
continue to do so, but another method, simplify(), will
be able to return a branch name for some cases.

Previous checkouts can be specified as @{-n}, where n is an
integer speifying the n:th previous branch. The result
is the branch name, unless the checkout was a detached head,
in which case the object id is returned. Since the result
is a branch it may be followed by a references to the reflog,
such as @{-1}@{1} if necessary.

A simple expression like "master" is resolved to master in
simplify, but anything starting with refs gets resolved to
its object id, even if it is a branch.

A symbolic ref is resolved to its leaf ref, e.g. "HEAD" might
be resolved to "master".

Change-Id: Ifb815a1247ba2a3e2d9c46249c09be9d47f2b693
2012-07-20 08:20:48 +02:00
Markus Duft 3ea694c252 Teach ResolveMerger to create more correct DirCacheEntry's
Currently, after a merge/cherry-pick/rebase, all index entries are
smudged as the ResolveMerger never sets entry lengths and/or
modification times. This change teaches it to re-set them at least for
things it did not touch. The other entries are then repaired when the
index is persisted, or entries are checked out.

Change-Id: I0944f2017483d32043d0d09409b13055b5609a4b
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
2012-07-19 10:30:59 +02:00
Robin Rosenberg f82d1cb5c0 Allow a @ without branch in revision syntax
No branch before @ is interpreted as the currently checked out branch.
For detached heads it would be HEAD, but normally it is the branch
that HEAD refers to.

Change-Id: I051a1724fa390b8212e8986ba832b1347a20371e
2012-07-16 23:56:51 +02:00
Markus Duft 3c09e980cb Make ApplyCommand create missing parent directories for new files
Otherwise applying will fail with a FileNotFoundException, because
File.createNewFile() fails with missing parents.

Contains change & according test.

Change-Id: I970522b549b8bb260ca6720da11f12c57ee8a492
Signed-off-by: Chris Aniszczyk <zx@twitter.com>
2012-07-16 09:04:30 -07:00
Robin Stocker a216624ef7 Create parent dir if necessary on checkout
An example where this is necessary is when a whole directory was deleted
and checkout is used to restore a file which was in that directory.

Bug: 372133
Change-Id: I1d45e0a5d2525fe1fdfbf08c9c5c166dd909e9fd
Signed-off-by: Robin Stocker <robin@nibor.org>
2012-07-08 15:15:38 +02:00
Dave Borowitz 2444aa231a Use the working tree's .gitmodules in SubmoduleWalk.forIndex()
This was broken in fe1f1b8f8a, which
preferred the index over the working tree when both were present.

Change-Id: I97dcf9a088adcbd0187fa7eec9ef34445ce3a981
Signed-off-by: Kevin Sawicki <kevin@github.com>
2012-06-25 10:46:36 -07:00
Christian Halstrick 1bf5b9c7a8 Merge changes I6b2ce96b,I499f518f
* changes:
  Fix order of deletion for files/dirs in ResolveMerger
  Don't return success on failing paths in ResolveMerger
2012-06-25 03:08:03 -04:00
Robin Stocker 14ff22fd74 Ignore empty lines when parsing git-rebase-todo
When starting a rebase with C Git, there may be empty lines in the
git-rebase-todo file. Before this change, JGit would fail to parse the
file with e.g. the following exception:

  JGitInternalException: Unknown or unsupported command "
  #", only "pick" is allowed.

This happened when there was an empty line just before the comments,
because the nextSpace would be the one from the comment. Now the empty
lines are ignored by checking for nextSpace < ptr outside of the loop.

Change-Id: I94ad299f367c846e7729c74f49c6b8f93f75ae81
Signed-off-by: Robin Stocker <robin@nibor.org>
2012-06-23 16:38:54 +02:00
Robin Stocker e623db0f87 Fix order of deletion for files/dirs in ResolveMerger
Before, the paths to delete were stored in a HashMap, which doesn't have
a particular order. So when e.g. both the file "a/b" and the directory
"a" were to be deleted, it would sometimes try to delete "a" first. This
resulted in a failed path because File#delete() fails when a directory
isn't empty.

With this change, an ArrayList is used for storing the paths to delete.
The list contains the paths in a top-down order, as defined by the order
of processEntry. When the files are deleted, the list is iterated in
reverse, ensuring that all files of a directory are deleted before the
directory itself.

Bug: 354099
Change-Id: I6b2ce96b3932ca84ecdfbeab457ce823c95433fb
Signed-off-by: Robin Stocker <robin@nibor.org>
2012-06-23 16:32:34 +02:00
Robin Stocker 028434e4f5 Don't return success on failing paths in ResolveMerger
ResolveMerger#mergeImpl() was only returning false (= failed) when there
were unmerged paths. In the case when there were only failing paths, it
returned true.

Because MergeCommand looks at the return value for determining if the
merge failed, it would fall into the successful case there, where it
should instead return a MergeResult with MergeStatus.FAILED.

This change adds a test case for this and makes the ResolveMerger return
false when there are failing paths.

This was discovered while working on fixing bug 354099 and is needed for
its test case.

Bug: 354099
Change-Id: I499f518f6289ef93e017db924b2aa857f2154707
Signed-off-by: Robin Stocker <robin@nibor.org>
2012-06-23 16:32:34 +02:00