Commit Graph

1254 Commits

Author SHA1 Message Date
Sebastian Schuberth 6fdd214349 Split discoverGitPrefix() code out into discoverGitExe()
Change-Id: I700540eec06efb24eeb09bfcb40420820c32d156
Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-05-21 23:37:42 +02:00
Matthias Sohn 686124bec3 Replace deprecated release() methods by close()
See the discussion [1] in the Gerrit mailing list.

[1] https://groups.google.com/forum/#!topic/repo-discuss/RRQT_xCqz4o

Change-Id: I2c67384309c5c2e8511a7d0d4e088b4e95f819ff
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-05-21 02:05:45 +02:00
Shawn Pearce 8ff08455f6 Fix memory leak in dfs.DeltaBaseCase
The LRU chain management code was broken leading to situations where
the chain was incomplete.  This prevented the cache from removing
items when it exceeded its memory target, causing a leak.

One case was repeated hit on the head of the chain. moveToHead(e)
was invoked linking the head back to itself in a cycle orphaning
the rest of the table.

Add some unit tests to cover this and a few other paths.

Change-Id: Ib27486eaa1b1d2bf1c745a56d0a5832bfb029322
2015-05-11 11:39:28 -07:00
Shawn Pearce bfdd963083 FS_POSIX: Rework umask detection to make it settable
Avoid always calling `sh -c umask` on startup, instead deferring
the invocation until the first time a working tree file needs to
use the execute bit. This allows servers using bare repos to avoid
a costly fork+exec for a value that is never used.

Store the umask as an int instead of two Boolean. This is slightly
smaller memory (one int vs. two references) and makes it easier for
an application to force setting the umask to a value that overrides
whatever the shell told JGit.

Simplify the code to bail by returning early when canExecute is
false, which is the common case for working tree files.

Change-Id: Ie713647615bc5bdf5d71b731a6748c28ea21c900
2015-05-10 12:36:18 -07:00
Shawn Pearce 53e39094bf ObjectWalk: make setRetainBody(false) the default
Despite being the primary author of RevWalk and ObjectWalk I still
fail to remember to setRetainBody(false) in application code using
an ObjectWalk to examine the graph.

Document the default for RevWalk is setRetainBody(true), where the
application usually wants the commit bodies to display or inspect.

Change the default for ObjectWalk to setRetainBody(false), as nearly
all callers want only the graph shape and do not need the larger text
inside a commit body. This allows some code in JGit to be simplified.

Change-Id: I367e42209e805bd5e1f41b4072aeb2fa98ec9d99
2015-05-10 10:45:34 -07:00
Shawn Pearce 3d06349ff2 Merge changes I62befa4a,Ia9c3d123,I7fcf6534
* changes:
  Delete deprecated PackWriter.preparePack() methods
  Delete deprecated class IgnoreRule
  Delete deprecated checkoutEntry() methods in DirCacheCheckout
2015-05-09 23:00:56 -04:00
Shawn Pearce 4feffb3bf5 Add fsck.allowInvalidPersonIdent to accept invalid author/committers
A larger than expected number of real-world repositories found on
the Internet contain invalid author, committer and tagger lines
in their history. Many of these seem to be caused by users misusing
the user.name and user.email fields, e.g.:

  [user]
    name = Au Thor <author@example.com>
    email = author@example.com

that some version of Git (or a reimplementation thereof) copied
directly into the object header. These headers are not valid and
are rejected by a strict fsck, making it impossible to transfer
the repository with JGit/EGit.

Another form is an invalid committer line with double negative for
the time zone, e.g.

  committer Au Thor <a@b> 1288373970 --700

The real world is messy. :(

Allow callers and users to weaken the fsck settings to accept these
sorts of breakages if they really want to work on a repo that has
broken history.  Most routines will still function fine, however
commit timestamp sorting in RevWalk may become confused by a corrupt
committer line and sort commits out of order. This is mostly fine if
the corrupted chain is shorter than the slop window.

Change-Id: I6d529542c765c131de590f4f7ef8e7c1c8cb9db9
2015-04-30 10:27:03 -04:00
Matthias Sohn 65423ea1b1 Merge branch 'stable-3.7'
* stable-3.7:
  Prepare 3.7.2-SNAPSHOT builds
  JGit v3.7.1.201504261725-r
  Revert "Let ObjectWalk.markUninteresting also mark the root tree as"

Change-Id: If1b62ff695e063d797c3d13c43e488ca56f29cbe
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-04-27 23:59:26 +02:00
Matthias Sohn 720adcebb5 Prepare 3.7.2-SNAPSHOT builds
Change-Id: Ia42a665e76953b643a080b58d2cd4526575ddf2e
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-04-27 00:33:14 +02:00
Matthias Sohn 2383cccf12 JGit v3.7.1.201504261725-r
Change-Id: I80639e317df80c103aef5cad75ad9079d43fb9d0
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-04-26 23:23:20 +02:00
Matthias Sohn f02e4a6188 Merge "Revert "Let ObjectWalk.markUninteresting also mark the root tree as"" into stable-3.7 2015-04-26 16:26:54 -04:00
David Ostrovsky d1da2780c2 Revert "Let ObjectWalk.markUninteresting also mark the root tree as"
The Iff2de881 tried to fix missing tree ..." but introduced severe
performance degradation (>10x in some cases) when acting as server
(git push) and as client (replication). IOW cure is worse than the
disease.

This reverts commit c4797fe986.

Change-Id: I4e6056eb352d51277867f857a0cab380eca153ac
Signed-off-by: David Ostrovsky <david@ostrovsky.org>
2015-04-26 17:52:24 +02:00
Matthias Sohn ffdacc2bbb Delete deprecated class IgnoreRule
Was replaced by FastIgnoreRule in 3.6

Change-Id: Ia9c3d1231a5d97f3f5bddc81113954c9f9d8ee1e
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-04-25 00:43:20 +02:00
André de Oliveira 3cd7d0d85a Do not add a newline at the end if neither merged side had one
Bug: 390833
Change-Id: I29f7b79b241929877c93ac485c677487a91bb77b
Signed-off-by: André de Oliveira <andre.oliveira@liferay.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-03-27 20:42:49 -04:00
Laurent Delaigue a5c40a3862 Make RepositoryState.REBASING_MERGE reachable again.
If a non interactive rebase is launched, stopping after a conflict
should set the repository state to RepositoryState.REBASING_MERGE
instead of RepositoryState.REBASING_INTERACTIVE.

Bug: 452623
Change-Id: Ie885aab6d71dabd158a718af0d14fff643c9b850
Also-by: Arthur Daussy <arthur.daussy@obeo.fr>
Signed-off-by: Laurent Delaigue <laurent.delaigue@obeo.fr>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-03-27 15:58:05 +01:00
Christian Halstrick 2bd3556e7e Fix RecursiveMerger in case of multiple, independent base commits
When RecursiveMerger found that there are multiple base-commits for the
commits to be merged it tries to temporarily merge the base commits. But
if these base commits have no common predecessor there was a bug in JGit
leading to a NPE. This commit fixes this by enforcing that an empty tree
is used as base when merging two unrelated base commits.

This logic was already there when merging two commits which have no
common predecessor (ThreeWayMerger.mergeBase()). But the code which was
computing a new temporary base commit in case of criss-cross merges
didn't take care to pick an empty tree when no common predecessor can be
found.

Bug: 462671
Change-Id: Ibd96302f5f81383f36d3b1e3edcbf5822147b1a4
2015-03-25 10:49:58 +01:00
Dave Borowitz f1a15f7eb0 TestRepository: Add a cherryPick method
CherryPickCommand only works on a non-bare repository, as it must
modify the working tree and index in case of a merge conflict. In
tests, being able to recover from a merge conflict is less important,
as the caller should be able to control the full contents of files in
advance of the cherry-pick.

Change-Id: Ic332e44df1308b9336e884666b08c1f6db64513d
2015-03-23 13:03:31 -07:00
Matthias Sohn 197e3393a5 Merge bundle org.eclipse.jgit.java7 into org.eclipse.jgit
As we moved minimum Java version to 7 we don't need a separate bundle
and feature for JGit features depending on Java 7 anymore.

Change-Id: Ib5da61b0886ddbdea65298f1e8c6d65c9879ced1
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-03-23 14:23:07 +01:00
Jonathan Nieder 5967b65838 Revert "CommitBuilder should check for duplicate parents"
This reverts commit 6bc48cdc62.

Until git v1.7.10.2~29^2~1 (builtin/merge.c: reduce parents early,
2012-04-17), C git merge would make merge commits with duplicate parents
when asked to with a series of commands like the following:

  git checkout origin/master
  git merge --no-ff origin/master

Nowadays "git merge" removes redundant parents more aggressively
(whenever one parent is an ancestor of another and not just when
duplicates exist) but merges with duplicate parents are still permitted
and can be created with git fast-import or git commit-tree and history
viewers need to be able to cope with them.

CommitBuilder is an interface analagous to commit-tree, so it should
allow duplicate parents.  (That said, an option to automatically remove
redundant parents would be useful.)

Reported-by: Dave Borowitz <dborowitz@google.com>
Change-Id: Ia682238397eb1de8541802210fa875fdd50f62f0
Signed-off-by: Jonathan Nieder <jrn@google.com>
2015-03-18 16:26:05 -07:00
Dave Borowitz edf4368b0c TemporaryBuffer: Allow presizing block pointer list
Callers may wish to use TemporaryBuffer as an essentially unbounded
buffer by passing Integer.MAX_VALUE as the size. (This makes it
behave like ByteArrayOutputStream, only without requiring contiguous
memory.) Unfortunately, it was always allocating an array in the
backing block pointer list to hold enough blocks to MAX_VALUE--all
262,016 of them. It wasn't allocating the blocks themselves, but this
array was still extremely wasteful, using about 2MiB of memory on a
64-bit system.

Tweak the interface to specify an estimated size, and only allocate
the block pointer list enough entries to hold that size. It's an
ArrayList, so if that estimate was wrong, it'll grow. We assume the
cost of finding enough contiguous memory to grow that array is
acceptable.

While we're in there, fix an off-by-one error: due to integer division
we were undercounting the number of blocks needed to store n bytes of
data as (n / SZ).

Change-Id: I794eca3ac4472bcc605b3641e177922aca92b9c0
2015-03-18 13:38:57 -07:00
Christian Halstrick 6bc48cdc62 CommitBuilder should check for duplicate parents
When setting the parents of a commit with setParentIds() or
addParentId() it should be checked that we don't have duplicate parents.
An IllegalArgumentException should be thrown in this case.

Change-Id: I9fa9f31149b7732071b304bca232f037146de454
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
2015-03-12 18:18:45 -07:00
Dave Borowitz 8b6f9ace15 TestRepository: Allow setting explicit Change-Id
This includes both leaving existing Change-Ids alone (as, for example
Gerrit's commit-msg hook does) and programmatically setting a value.

Change-Id: Iaaffb0107ae27de24df1f0e95a8d628fb8ea5364
2015-03-12 12:47:18 -07:00
Dave Borowitz 6ed07f5cb5 TestRepository: Ignore existing Change-Id in message
Change-Id: I343c3065fa369ef8aab2b033ac1e392b28d10daf
2015-03-12 12:46:50 -07:00
Dave Borowitz 0b625445ef TestRepository: Support committing to unborn symref
Change-Id: I6bcee635adda7c929f6fa68ef20438fe77e49184
2015-03-12 12:46:26 -07:00
Dave Borowitz da85ca73ff TestRepository: Add methods to amend commits or refs
Change-Id: I47082416f6e281262b160ba15272258f9109abd1
2015-03-12 12:46:24 -07:00
Dave Borowitz d79cadb3cf TestRepository: Add a reset method to move HEAD around
This flushed out a number of bugs in the way DfsRefUpdate, or at least
the InMemoryRepository implementation, processes symrefs. These have
been fixed, to an extent, in InMemoryRepository, but other
implementations may still suffer from these bugs.

Change-Id: Ifd12115a0060b9ff45a88d305b72f91ca0472f9a
2015-03-12 12:45:46 -07:00
Dave Borowitz c1d40caa32 TestRepository: Optionally insert Change-Id in commit message
Copied the implementation from CommitCommand.

Change-Id: Iade0e2d70bde70cfa830fe23bcc41959b011a14a
2015-03-12 10:47:12 -07:00
Shawn Pearce d1bda470d4 Merge "ArchiveCommand: Allow to pass options to underlying stream" 2015-03-11 13:27:18 -04:00
Christian Halstrick 0e3ddea1b0 Add "--long" option to JGit describe
Native git supports "git describe --long". This will enforce returning a
long description of a commit even if a tag is directly pointing to the
commit (in contrast to just returning the tag name as it is now). This
commit teaches JGits DescribeCommand and the describe command in the pgm
package to support "--long".

Bug: 460991
Change-Id: I65e179b79e89049c6deced3c71cb3ebb08ed0a8f
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-03-09 13:48:04 -07:00
Dave Borowitz 12a55c3475 Add an in-process pack transport for use in tests
This allows for testing arbitrary sets of push/fetch hooks (e.g.
PreReceiveHook) without depending on either an external protocol (e.g.
HTTP) or the local filesystem.

Change-Id: I4ba2fff9c8a484f990dea05e14b0772deddb7411
2015-02-27 16:26:39 -08:00
Matthias Sohn 1350f7ea1d Merge branch 'stable-3.7'
* stable-3.7:
  Prepare 3.7.1-SNAPSHOT builds
  JGit v3.7.0.201502260915-r
  Read user.name and email from environment first
  Provide more details in exceptions thrown when packfile is invalid

Change-Id: I427f861c6bc94da5e3e05dbbebbf0ad15719a323
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-02-27 01:54:12 +01:00
Matthias Sohn 9b486e3906 Prepare 3.7.1-SNAPSHOT builds
Change-Id: I2e97610ea9e552e5800e7ca895fd193c8bc507aa
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-02-27 01:41:30 +01:00
Matthias Sohn a312131d79 JGit v3.7.0.201502260915-r
Change-Id: Iec17746cad81cfb1d775e782b30f9d8a13c938b6
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-02-26 15:13:01 +01:00
Matthias Sohn a8fd029a93 Read user.name and email from environment first
According to [1] user name and email are taken first from the
environment variables:
GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL
GIT_COMMITTER_NAME, GIT_COMMITTER_EMAIL

In case (some of) these environment variables are not set, the
information is taken from the git configuration.

JGit doesn not yet support the environment variables GIT_AUTHOR_DATE and
GIT_COMMITTER_DATE.

[1] https://www.kernel.org/pub/software/scm/git/docs/git-commit-tree.html#_commit_information

Bug: 460586
Change-Id: I3ba582b4ae13674cf319652b5b13ebcbb96dd8ec
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-02-24 16:39:19 +01:00
David Ostrovsky c0c4c6f09a ArchiveCommand: Allow to pass options to underlying stream
Current ArchiveCommand design doesn't allow to pass in options to
underlying stream implementations. To overcome this, client has to
implement custom format implementation (it cannot be derived from
the existing one, because the classes are marked as final), and set
the options using ThreadLocal, before the method

  ArchiveOutputStream createArchiveOutputStream(OutputStream s)

is get called.

This change extends the ArchiveCommand.Format by allowing to pass
option map during creation of ArchiveOutputStream.

ArchiveCommand is extended correspondingly. That way client can
easily pass options to the underlying streams:

  Map<String, Object> level = ImmutableMap.<String, Object> of(
      "level", new Integer(9));
  new ArchiveCommand(repo)
      .setFormat("zip")
      .setFormatOptions(level)
      .setTree(tree)
      .setPaths(paths)
      .setPrefix(prefix)
      .setOutputStream(sidebandOut)
      .call();

Change-Id: I1d92a1e5249117487da39d19c7593e4b812ad97a
Signed-off-by: David Ostrovsky <david@ostrovsky.org>
2015-02-20 01:40:06 +01:00
Matthias Sohn 6c1f739388 Move console classes to pgm bundle
Since we updated minimum Java version to Java 7 the console bundle
doesn't need to be a separate bundle anymore. Move the contained classes
to the pgm bundle which is using these classes.

Change-Id: If8e6f2d7405fdfe6f4b178673b4ccf99c67d4b64
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-02-10 09:14:48 +01:00
Matthias Sohn c26bc63ef1 Set minimum required Java version to Java 7
Bug: 458475
Change-Id: Iea8f2236d4e6a94a8d14bb8cc685006ea3fd1bb7
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-02-09 14:11:50 +01:00
Matthias Sohn 21f667edba Merge branch 'stable-3.7'
* stable-3.7:
  Add option --orphan for checkout
  Prepare post 3.7.0.201502031740-rc1 builds
  JGit v3.7.0.201502031740-rc1
  Support for the pre-commit hook
  Fix FileUtils.testRelativize_mixedCase which failed on Mac OS X
  Add a hook test
  Introduce hook support into the FS implementations
  If a pack isn't found on disk remove it from pack list

Conflicts:
	org.eclipse.jgit.java7.test/META-INF/MANIFEST.MF

Change-Id: I936acd24d47b911fa30ab29856094e1b2c6ac3db
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-02-04 14:21:52 +01:00
Matthias Sohn 3c2b4086b6 Prepare post 3.7.0.201502031740-rc1 builds
Change-Id: Id3728e771a4441757de016cc9d68055f668126b0
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-02-04 02:04:47 +01:00
Matthias Sohn 8fe6e51be2 JGit v3.7.0.201502031740-rc1
Change-Id: Ia2ea65945b7e1d4120da3d6e6c9f6d5fdb642ae6
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-02-03 23:36:31 +01:00
Matthias Sohn d2e0bfa568 Fix FileUtils.testRelativize_mixedCase which failed on Mac OS X
HFS is case insensitive hence expecting it to return the result for case
sensitive filesystem doesn't work.

Change-Id: I292eab78e50711529a0412f9a54e174a3ac16109
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-02-02 21:23:31 +01:00
Laurent Goubet 6aed51e3ce Introduce hook support into the FS implementations
This introduces the background plumbing necessary to run git hooks from
JGit. This implementation will be OS-dependent as it aims to be
compatible with existing hooks, mostly written in Shell. It is
compatible with unix systems and windows as long as an Unix emulator
such as Cygwin is in its PATH.

Change-Id: I1f82a5205138fd8032614dd5b52aef14e02238ed
Signed-off-by: Laurent Goubet <laurent.goubet@obeo.fr>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-02-02 10:22:53 +01:00
Matthias Sohn 94ebdbfada Prepare 4.0.0-SNAPSHOT builds
Change-Id: I414ba8ccc82866d3107ba7083a567ea70c879bdf
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-01-27 08:48:26 +01:00
Frank Wagner e09e7c064e Fix RawText.getLineDelimiter() for empty first line
Bug: 456776
Change-Id: Iae50be89ea6d5aee33bd938a937ac5ca578aabca
Signed-off-by: Frank Wagner <frank.wagner@fr.ibm.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-01-17 23:28:20 +01:00
Arthur Daussy c185484dcf Add basic support for .gitattributes
Core classes to parse and process .gitattributes files including
support for reading attributes in WorkingTreeIterator and the
dirCacheIterator.

The implementation follows the git ignore implementation. It supports
lazy reading attributes while walking the working tree.

Bug: 342372
CQ: 9078
Change-Id: I05f3ce1861fbf9896b1bcb7816ba78af35f3ad3d
Also-by: Marc Strapetz <marc.strapetz@syntevo.com>
Also-by: Gunnar Wagenknecht <gunnar@wagenknecht.org>
Also-by: Arthur Daussy <arthur.daussy@obeo.fr>
Signed-off-by: Gunnar Wagenknecht <gunnar@wagenknecht.org>
Signed-off-by: Marc Strapetz <marc.strapetz@syntevo.com>
Signed-off-by: Arthur Daussy <arthur.daussy@obeo.fr>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2015-01-07 10:52:06 -08:00
Andrey Loskutov 428d31efd3 AIOOB in ChangeIdUtil.indexOfChangeId if amended message is a newline
Bug: 456792
Change-Id: Idf38a0db7dc72d672ff185dcac2f41f0012a6673
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-01-06 14:33:07 +01:00
Matthias Sohn 79dacba922 Merge branch 'stable-3.6'
* stable-3.6:
  Prepare 3.6.2-SNAPSHOT builds
  JGit v3.6.1.201501031845-r
  Trim author/committer name and email in commit header
  Rename detection should canonicalize line endings
  PathMatcher should respect "assumeDirectory" flag

Change-Id: Idd48c6d94cf1ab09abc07f70d50890b1b78e1833
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-01-04 02:18:27 +01:00
Matthias Sohn 741ebca8b7 Prepare 3.6.2-SNAPSHOT builds
Change-Id: I9699d84af2d4b5382d8ee88ed3517d6b91305421
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-01-04 01:19:35 +01:00
Matthias Sohn f1b2a5361f JGit v3.6.1.201501031845-r
Change-Id: I56e235a271f90ea2d8cdb7d99706f726d4a59c43
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-01-04 00:46:52 +01:00
Rüdiger Herrmann a4c2c8a3ee Trim author/committer name and email in commit header
C Git trims name and email before inserting them into the commit header
so that " A U Thor  " and "  author@example.com " becomes 
"A U Thor <author@example.com>" with a single separating space.

This changes PersonIdent#toExternalString() to trim name and email
before concatenating them.

Change-Id: Idd77b659d0db957626824f6632e2da38d7731625
Signed-off-by: Rüdiger Herrmann <ruediger.herrmann@gmx.de>
2015-01-03 00:28:15 +01:00