Commit Graph

3449 Commits

Author SHA1 Message Date
Matthias Sohn 514b11ddcc Merge branch 'stable-4.2'
* stable-4.2:
  Don't use deprecated LockFile constructor
  Fix warnings about unchecked conversion of MergeResult
  MockServletConfig: Fix warning about unchecked conversion of Enumeration
  HugeFileTest: Make Git a class member and open in try-with-resource
  Suppress "unchecked cast" warnings related to UploadPackFactory.DISABLED
  DiffAlgorithms: Fix warnings about variable hiding
  DirCacheBasicTest: Open ObjectInserter.Formatter in try-with-resource
  DirCacheBuilderIteratorTest: Open TreeWalk in try-with-resource
  DirCacheCGitCompatabilityTest: Open TreeWalk in try-with-resource
  DirCacheCheckoutMaliciousPathTest: Open Git and RevWalk in t-w-r
  DirCacheIteratorTest: Open TreeWalk instances in try-with-resource
  ForPathTest: Open TreeWalk in try-with-resource
  GitConstructionTest: Open Git instance in try-with-resource
  IndexDiffTest: Open Git instances in try-with-resources
  ManifestParserTest: Don't use deprecated StringBufferInputStream
  InMemoryRepository: Remove unused RevWalk from batch method signature
  IndexModificationTimesTest: Open Git instances in try-with-resource
  InterIndexDiffFilterTest: Open TreeWalk in try-with-resource
  LockFileTest: Open Git instance in try-with-resource
  JGit v4.1.2.201602141800-r
  MergeCommandTest: Use JUnit's assume to check preconditions
  MergeCommandTest: Open Git instances in try-with-resource

Change-Id: Ie5dba6b9132a29e86958a04fa2b76465bcd2c6b5
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-02-15 23:28:18 +01:00
Shawn Pearce 621b0740b3 Merge "Allow deletion of HEAD ref if the repository is bare." 2016-02-15 13:02:05 -05:00
David Pursehouse e96cb22a43 Don't use deprecated LockFile constructor
Change-Id: Ibc3e2f3372e1a65732dd6d3c71cec53fb1aa15e2
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
2016-02-15 18:44:24 +09:00
David Pursehouse 979fa19110 Fix warnings about unchecked conversion of MergeResult
Change-Id: I1490b2209fa7b39676849c624adbc262a672f6df
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
2016-02-15 18:22:53 +09:00
David Pursehouse f04bd20fc6 InMemoryRepository: Remove unused RevWalk from batch method signature
The RevWalk given in the arguments is not used. According to the
comment at the top of the method, a new RevWalk is intentionally
used in the implementation.

Remove the unused argument.

Change-Id: Iec81a1341d5bf377801475845b96a465753096ef
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
2016-02-15 14:57:39 +09:00
Ivan Motsch 975aa88685 Add Attribute Macro Expansion
Attributes MacroExpander implements macros used in git attributes. This
is implemented inside the TreeWalk using a lazy created MacroExpander.
In addition, the macro expander caches the global and info attributes
node in order to provide fast merge of attributes.

Change-Id: I2e69c9fc84e9d7fb8df0a05817d688fc456d8f00
Signed-off-by: Ivan Motsch <ivan.motsch@bsiag.com>
2016-02-11 17:08:49 +01:00
Matthias Sohn 28e2fed761 Merge branch 'stable-4.2'
* stable-4.2:
  RepoProject: Fix warnings about variable hiding
  RepoTest: Open Git in try-with-resources
  RepositoryResolveTest: Open Git in try-with-resource
  RepositoryTestCase: Open autocloseable types in try-with-resource
  ResetCommandTest: Use Git member in testHardResetAfterSquashMerge
  ResolveMergerTest: Open Git in try-with-resource
  RevCommitListTest: Open Git and RevWalk in try-with-resource
  RevCommitParseTest: Open ObjectInserter.Formatter in try-with-resource
  RevObjectTest: Open RevWalk in try-with-resource
  RevTagParseTest: Open ObjectInserter.Formatter in try-with-resource
  RevertCommandTest: Open Git in try-with-resource
  SquashMessageFormatterTest: Open git in try-with-resource
  StatusCommandTest: Open Git in try-with-resource
  SubmoduleAddTest: Open Git in try-with-resource
  SymlinksTest: Open git and TreeWalk in try-with-resource
  T0003_BasicTest: Open autocloseable types in try-with-resource
  TextHashFunctions: Fix warnings about variable hiding
  TreeFilterTest: Open TreeWalk in try-with-resource
  TreeWalkJava7Test: Open TreeWalk in try-with-resource
  Fix diff for added and removed submodule

Change-Id: If3ecc63f6dfac55474d3c1dd2f4105371f3d24fb
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-02-10 00:51:01 +01:00
Matthias Sohn 26012958a3 Merge branch 'stable-4.1' into stable-4.2
* stable-4.1:
  Fix diff for added and removed submodule

Change-Id: I37dd71ed19b06e9bbcffe37370081ab875c6d8d4
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-02-10 00:45:18 +01:00
David Pursehouse 4e5255c59a RepoProject: Fix warnings about variable hiding
Method parameter names were hiding class members of the same
name.

Change-Id: I182f2715894ac4259b09a371cb4e0eb24f52518a
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
2016-02-05 18:22:58 +09:00
Saša Živkov a0e1374e22 Allow to reuse disableSslVerify method, move it to HttpSupport
The disableSslVerify method will be used in the follow up change.

Change-Id: Ie00b5e14244a9a036cbdef94768007f1c25aa8d3
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-02-04 17:49:43 +01:00
Matthias Sohn 3bae524f6f Support LFS protocol and a file system based LFS storage
Implement LfsProtocolServlet handling the "Git LFS v1 Batch API"
protocol [1]. Add a simple file system based LFS content store and the
debug-lfs-store command to simplify testing.

Introduce a LargeFileRepository interface to enable additional storage
implementation while reusing the same protocol implementation.

At the client side we have to configure the lfs.url, specify that
we use the batch API and we don't use authentication:

  [lfs]
	  url = http://host:port/lfs
	  batch = true
  [lfs "http://host:port/lfs"]
	  access = none

the git-lfs client appends the "objects/batch" to the lfs.url.

Hard code an Authorization header in the FileLfsRepository.getAction
because then git-lfs client will skip asking for credentials. It will
just forward the Authorization header from the response to the
download/upload request.

The FileLfsServlet supports file content storage for "Large File
Storage" (LFS) server as defined by the Github LFS API [2].

- upload and download of large files is probably network bound hence use
  an asynchronous servlet for good scalability
- simple object storage in file system with 2 level fan-out
- use LockFile to protect writing large objects against multiple
  concurrent uploads of the same object
- to prevent corrupt uploads the uploaded file is rejected if its hash
  doesn't match id given in URL

The debug-lfs-store command is used to run the LfsProtocolServlet and,
optionally, the FileLfsServlet which makes it easier to setup a
local test server.

[1]
https://github.com/github/git-lfs/blob/master/docs/api/http-v1-batch.md
[2] https://github.com/github/git-lfs/tree/master/docs/api

Bug: 472961
Change-Id: I7378da5575159d2195138d799704880c5c82d5f3
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Signed-off-by: Sasa Zivkov <sasa.zivkov@sap.com>
2016-02-04 17:49:43 +01:00
Matthias Sohn 536db18cc6 Implement SHA-256 abstraction
The Large File Storage extension specified by GitHub [1] uses SHA-256 to
compute the ID of large files stored by the extension. Hence implement a
SHA-256 abstraction similar to the SHA-1 abstraction used by JGit.

[1] https://git-lfs.github.com/

Bug: 470333
Change-Id: I3a95954543c8570d73929e55f4a884b55dbf1b7a
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-02-04 17:49:42 +01:00
Hugo Arès df904a4227 Fix diff for added and removed submodule
Since If13f7b406, submodule difference are shown as a hunk. The issue
was that added and removed submodule were considered as Edit.REPLACE
instead of Edit.INSERT and Edit.DELETE in the DiffFormatter result.

Change-Id: I4330c2aa3f10e29d7d6b0b2e5286e59293a06239
Signed-off-by: Hugo Arès <hugo.ares@ericsson.com>
2016-02-04 10:27:50 -05:00
Matthias Sohn 2de33d7678 Remove unused API problem filters
Change-Id: I8b1c99b108b4cea6356e0a62e6bfc0731df44cf5
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-02-03 10:39:08 +01:00
Matthias Sohn b0facdc113 Merge branch 'stable-4.2'
* stable-4.2:
  DirCacheCheckoutTest: Open Git and TreeWalk in try-with-resource
  CommitCommand: Remove declaration of unthrown exception
  Branch: Fix variable hiding warning
  ApplyCommandTest: Open Git in try-with-resource
  PackFileTest: Open ObjectInserter.Formatter in try-with-resource

Change-Id: I8484b10fad5a4c35fcfaedc1cdf8ccf97471618e
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-02-03 10:30:52 +01:00
David Pursehouse 521f513d6d CommitCommand: Remove declaration of unthrown exception
Change-Id: I1795b1e510ab170f062ee6c5988d7a7567abe260
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
2016-02-02 18:27:47 +09:00
Matthias Sohn 9400d0cb17 Merge "Prevent ChainingCredentialsProvider from adding delegated providers twice" 2016-01-28 18:51:14 -05:00
Mike Williams 48ad6842fc Allow deletion of HEAD ref if the repository is bare.
Change-Id: I2281d818c9f76019e7e053e89b20214f2d663957
Signed-off-by: Mike Williams <miwilliams@google.com>
2016-01-28 11:43:59 -05:00
Yuxuan 'fishy' Wang 7960fa8735 [gitrepo] Support revision in remote tag.
Repo manifest file allows revision attribute in <remote> tag. This change
teaches JGit to read that information.

Change-Id: I1c878a2505b9d09fa09fbd404a119b71f2fb8fdb
Signed-off-by: Yuxuan 'fishy' Wang <fishywang@google.com>
2016-01-27 16:01:06 -08:00
Rüdiger Herrmann bd67084d2b Prevent ChainingCredentialsProvider from adding delegated providers twice
Signed-off-by: Rüdiger Herrmann <ruediger.herrmann@gmx.de>
Change-Id: Icc0907af4fe26877d066db3c813dba37213a3ccc
2016-01-26 18:55:39 +01:00
Thomas Wolf 9441d61e37 Fix a @since tag
Ketch didn't make it into 4.2

Change-Id: Iab3ddfb926a2f8d31622e212c845c825369b09d5
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2016-01-23 23:51:14 +01:00
Matthias Sohn fc4d117511 Prepare 4.2.1-SNAPSHOT builds
Change-Id: Ic9eac53b10ac97b2038b334d388ae3d21393f993
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-01-22 01:48:52 +01:00
Matthias Sohn 20c2079f70 JGit v4.2.0.201601211800-r
Change-Id: I89f33b0da81ff499315baa5311f95f31724fa510
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-01-21 23:47:12 +01:00
Terry Parker f321741cff Merge "Remove unused variable from DfsBlockCache" 2016-01-21 16:21:15 -05:00
Terry Parker 4d178be021 Remove unused variable from DfsBlockCache
Change-Id: I8ea167e44e9ebcac7ca08920e806d8bcb8188bf0
Signed-off-by: Terry Parker <tparker@google.com>
2016-01-21 13:02:39 -08:00
Matthias Sohn b30917ce21 Prepare 4.3.0-SNAPSHOT builds
Change-Id: Idcf0479529693b023042becd96698f9afd344bd4
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-01-21 21:49:41 +01:00
Laurent Delaigue 4409751516 Add progress monitor to Merger
Monitoring progress of merges can be useful for users for large
repositories or complex merge processes that take some time.

This enables setting a monitor. Existing merge implementations in jgit
do not yet report progress if a monitor is set. This will be added in a
later change.

Change-Id: I17b978b3fc91750dd88649638b90a46820a0877c
Signed-off-by: Laurent Delaigue <laurent.delaigue@obeo.fr>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-01-21 17:08:04 +01:00
Chris Gavin 82f47ace3d Fix TransportException when reading bundle
When reading a bundle file, commit messages who's oneline format is
longer than 982 characters caused JGit to treat subsequent text in
the commit as a SHA, then throw a TransportException because it's
not a valid SHA.

Now the readLine method will read all the way to the end of the
line, not just the first 1024 characters of it.

Change-Id: If15b491aa9a1e4fd9b8bbed2dd9e6be47a64ccb7
Signed-off-by: Chris Gavin <chris@chrisgavin.me>
2016-01-21 17:07:57 +01:00
Laurent Delaigue 1e1fb9fc59 Add progress monitor to Merger
Monitoring progress of merges can be useful for users for large
repositories or complex merge processes that take some time.

This enables setting a monitor. Existing merge implementations in jgit
do not yet report progress if a monitor is set. This will be added in a
later change.

Change-Id: I17b978b3fc91750dd88649638b90a46820a0877c
Signed-off-by: Laurent Delaigue <laurent.delaigue@obeo.fr>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-01-21 11:37:26 +01:00
Shawn Pearce 08aac5904e Merge "Fix TransportException when reading bundle" 2016-01-21 01:15:12 -05:00
Chris Gavin d2bf41e7dd Fix TransportException when reading bundle
When reading a bundle file, commit messages who's oneline format is
longer than 982 characters caused JGit to treat subsequent text in
the commit as a SHA, then throw a TransportException because it's
not a valid SHA.

Now the readLine method will read all the way to the end of the
line, not just the first 1024 characters of it.

Change-Id: If15b491aa9a1e4fd9b8bbed2dd9e6be47a64ccb7
Signed-off-by: Chris Gavin <chris@chrisgavin.me>
2016-01-21 01:14:56 -05:00
Shawn Pearce 8fe9a8baf5 Merge changes from topic 'reftree'
* changes:
  debug-rebuild-ref-tree: Copy HEAD into RefTree
  debug-rebuild-ref-tree: Add --enable flag to turn the database on
  RefTreeDatabase: Allow ORIG_HEAD, etc. on non-bare repositories
  RefTreeDatabase: Expose bootstrap refs in getAdditionalRefs
2016-01-21 00:32:17 -05:00
Shawn Pearce 8d0551dd64 Merge changes from topic 'ketch'
* changes:
  daemon: Add --ketch=LEADER flag
  Ketch: Intercept push and route it through Ketch
  Ketch: Simple map of running leader instances
  Ketch: Basic replication system
2016-01-20 23:15:09 -05:00
Shawn Pearce 7b6122908b Merge "TreeWalk: Remove CorruptObjectException from addTree(AbstractTreeIterator)" 2016-01-20 11:03:47 -05:00
Shawn Pearce 2262a794b4 TreeWalk: Remove CorruptObjectException from addTree(AbstractTreeIterator)
This form of addTree() does not parse any objects and cannot throw the
declared checked exception.  Callers are being forced to try-catch
CorruptObjectException that cannot occur when the iterator instance
has already been constructed.

Change-Id: Id338035302903bab81569d1576eab063eee0885a
2016-01-20 07:41:08 -08:00
Christian Halstrick 7182cb2a26 Fix ResetCommand to return the resulting ref
ResetCommand was not returning the updated ref as a result of the call()
method. Since the ResetCommand is always updating the same ref (HEAD)
this should always be the HEAD ref.

Bug: 440750
Change-Id: I7974975c3ab05e68c208384e69cf0692ded6e8db
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-01-20 11:27:31 +01:00
Christian Halstrick da43d8d798 Add option to allow empty commits to CommitCommand
CommitCommand should allow to specify whether empty commits (commits
having the same tree as the sole predecessor commit) are allowed or not.
Similar to native git's "--allow-empty" flag.

The defaults differ between JGit and native git even after this change.
When not specifying paths then by default JGit allows to create empty
commits while native git does not. It would be API breaking to change
this now.

Bug: 460301
Change-Id: I88feb0c3ffb2c686b1d0594e669729b065cda4cb
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-01-20 11:14:19 +01:00
Shawn Pearce da5ef91ad0 daemon: Add --ketch=LEADER flag
Experimental flag to turn on the KetchLeader within this daemon JVM.
This is a manually elected leader process, set from the command line.
Remote followers for each repository are configured per-repository
using remote sections with ketch-type = FULL. For example:

Manually elected leader's $GIT_DIR/config:

  [ketch]
    name = A

  [remote "A"]
    ketch-type = FULL

  [remote "B"]
    url = git://127.0.0.1:9421/sample.git
    ketch-type = FULL

  [remote "C"]
    url = git://127.0.0.1:9422/sample.git
    ketch-type = FULL

Replica B and C daemons:

  git daemon \
    --export-all \
    --enable=receive-pack \
    --listen=127.0.0.1 --port=9421 \
    --base-path=$HOME/ketch_test/follower_one \
    $HOME/ketch_test/follower_one &

  git daemon \
    --export-all \
    --enable=receive-pack \
    --listen=127.0.0.1 --port=9422 \
    --base-path=$HOME/ketch_test/follower_two \
    $HOME/ketch_test/follower_two &

Change-Id: I165f85970a77e16b5263115290d685d8a00566f5
2016-01-19 23:05:28 -08:00
Shawn Pearce 1f9d205043 Ketch: Intercept push and route it through Ketch
Capture commands and pass to the in-process KetchLeader, allowing
it to replicate to followers.

Change-Id: I25dfeb2a93821af65354337f391480a72bae2210
2016-01-19 23:04:41 -08:00
Shawn Pearce b718e3d304 Ketch: Simple map of running leader instances
Supports use in basic daemons where RepositoryCache is also effective.

Change-Id: Ia736b32c2c710b5a802233badc0d30818de763cd
2016-01-19 23:03:35 -08:00
Shawn Pearce 9b33f4aeeb Ketch: Basic replication system
Git Ketch is a multi-master Git repository management system.  Writes
are successful only if a majority of participant servers agree.  Acked
writes are durable against server failures as a majority of the
participants store all required objects.

Git Ketch is modeled on the Raft Consensus Algorithm[1].  A ketch
sailing vessel is faster and more nimble than a raft.  It can also
carry more source codes.

Git Ketch front-loads replication costs, which vaguely resembles a
ketch sailing vessel's distinguishing feature of the main mast on the
front of the ship.

[1] https://raft.github.io/
Change-Id: Ib378dab068961fc7de624cd96030266660b64fb4
2016-01-19 23:03:32 -08:00
David Pursehouse aca07fac46 Merge branch 'stable-4.2'
* stable-4.2:
  CheckoutCommandTest: Create Git instances in try-with-resource
  BranchCommandTest: Create Git instances in try-with-resource
  CheckoutTest: Create Git instances in try-with-resource
  BranchTest: Create Git instances in try-with-resource
  URIishTest: Use @Test annotation's `expected` argument
  Suppress "The allocated object is never used" warning in tests
  Add $NON-NLS to suppress "Non-externalized string literal" warnings
  Don't use deprecated constructors of CmdLineException
  Prepare 4.2.0-SNAPSHOT builds
  Remove org.eclipse.jgit.updatesite project from tools/version.sh
  RevParse: Remove superfluous semicolon
  RefUpdateTest: Use try-with-resource for auto-closable types
  RefUpdateTest: Add null check to prevent potential NPE
  CommitCommand: Remove redundant null check
  JGit v4.2.0.201512141825-rc1

Change-Id: I2179859289b2f2e3d0b7c6d02ef7e7890c467f7b
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
2016-01-20 09:45:48 +09:00
Dave Borowitz 2ccea7f05a ChangeIdUtil: Don't throw IOException
This could have only happened during the getBytes call. Instead, use
Constants.encode, which is a non-throwing implementation.

This change is binary compatible with existing code compiled against
older versions of JGit, although it might break compilation of
previously compiling code due to dead catch blocks.

Change-Id: I191fec5cac718657407230de141440e86d0151fb
2016-01-19 17:59:19 -05:00
Shawn Pearce a693d7b33c Merge "Transport: Implement AutoCloseable" 2016-01-19 17:36:39 -05:00
Shawn Pearce 6b662af76e Transport: Implement AutoCloseable
After creating a Transport instance callers should always call
its close() method. Use AutoCloseable to document this idiom
and allow use of try-with-resources.

Change-Id: I0c6ff3e39ebecdd7a028dbcae1856a818937b186
2016-01-19 14:27:11 -08:00
Shawn Pearce 68a6d0c0ab Merge changes from topic 'deadtree'
* changes:
  Ignore API errors about Tree, TreeEntry, FileTreeEntry and friends being removed
  Revert "Revert "Remove deprecated Tree, TreeEntry, FileTreeEntry and friends""
2016-01-19 17:08:54 -05:00
Shawn Pearce 9d3b56a905 Merge "ReceiveCommand.abort(): Utility to mark batch of commands as failed" 2016-01-19 15:54:07 -05:00
Shawn Pearce 462017e02b Ignore API errors about Tree, TreeEntry, FileTreeEntry and friends being
removed

Bug: 486105
Change-Id: I04adcdb68bee7d5f608bb7ab959fe36a890f9ecd
2016-01-19 18:49:11 +01:00
Andrey Loskutov 7f31a9c9ad Revert "Revert "Remove deprecated Tree, TreeEntry, FileTreeEntry and
friends""

This reverts commit 2cc80187d3.

Bug: 486105
Change-Id: Id4f9987c33d66cbed9de6e4d4d6784afdd01a3cf
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2016-01-19 18:48:48 +01:00
David Pursehouse 9ddc0ed83d Add $NON-NLS to suppress "Non-externalized string literal" warnings
Change-Id: I3e6f83ad2bc7d493e2c1ab5a8c60affa2b49c386
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
2016-01-19 17:27:45 +01:00
Andrey Loskutov 2006e90abc Annotated to be removed Tree API with @noreference and @noextend
See https://wiki.eclipse.org/Eclipse/API_Central/API_Removal_Process.

Bug: 486105
Change-Id: I460e43da0d487279608729a2081c614e7065f56f
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2016-01-19 14:27:41 +01:00
Matthias Sohn 20f272a71c Prepare 4.2.0-SNAPSHOT builds
Change-Id: Ibe38a95bf36db0c0ed948280b28c416943ec0329
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-01-19 13:10:20 +01:00
Shawn Pearce eadfcd3ec1 ReceiveCommand.abort(): Utility to mark batch of commands as failed
If one or more commands is failing the entire group usually has to
also fail with "transaction aborted". Pull this loop into a helper
so the idiom can be easily reused in several places throughout JGit.

Change-Id: I3b9399b7e26ce2b0dc5f7baa85d585a433b4eaed
2016-01-18 11:39:09 -08:00
Shawn Pearce bbfca06d64 RefTreeDatabase: Allow ORIG_HEAD, etc. on non-bare repositories
Store these in the bootstrap layer where they are using $GIT_DIR
as the storage directory for any reference that does not contain '/'.

Change-Id: I5595bf514e4475b7c7e799c2c79446597a3abb4a
2016-01-15 12:46:33 -08:00
Shawn Pearce a290b822ab RefTreeDatabase: Expose bootstrap refs in getAdditionalRefs
By showing the bootstrap layer in getAdditionalRefs() garbage
collector code can be more RefDatabase agnostic and not care about
the special case of RefTree and RefTreeNames for the purposes of
building up the roots to GC. Instead they can combine getRefs(ALL)
and getAdditionalRefs() and have a clean set of roots.

Change-Id: I665cd2456e9316640215b6a08bc728d1356f36d8
2016-01-15 11:07:19 -08:00
Shawn Pearce f52581c6a5 Merge "Revert "Remove deprecated Tree, TreeEntry, FileTreeEntry and friends"" 2016-01-15 10:45:43 -05:00
Shawn Pearce 2cc80187d3 Revert "Remove deprecated Tree, TreeEntry, FileTreeEntry and friends"
This reverts commit 0f8743d4d7.

JGit is unable to iterate its API.

Change-Id: Ie3d6a28e622a5c0cf54768a2299f1c44c0114c19
2016-01-15 10:45:36 -05:00
David Pursehouse 1ed5382b37 CommitCommand: Remove redundant null check
Repository.getWorkTree is annotated as @NonNull, so the check
for it returning null is redundant.

Change-Id: I597b0f774ff857b8900519f14a1a17a904cf7c6f
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
2016-01-14 15:04:34 +09:00
Shawn Pearce 95bdc589b8 Merge "PackWriter: Declare preparePack object sets as @NonNull" 2016-01-12 19:45:40 -05:00
Shawn Pearce 4e650c0d76 PackWriter: Declare preparePack object sets as @NonNull
Require callers to pass in valid sets for both want and have
collections. Offer PackWriter.NONE as a handy constant for an
empty collection for the have part of preparePack instead of null.

Change-Id: Ifda4450f5e488cbfefd728382b7d30797e229217
2016-01-12 19:30:32 -05:00
Shawn Pearce 17580101f5 Merge "GC: Pack RefTrees in their own pack" 2016-01-12 18:49:02 -05:00
Shawn Pearce 40051505d7 GC: Pack RefTrees in their own pack
The RefTree graph needs to be quickly accessed to read references.
It is also distinct graph disconnected from the rest of the
repository. Store the commit and tree objects in their own pack.

Change-Id: Icbb735be8fa91ccbf0708ca3a219b364e11a6b83
2016-01-12 12:15:53 -08:00
Shawn Pearce 9e3d391953 Change to extensions.refsStorage
git-core just rerolled the extensible backends series with refsStorage
as the configuration key. Update JGit to match git-core.

Change-Id: If345a2403a996e358b29cfa2a2298f6e8d59d96b
2016-01-11 20:44:10 -08:00
Shawn Pearce 398d8e877f RefTree: Change peel suffix to " ^" (space carrot)
Using ^{} as the peel suffix has caused problems when projects used
tags like v2.1 and then v2.1.1, v2.2.2, etc.  The peeled value for
v2.1 was stored very far away in the tree relative to v2.1 itself as
^ sorts in the ASCII/UTF-8 encoding after all other common tag
characters like digits and dots.

Use " ^" instead as space is not valid in a reference name, sorts
before all other valid reference characters (thus forcing next entry
locality) and this looks like a peeled marker for the prior tag.

Change-Id: I26d2247a0428dfe26a9c319c02159502b3a67455
2016-01-11 15:27:14 -08:00
Shawn Pearce 088c2fc6e3 FileRepository: Support extensions.refsBackendType = RefTree
This experimental code can be enabled in $GIT_DIR/config:

  [core]
    repositoryformatversion = 1

  [extensions]
    refsBackendType = RefTree

When these are set the repository will read references from the
RefTree rooted by the $GIT_DIR/refs/txn/committed reference.

Update debug-rebuild-ref-tree to rebuild refs/txn/committed only from
the bootstrap layer.  This avoids misuse by rebuilding using packed-refs
and $GIT_DIR/refs tree.

Change-Id: Icf600e4a36b2f7867822a7ab1f1617d73c710a4b
2016-01-11 15:27:07 -08:00
Shawn Pearce 48e245fc60 RefTreeDatabase: Ref database using refs/txn/committed
Instead of storing references in the local filesystem rely on the
RefTree rooted at refs/txn/committed.  This avoids needing to store
references in the packed-refs file by keeping all data rooted under
a single refs/txn/committed ref.

Performance to scan all references from a well packed RefTree is very
close to reading the packed-refs file from local disk.

Storing a packed RefTree is smaller due to pack file compression,
about 49.39 bytes/ref (on average) compared to packed-refs using
~65.49 bytes/ref.

Change-Id: I75caa631162dc127a780095066195cbacc746d49
2016-01-11 15:26:42 -08:00
Shawn Pearce 8f31aa7c28 Merge "RevCommit: Better support invalid encoding headers" 2016-01-11 15:48:16 -05:00
Shawn Pearce 31d92ace5b RevCommit: Better support invalid encoding headers
With this support we no longer need the 'utf-8' alias. UTF-8 will be
automatically tried when the encoding header is not recognized and used
if the character sequence cleanly decodes as UTF-8.

Modernize some of the references to use StandardCharsets.

Change-Id: I4c0c88750475560e1f2263180c4a98eb8febeca0
2016-01-11 12:30:35 -08:00
Shawn Pearce 0f8743d4d7 Remove deprecated Tree, TreeEntry, FileTreeEntry and friends
These types were deprecated in 0.9.1 (aka 384a19eee0).
If anyone is still using them, its time to stop.

Change-Id: I3f73347ba78c639e0c6a504812bc1a0702f829b1
2016-01-09 09:45:33 -08:00
Shawn Pearce 1243e25aad Paths.pathCompare: Utility to sort paths from byte[]
Consolidate copies of this function into one location.

Add some unit tests to prevent bugs that were accidentally
introduced while trying to make this refactoring.

Change-Id: I82f64bbb8601ca2d8316ca57ae8119df32bb5c08
2016-01-09 09:44:57 -08:00
Shawn Pearce bace383507 Add Paths utility class
Simple container for some path related utility functions.

Change-Id: Ice2bec6ad12b1e2cea15988c01aa9dd4e016a849
2016-01-08 16:58:23 -08:00
Shawn Pearce 73eb32be82 RefTree: Store references in a Git tree
A group of updates can be applied by updating the tree in one step,
writing out a new root tree, and storing its SHA-1. If references
are stored in RefTrees, comparing two repositories is a matter of
checking if two SHA-1s are identical. Without RefTrees comparing two
repositories requires listing all references and comparing the sets.

Track the "refs/" directory as a root tree by storing references
that point directly at an object as a GITLINK entry in the tree.
For example "refs/heads/master" is written as "heads/master".

Annotated tags also store their peeled value with ^{} suffix, using
"tags/v1.0" and "tags/v1.0^{}" GITLINK entries.

Symbolic references are written as SYMLINK entries with the blob of
the symlink carrying the name of the symbolic reference target.

HEAD is outside of "refs/" namespace so it is stored as a special
"..HEAD" entry. This name is chosen because ".." is not valid in
a reference name and it almost looks like "../HEAD" which names
HEAD if the reader was inside of the "refs/" directory.

A new Command type is required to handle symbolic references and
peeled references.

Change-Id: Id47e5d4d32149a9e500854147edd7d93c1041a39
2016-01-07 15:40:26 -08:00
Shawn Pearce 5001038f52 Merge "InMemoryRepository: Abort BatchRefUpdate if a command previously failed" 2016-01-06 15:18:04 -05:00
Shawn Pearce 4c9eda17be InMemoryRepository: Abort BatchRefUpdate if a command previously failed
If any command has already been marked as failing, fail the entire batch.

Change-Id: I1692240841aa4f4cb252bdccbc6f11d9246929c1
2016-01-06 12:05:46 -08:00
Shawn Pearce f0d634eed7 DFS: Allow other RefDatabase implementations
Permit a DfsRepository implementation to use a different RefDatabase
than DfsRefDatabase.

Change-Id: Ia263285f547bde1943993cc994d0222185021a16
2016-01-06 11:54:45 -08:00
Matthias Sohn 91a3f17474 Merge changes Idaed9310,I62bd7c0b
* changes:
  ObjectChecker: honor some git-core fsck.* options
  ObjectChecker: allow some objects to skip errors
2016-01-03 10:27:37 -05:00
Shawn Pearce 163be57d0f Merge changes from topic 'add-df'
* changes:
  DirCache: Do not create duplicate tree entries
  DirCacheEditor: Replace file-with-tree and tree-with-file
  AddCommand: Use NameConflictTreeWalk to identify file-dir changes
2016-01-01 12:58:35 -05:00
Shawn Pearce 09500165a8 Fix "remote: Counting objects: ..." formatting
Trailing whitespace is usually removed in properties files so
JGitText did not supply a space between : and the remote message.
Ensure the space exists at runtime by reading the localized string
and appending a space if it is missing.

Messages should be dynamically fetched and not held in a static
class variable, as they can be changed using thread locals.

Change-Id: If6a3707d64094253b1a5304fbfafcf195db7497a
2015-12-31 17:37:16 -08:00
David Ostrovsky 13502fef8f Implement Buck driven build
Today there are plenty of modern build tool systems available in the
wild (in no particular order):

* http://bazel.io
* https://pantsbuild.github.io
* http://shakebuild.com
* https://ninja-build.org
* https://buckbuild.com

The attributes, that all these build tools have in common, are:

* reliable
* correct
* very fast
* reproducible

It must not always be the other build tool, this project is currently
using. Or, quoting Gerrit Code Review maintainer here:

  "Friends, don't let friends use <the other build tool system>!"

This change is non-complete implementation of JGit build in Buck,
needed by Gerrit Code Review to replace its dependency with standlone
JGit cell. This is very useful when a developer is working on both
projects and is trying to integrate changes made in JGit in Gerrit.

The supported workflow is:

  $ cd jgit
  $ emacs <hack>
  $ cd ../gerrit
  $ buck build --config repositories.jgit=../jgit gerrit

With --config repositories.jgit=../jgit jgit cell is routed through
JGit development tree.

To build jgit, issue:

  $ buck build //:jgit
  [-] PROCESSING BUCK FILES...FINISHED 0,0s

Yes, you can't measure no-op build time, given that Buck daemon is
used.

Change-Id: I301a71b19fba35a5093d8cc64d4ba970c2877a44
Signed-off-by: David Ostrovsky <david@ostrovsky.org>
2015-12-31 10:08:55 -08:00
Shawn Pearce 2fbd98dbe8 Merge "Fix encoding problem from curl repostory on github" 2015-12-30 23:47:28 -05:00
Shawn Pearce 80edcac06f Merge "Fix hanging fetch via SSH" 2015-12-30 23:27:09 -05:00
Eryk Szymanski 53c3bbe42f Fix encoding problem from curl repostory on github
Pushing curl repository to gerrit fails with a message:
remote: error: internal error while processing changes
java.nio.charset.IllegalCharsetNameException: 'utf8'

curl repository url: https://github.com/bagder/curl.git

To avoid this problem encodingAliases in RawParseUtils have
been extended to contain "'utf8'" (single quoted utf8) string.

Change-Id: I40f613cfdcabf0dc9455bee45116ab8d8c7dd6ee
Signed-off-by: Eryk Szymanski <eryksz@gmail.com>
2015-12-30 23:24:12 -05:00
Shawn Pearce ac41920a43 ObjectChecker: honor some git-core fsck.* options
Accept some of the same section keys that fsck does in git-core,
allowing repositories to skip over specific kinds of acceptable
broken objects, e.g.:

  [fsck]
    duplicateEntries = ignore
    zeroPaddedFilemode = ignore

The zeroPaddedFilemode = ignore is a synonym for the JGit specific
allowLeadingZeroFileMode = true. Only accept the JGit key if git-core
key was not specified.

Change-Id: Idaed9310e2a5ce5511670ead1aaea2b30aac903c
2015-12-30 15:19:09 -08:00
Shawn Pearce fa7ce0e0f3 ObjectChecker: allow some objects to skip errors
Some ancient objects may be broken, but in a relatively harmless way.
Allow the ObjectChecker caller to whitelist specific objects that are
going to fail checks, but that have been reviewed by a human and decided
the objects are OK enough to permit continued use of.

This avoids needing to rewrite history to scrub the broken objects out.

Honor the git-core fsck.skipList configuration setting when receiving a
push or fetching from a remote repository.

Change-Id: I62bd7c0b0848981f73dd7c752860fd02794233a6
2015-12-30 15:18:48 -08:00
Matthias Sohn 3fc93f8a56 Rename files using NIO2 atomic rename
Bug: 319233
Change-Id: I5137212f5cd3195a52f90ed5e4ce3cf194a13efd
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-12-30 17:22:33 -05:00
Shawn Pearce e3acf01748 ObjectChecker: use java.text.Normalizer directly
Base Java version for JGit is now Java 7. The java.text.Normalizer
class was available in Java 6. Reflection is no longer required to
normalize strings for Mac OS X.

Change-Id: I98e14b72629a7a729a2d40a3aa275932841274e8
2015-12-30 15:45:13 -05:00
Shawn Pearce 7177b506b4 Merge changes I3db332bf,I614e7110,I37a4ccd6,I86b81e7f,Ic8b362e0, ...
* changes:
  Sort "eager" path-like options to the end of the help
  reset command: provide convenient and meaningful options help
  commit command: allow to specify path(s) argument(s)
  status command: consume more then one argument after --
  repo command: properly name the required 'path' argument
  Un-ignored existing CLI tests which run just fine on Java 7+
  Don't treat command termination due '-h' option as a fatal error
2015-12-30 15:44:30 -05:00
Shawn Pearce 018a91b715 Unify fetch and receive ObjectChecker setup
This avoids duplication of code between receive-pack and fetch-pack paths.
Separate methods are still required to check use of receive.fsckobjects vs.
fetch.fsckobjects, both of which default to transfer.fsckobjects.

Change-Id: I41193e093e981a79fc2f63914e273aaa44b82162
2015-12-29 16:55:41 -08:00
Shawn Pearce 29aa444760 PackWriter: use lib.ObjectIdSet to avoid wrapper
Hoist ObjectIdSet up to lib as part of the public API and add
the interface to some common types like PackIndex and JGit custom
ObjectId map types.  This cleans up wrapper code in a number of
places by allowing direct use of the types as an ObjectIdSet.

Future commits can now rely on ObjectIdSet as a simple read-only
type to check a set of objects from a number of storage options.

Change-Id: Ib62b062421d475bd52abd6c84a73916ef36e084b
2015-12-29 15:32:24 -08:00
Shawn Pearce 683c41af92 DirCache: Do not create duplicate tree entries
If a file (e.g.  "A") and a subtree file (e.g. "A/foo.c") both appear
in the DirCache this cache should not be written out as a tree object.
The "A" file and "A" subtree conflict with each other in the same tree
and will fail fsck.

Detect this condition during DirCacheBuilder and DirCacheEditor
finish() so the application can be halted early before it updates a
DirCache that might later write an invalid tree structure.

Change-Id: I95660787e88df336297949b383f4c5fda52e75f5
2015-12-29 11:33:39 -08:00
Shawn Pearce b71ba69410 DirCacheEditor: Replace file-with-tree and tree-with-file
If a PathEdit tries to store a file where a subtree was, or a subtree
where a file was, replace the entry in the DirCache with the new
name(s).  This supports switching between file and tree entry types
using a DirCacheEditor.

Add new unit tests to cover the conditions where these can happen.

Change-Id: Ie843d9388825f9e3d918a5666aa04e47cd6306e7
2015-12-29 11:33:39 -08:00
Shawn Pearce 3776b14ab4 AddCommand: Use NameConflictTreeWalk to identify file-dir changes
Adding a path that already exists but is changing type such as
from symlink to subdirectory requires a NameConflictTreeWalk to
match up the two different entry types that share the same name.

NameConflictTreeWalk needs a bug fix to pop conflicting entries
when PathFilterGroup aborts the walk early so that it does not
allow DirCacheBuilderIterator to copy conflicting entries into
the output cache.

Change-Id: I61b49cbe949ca8b4b98f9eb6dbe7b1f82eabb724
2015-12-29 11:33:35 -08:00
Andrey Loskutov 0505657d6a commit command: allow to specify path(s) argument(s)
This fixes the command below:

jgit commit a -m "added file a"

which currently fails with:

org.eclipse.jgit.api.errors.JGitInternalException: The combination of
arguments --all and --only is not allowed

Bug: 484973
Change-Id: I37a4ccd68101a66520ef99110f7aa0cbdcc8beba
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-12-29 15:00:09 +01:00
Andrey Loskutov 241b50be31 Simplify development of commands: added main() to CLIGitCommand
This will execute git commands (with arguments) specified on the command
line, handy for developing/debugging a sequence of arbitrary git
commands working on same repository.

The git working dir path can be specified via Java system property
"git_work_tree". If not specified, current directory will be used.

Change-Id: I621a9ec198c31e28a383818efeb4b3f835ba1d6f
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-12-28 22:59:59 +01:00
Shawn Pearce ef757a7e12 DirCacheEditor: Cleanup DeleteTree constructor
Neaten up formatting and avoid strings, which prevents the need for
NLS comment tags.  Instead check the last character using char
literal, and append a char literal instead of a string.

Change-Id: Ib68e017769a1f5c03200354a805769d585a48c8b
2015-12-28 11:43:31 -08:00
Shawn Pearce 110d3ca595 DirCacheEditor: Fix formatting to avoid , at start of line
Change-Id: I1b1d614470c67fe4736fdc9c26ae26fb38dd58b5
2015-12-28 11:43:30 -08:00
Shawn Pearce 21cec184b7 Merge "AddCommand: Avoid unnecessary string conversions" 2015-12-28 14:24:33 -05:00
Christian Halstrick 2fdce1ef8c Merge "AddCommand: Cleanup conditional logic" 2015-12-28 08:39:07 -05:00
Shawn Pearce a94e517940 AddCommand: Avoid unnecessary string conversions
Change-Id: I13634caeccd9f675a86adfdfa94099b6fb75463a
2015-12-23 22:26:50 -08:00
Shawn Pearce bb8627bd9b AddCommand: Cleanup conditional logic
Unnest and simplify conditional logic for handling entries.

Change-Id: I3093cab5f0edfaf3efbbd6c644e9c922edc67d38
2015-12-23 20:31:15 -08:00
Dmitry Neverov 9c71bf14b7 Close copy threads in case of errors
Bug: 484775
Change-Id: I3c7105188e615b6b994261f4ece0c8abc98eb444
Signed-off-by: Dmitry Neverov <dmitry.neverov@gmail.com>
2015-12-24 01:20:14 +01:00
Yuxuan 'fishy' Wang d88695e412 Skip nested copyfiles in RepoCommand.
Similar to nested directories, nested copyfiles won't work with git submodule
either.

Change-Id: Idbe965ec20a682fca0432802858162f8238f05de
Signed-off-by: Yuxuan 'fishy' Wang <fishywang@google.com>
2015-12-22 14:05:35 -08:00
Andrey Loskutov 1aafa61958 Checkout should be able to override modified symbolic links
Handle existing symlink as a file, not as directory if deleting a file
before creating (overriding) a symlink.

Bug: 484491
Change-Id: I29dbf57d1daec2ba98454975b093e1d381d05196
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-12-17 10:42:44 +01:00
Shawn Pearce 8cfbbc9f54 Merge "ProgressSpinner: Simple busy wait entertainment" 2015-12-16 16:20:59 -05:00
Shawn Pearce a38531b21c ProgressSpinner: Simple busy wait entertainment
Keep a user amused while the server does work by spinning a
little ASCII-art object on a single line.

Change-Id: Ie8f181d1aa606d4ae69e5d3ca4db387cea739f38
2015-12-16 15:43:07 -05:00
James Kolb 3096a13340 Included cached deltas in delta packStatistics.
Previously, non-reuse deltas were only included in packStatistics if they
were not cached by the deltaWindow.

Change-Id: I7684d8214875f0a7569b34614f8a3ba341dbde9c
Signed-off-by: James Kolb <jkolb@google.com>
2015-12-16 14:06:16 -05:00
Jonathan Nieder cfa0b2fb3c Merge changes Ib4d53bdd,I55bd512c
* changes:
  Do not let PathFilter.create("a/b") match 'a' unless 'a' is a subtree
  Add tests for PathFilterGroup.Single
2015-12-16 12:09:49 -05:00
Shawn Pearce a3e9876d8f Merge "Fix InterruptTimer leak in BasePackConnection" 2015-12-16 10:29:02 -05:00
Matthias Sohn 6340c76d8b Fix InterruptTimer leak in BasePackConnection
When setting timeout on push, BasePackConnection creates a timer, which
will be terminated when push finishes. But, when using
SmartHttpPushConnection, it dropped the first timer created in the
constructor and then created another timer in doPush. If new threads are
created faster than the gc collects then this may stop the service if
it's hitting the max process limit. Hence don't create a new timer if it
already exists.

Bug: 474947
Change-Id: I6746ffe4584ad919369afd5bdbba66fe736be314
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-12-16 14:19:38 +01:00
Shawn Pearce 7c5b2761ed Merge "Refspec: loosen restrictions on wildcard "*"" 2015-12-15 23:22:12 -05:00
Shawn Pearce 9eda23e469 Merge "BaseRepositoryBuilder should trim CR from .git symref" 2015-12-15 23:18:14 -05:00
Shawn Pearce 8b749f7de5 Merge "Fix possible arithmetic overflow when setting a timeout" 2015-12-15 23:16:21 -05:00
Shawn Pearce fcd796a9a0 Merge "Accept UTF8 BOM with BlobBasedConfig" 2015-12-15 23:12:56 -05:00
Shawn Pearce 6297c2e92c Merge "Bug 484342: Support @ in username in SSH url." 2015-12-15 23:09:31 -05:00
Jonathan Nieder 75a0dcac18 Do not let PathFilter.create("a/b") match 'a' unless 'a' is a subtree
PathFilter and PathFilterGroup form JGit's implementation of git's
path-limiting feature in commands like log and diff.  To save time
when traversing trees, a path specification

	foo/bar/baz

tells the tree walker not to traverse unrelated trees like qux/.  It
does that by returning false from include when the tree walker is
visiting qux and true when it is visiting foo.

Unfortunately that test was implemented to be slightly over-eager: it
doesn't only return true when asked whether to visit a subtree "foo"
but when asked about a plain file "foo" as well.  As a result, diffs
and logs restricted to some-file/non-existing-suffix unexpectedly
match against some-file:

 $ jgit log -- LICENSE/no-such-file
 commit 629fd0d594
 Author: Shawn O. Pearce <spearce@spearce.org>
 Date:   Fri Jul 02 14:52:49 2010 -0700

     Clean up LICENSE file
[...]

Fix it by checking against the entry's mode.

Gitiles +log has the same bug and benefits from the same fix.

Callers know not to worry about what subtrees are included in the tree
walk because shouldBeRecursive() returns true in this case, so this
behavior change should be safe.  This also better matches the behavior
of C git:

 $ empty=$(git mktree </dev/null)
 $ git diff-tree --abbrev $empty HEAD -- LICENSE/no-such-file
 $ git diff-tree --abbrev $empty HEAD -- tools/no-such-file
 :000000 040000 0000000... b62648d... A  tools

Bug: 484266
Change-Id: Ib4d53bddd8413a9548622c7b25b338d287d8889d
2015-12-15 15:22:10 -08:00
Mike Gilbode 3e03907f65 Bug 484342: Support @ in username in SSH url.
Change-Id: I5795e925afff796488ba26c83694e806b76a374f
Signed-off-by: Mike Gilbode <gilbode@gmail.com>
2015-12-15 10:44:16 -05:00
Matthias Sohn 2647d024af Fix push with jgit pgm failing with "unauthorized"
Pushing with JGit commandline to e.g. Github failed with "unauthorized"
since HttpUrlConnection calls the configured authenticator implicitly.

The problem is that during a push two requests are sent to the server,
first a GET and then a POST (containing the pack data). The first GET
request sent anonymously is rejected with 401 (unauthorized). When an
Authenticator is installed the java.net classes will use the
Authenticator to ask the user for credentials and retry the request.
But this happens under the hood and JGit level code doesn't see that
this happens.

The next request is the POST but since JGit thinks the first GET request
went through anonymously it doesn't add authentication headers to the
POST request. This POST of course also fails with 401 but since this
request contains a lot of body-data streamed from JGit (the pack file!)
the java.net classes can't simply retry the request with authorization
headers. The whole process fails.

Fix this by using Apache httpclient which doesn't use Authenticator to
retrieve credentials. Instead initialize TransportCommand to use the
default credential provider if no other credentials provider was set
explicitly. org.eclipse.jgit.pgm.Main sets this default for the JGit
command line client.

Change-Id: Ic4e0f8b60d4bd6e69d91eae0c7e1b44cdf851b00
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-12-15 12:49:08 +01:00
Christian Halstrick 5c66ad5684 Merge "NetRCCredentialsProvider should return false if any item is missing" 2015-12-15 06:44:08 -05:00
Christian Halstrick 2f0b675a71 Merge "Fix ChainingCredentialsProvider" 2015-12-15 03:52:09 -05:00
Christian Halstrick 310e858f81 Fix possible arithmetic overflow when setting a timeout
BasePackPushConnection#readStringLongTimeout() was setting a timeout 10
times bigger than some other timeout or the pack transfer time. This
could lead to negative integer values when we hit an arithmetic
overflow. Add a check for this situation and set the timeout to
Integer.MAX_VALUE when overflow happens.

Bug: 484352
CC: Eugene Petrenko <eugene.petrenko@gmail.com>
Change-Id: Ie2a86312c1bcb1ec3e6388fa490ab3c845d41808
2015-12-15 09:44:09 +01:00
Andrey Loskutov 95b36b397b Null-annotated Ref class and fixed related compiler errors
This change fixes all compiler errors in JGit and replaces possible
NPE's with either appropriate exceptions, avoiding multiple "Nullable
return" method calls or early returning from the method.

Change-Id: I24c8a600ec962d61d5f40abf73eac4203e115240
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-12-15 09:07:05 +01:00
Matthias Sohn d2044aed4f JGit v4.2.0.201512141825-rc1
Change-Id: Id725ea888acd23793d37de2864ec0727160a2eaf
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-12-15 00:22:13 +01:00
Shawn Pearce 8179185d11 Merge "push: Do not blindly overwrite peer" 2015-12-14 17:45:57 -05:00
Shawn Pearce 4f8c993c49 push: Do not blindly overwrite peer
If an application uses PushConnection directly on the native Git wire
protocols JGit should send along the application's expected oldId, not
the advertised value.  This allows the remote peer to compare-and-swap
since it was not tested inside JGit.

Discovered when I tried to use a PushConnection (bypassing the
standard PushProcess) and the client blindly overwrote the remote
reference, even though my app had supplied the wrong ObjectId for
the expectedOldObjectId. This was not expected and cost me over an
hour of debugging, plus "corruption" in the remote repository.

By passing along the exact expectedOldObjectId from the app the
remote side can do the check that the application skipped, and
avoid data loss.

Change-Id: Id3920837e6c47100376225bb4dd61fa3e88c64db
2015-12-14 09:18:27 -08:00
Christian Halstrick 5b55498b16 Fix FileTreeIterator.idSubmodule(Entry)
FileTreeIterator was calling by mistake
WorkingTreeIterator.idSubmodule(Entry). Instead it should always compute
idSubmodule on its own.

Change-Id: Id1b988aded06939b1d7edd2671e34bf756896c0e
2015-12-13 01:24:46 +01:00
Andrey Loskutov 85d09a9ec7 URIish: fixed full uri pattern not expecting end of line after host name
Bug: 483326
Change-Id: I8b6e3eb648c8ec2c38f73de22382537b1276b779
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-12-12 00:55:31 +01:00
Kaloyan Raev e23521f0d9 Add remote command to JGit CLI
Supported subcommands are:
 - <none> (lists available remotes)
 - add
 - remove
 - set-url
 - update
 
Supported options are:
 --verbose
 --push
 --prune

Bug: 481316
Change-Id: I57c34ed6daabb7d308bc383b17c1ef4af433e714
Signed-off-by: Kaloyan Raev <kaloyan.r@zend.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-12-11 22:54:48 +01:00
Doug Kelly 618b0c1ceb Accept UTF8 BOM with BlobBasedConfig
In I1f5dc07182dbf6bba2a9f4807fdd25b475da4ead, FileBasedConfig got
support for reading a configuration with UTF8 BOM.  Apply the same
support to BlobBasedConfig, to make SubmoduleWalk able to parse
.gitmodules configurations with BOM.

Change-Id: I25b5474779952fe2c076180b96fc2869eef190a8
Signed-off-by: Doug Kelly <dougk.ff7@gmail.com>
2015-12-09 16:48:20 -06:00
Matthias Sohn afd167a1f2 NetRCCredentialsProvider should return false if any item is missing
Change-Id: I894d1621aaccd71dfe100fe83a1bd9d50a1e0808
2015-12-08 14:12:26 +01:00
Matthias Sohn 5786cc3c0f Fix ChainingCredentialsProvider
The ChainingCredentialsProvider gave up chaining to the next provider if
the first one returned no credentials items for the given URI.

Change-Id: I9539c50db35e564db9d43d8ebb71d7e9c6fdcc19
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-12-08 14:12:26 +01:00
Christian Halstrick 6dfad98d72 Merge "Fix NPE in HttpAuthMethod" 2015-12-08 02:25:35 -05:00
Jonathan Nieder e12482deed Use runtime retention for Nullable annotation
JGit's Nullable type was added[1] in the hope of being able to add
nullness annotations that (a) do not preclude building and running
with Java 7 and (b) could be shared by Gerrit, which uses a custom
Nullable type for other reasons[2].  Sharing a type is useful because
Eclipse's null analysis is only able to use one Nullable type at a
time in a given workspace (so for this analysis to function in a
workspace used to develop Gerrit, JGit and Gerrit would need to use
the same Nullable type).

The new Nullable type has CLASS instead of RUNTIME retention because
there wasn't any obvious use for the annotation at run time.

Gerrit uses the Nullable annotation to communicate with Guice.  Guice
injection happens at runtime, so it needs to be able to read the
@Nullable annotations at run time[3].  Otherwise Guice produces
provisioning errors, such as

 3) null returned by binding at com.google.gerrit.lucene.LuceneChangeIndex$Factory.create()
  but parameter 7 of com.google.gerrit.lucene.LuceneChangeIndex.<init>() is not @Nullable

Switch to RUNTIME retention to avoid this.

While at it, update the javadoc to explain more clearly how this
annotation relates to other Nullable types[4].  This should make it
clearer why JGit needed another Nullable type:

 A. Avoiding dependency on Java 8
 B. RUNTIME retention to allow Guice to read the annotation at run time
 C. Named Nullable so Guice can recognize the annotation
 D. Not an addition to Java EE's javax.annotation package, to avoid
    the split-package problem[2] that prevents the annotation from
    being readable at run time when loaded from an OSGi container
 E. Avoiding heavyweight dependencies, deprecated dependencies, and
    dependencies on package internals

 org.checkerframework.checker.nullness.qual.Nullable: A
 com.sun.istack.internal.Nullable: B, E
 *.CheckForNull, *.NullAllowed, etc: C
 edu.umd.cs.findbugs.annotations.Nullable: B, E
 javax.annotation.Nullable: D
 org.eclipse.jdt.annotation.Nullable: B
 org.jetbrains.annotations.Nullable: B
 org.jmlspecs.annotation.Nullable: E
 android.annotation.Nullable, android.support.annotation.Nullable: E

[1] https://git.eclipse.org/r/59993
[2] https://gerrit-review.googlesource.com/50112
[3] https://github.com/google/guice/blob/master/core/src/com/google/inject/internal/Nullability.java
[4] https://github.com/typetools/checker-framework/blob/5832a01f1/checker/src/org/checkerframework/checker/nullness/NullnessAnnotatedTypeFactory.java#L118
    http://types.cs.washington.edu/checker-framework/current/checker-framework-manual.html#nullness-related-work

Change-Id: I6c482653d2b53e3509abb11211b67fc29cf2949c
Signed-off-by: Jonathan Nieder <jrn@google.com>
2015-12-07 19:26:23 -05:00
Matthias Sohn ac89b47eeb Fix NPE in HttpAuthMethod
If the password char array is null constructing a new String from this
array fails with a NPE. Add a null check to fix this.

Change-Id: Ifae6eecca38d5f114861f44658a32521e6e96866
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-12-07 16:05:19 +01:00
Shawn Pearce 3d8e6b1e16 Support atomic push in JGit client
This should mirror the behavior of `git push --atomic` where the
client asks the server to apply all-or-nothing. Some JGit servers
already support this based on a custom DFS backend. InMemoryRepository
is extended to support atomic push for unit testing purposes.

Local disk server side support inside of JGit is a more complex animal
due to the excessive amount of file locking required to protect every
reference as a loose reference.

Change-Id: I15083fbe48447678e034afeffb4639572a32f50c
2015-12-02 22:06:06 -08:00
Matthias Sohn f109af47d0 Fix wrong @since tag In ReceiveCommand
Change-Id: I58fa657dd4783fed0ffca94020c87c49d99009c6
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-12-02 15:24:26 +01:00
Shawn Pearce f89f30ffcd ReceiveCommand.filter: Accept Iterable
PreReceiveHook is given a Collection<ReceiveCommand> and it can be
very useful here to call ReceiveCommand.filter(cmds, NOT_ATTEMPTED).

Overload filter to accept both Iterable and List.
Keep backwards binary compatibility for List by upcasting to Iterable.

Change-Id: Ib1341876c703670945ef209edc8259715ee86c26
2015-12-01 19:59:03 -08:00
Shawn Pearce 8078021e8f Merge changes If1490ca2,Ife950253
* changes:
  DirCacheBuilder: Speed up reading from trees
  Delay locating .gitattributes until requested
2015-11-30 19:03:11 -05:00
Shawn Pearce 2d011cd648 DirCacheBuilder: Speed up reading from trees
Recursively copying a tree into a DirCache is a bottleneck for some
algorithms like the in memory merge code in Gerrit Code Review.  Drop
a layer down in the stack and use CanonicalTreeParser directly as the
addition logic only processes 1 tree at a time and does not need the
merge sorting feature (or overhead) of TreeWalk.

Combined with 761814fe9c ("DirCacheEntry: Speed up creation by
avoiding string cast") tree loading 38,900 entries nearly halves
in running time from 70ms to 36ms on some platforms.

Change-Id: If1490ca25de0679a71cf508f59b486f9cc816165
2015-11-30 15:46:40 -08:00
Shawn Pearce 93eca6dfe1 DirCache: Add helper to read from a tree
Application code sometimes wants to read a DirCache from an ObjectId,
but its confusing how to do this because its buried inside the
DirCacheBuilder.

Use this utility in a few places within JGit that also want to read
a DirCache from a tree's ObjectId.

Change-Id: I578b7e18e58753d154937f4ab835012b09e5adca
2015-11-29 22:05:24 -05:00
Shawn Pearce b0eb744604 Delay locating .gitattributes until requested
Instead of checking every entry for .gitattributes only look for the
entry on request by TreeWalk.  This avoids impacting uses like RevWalk
filtering history.

When the attrs is requested skip to the start of the tree and look for
.gitattributes until either it is found, or it is impossible to be
present.  Due to the sorting rules of tree entries .gitattributes
should be among the first or second entries in the tree so very few
entries will need to be considered.

Waiting to find the .gitattributes file by native ordering may miss
attrs for files like .config, which sorts before .gitattributes.
Starting from the front of the tree on demand ensures the attributes
are parsed as early as necessary to process any entry in the tree.

Due to TreeWalk recursively processing up the tree of iterators we
cannot just reset the current CanonicalTreeParser to the start as
parent parsers share the same path buffer as their children.
Resetting a parent to look for .gitattributes may overwrite path
buffer data used by a child iterator.  Work around this by building a
new temporary CanonicalTreeParser instance.

Change-Id: Ife950253b687be325340d27e9915c9a40df2641c
2015-11-29 18:56:49 -08:00
Shawn Pearce 45cc76524b DirCache: Fix bad code formatting
Line breaking before , is ugly to read.  Most formatters and humans
expect line break after , so update a few offensive locations.

Use String.format() for the construction of the error message when
a bad DirCachEntry is being failed on. This simplifies the code and
its not a performance critical section.

Change-Id: I5d990389e7ba24ef0861cf8ec0026ed030d4aeda
2015-11-28 09:28:09 -08:00
Shawn Pearce 761814fe9c DirCacheEntry: Speed up creation by avoiding string cast
The checkPath function is available as a byte[] form, in fact the
String form just converts to byte[] to run the algorithm.

Having DirCacheEntry take a byte[] -> String -> byte[] to check if
each path is valid is a huge waste of CPU time. On some systems it
can double the time required to read 38,999 files from trees to the
DirCache. This slows down any operation using a DirCache.

Expose the byte[] form and use it for DirCacheEntry creation.

Change-Id: I6db7bc793ece99ff3c356338d793c07c061aeac7
2015-11-28 09:01:03 -08:00
Shawn Pearce 885879ffe9 DirCache: Fix getEntriesWithin("") to not include null entries
The internal array may be longer than entryCnt, in this case the tail
of the array is padded with null entries. Do not return those to the
caller of getEntriesWithin().

Change-Id: I19efb05e103fab6b739ced407f6e28155a48dba6
2015-11-27 23:25:22 -08:00
Shawn Pearce 46e4992e92 Fix performance regression in CanonicalTreeParser
Change-Id: I14046559fddb9656d890d3099010117e84cd9439
2015-11-27 23:23:49 -08:00
Christian Halstrick bd31555ee5 Add support for smudge filters
If defined in .gitattributes call smudge filter during checkout.

To support checkout where current HEAD,index do not contain attributes
we need to also consider attributes from the tree we checkout. Therefore
CanonicalTreeParser has to learn how to provide attributes.

Change-Id: I168fdb81a8e1a9f991587b3e95a36550ea845f0a
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-11-27 23:33:53 +01:00
Christian Halstrick 5d9f595eb8 Add support for clean filters
When filters are defined for certain paths in gitattributes make
sure that clean filters are processed when adding new content to the
object database.

Change-Id: Iffd72914cec5b434ba4d0de232e285b7492db868
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-11-27 23:23:09 +01:00
Ivan Motsch 75697adc5a Add the new class Attributes holding multiple Attribute(s)
Attributes represents a semantic collector of Attribute(s) and replaces
the anonymous Map<String,Attribute>. This class will be returned by
TreeWalk.getAttributes(). It offers convenient access to the attributes
wrapped in the Attributes object. Adds preparations for a future
Attribute Macro Expansion

Change-Id: I8348c8c457a2a7f1f0c48050e10399b0fa1cdbe1
Signed-off-by: Ivan Motsch <ivan.motsch@bsiag.com>
2015-11-27 11:40:34 +01:00
Matthias Sohn 2cdc130dfc Add missing @since tags and missing javadoc
Change-Id: I8575797127fc96abea8af56f019ca39f5897486f
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-11-25 19:25:53 -05:00
Christian Halstrick 55fb18feaa Fix FS.runProcess() to close the InputStream
When FS.runProcess was called and an InputStream was given the method
tried to pump the whole InputStream to the process. When the method
ended the InputStream was not giving any data anymore. Consequently
close the InputStream inside the method.

Change-Id: I0ed738a775e5c977b21447d195acee1ecf5e2cb9
2015-11-26 00:36:09 +01:00
Jonathan Nieder fe98218e0d repo: Do not use search path to find refs/remotes/origin/<branch>
When running from a non-bare repository, "jgit repo" checks whether
the rev passed in is a sha1 or branch name and in the latter case will
check out origin/<branch>.

We are expecting refs/remotes/origin/<branch>, but as a side effect of
using getRef we also end up looking for refs/origin/<branch>,
refs/heads/origin/<branch>, and so on.  Avoid that by using exactRef
instead.

Signed-off-by: Jonathan Nieder <jrn@google.com>
Change-Id: I670b2e48a88138a1f2104ea201baa958e9edbddb
2015-11-25 14:05:24 -08:00
Jonathan Nieder 5be4814e38 Repository: Introduce exactRef and findRef, deprecate getRef
The Repository class provides only one method to look up a ref by
name, getRef.  If I request refs/heads/master and that ref does not
exist, getRef will look further in the search path:

 ref/refs/heads/master
 refs/heads/refs/heads/master
 refs/remotes/refs/heads/master

This behavior is counterintuitive, needlessly inexpensive, and usually
not what the caller expects.

Allow callers to specify whether to use the search path by providing
two separate methods:

- exactRef, which looks up a ref when its exact name is known
- findRef, which looks for a ref along the search path

For backward compatibility, keep getRef as a deprecated synonym for
findRef.

This change introduces findRef and exactRef but does not update
callers outside tests to use them yet.

Change-Id: I35375d942baeb3ded15520388f8ebb9c0cc86f8c
Signed-off-by: Jonathan Nieder <jrn@google.com>
2015-11-25 14:05:20 -08:00
Andrey Loskutov 830117e761 Null-annotated RefDatabase class
No other code changes except adding nullness annotations.

Change-Id: If2606fb208f6690bd4fd7ad953e709a3ebd6398c
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-11-25 21:19:05 +01:00
Andrey Loskutov 1020f40813 Null-annotated Repository class and fixed related compiler errors
org.eclipse.jgit.lib.Repository class is an example of the API which
should be written with Java 8 java.util.Optional<T> type. Unfortunately
this API is already released and widely used. The good clients are
currently doing their best with checking return values for null and bad
clients do not know how bad their code is.

I've tried not to change any logic and to be as less intrusive as
possible. Most of the JGit code was well prepared to this, only few
classes needed some smaller fixes.

This change fixes all compiler errors in JGit and replaces possible
NPE's with either appropriate exceptions, avoiding multiple "Nullable
return" method calls or early returning from the method.

Because annotating getDirectory() and getFS() as Nullable would cause
lot of additional changes in JGit and EGit they are postponed.

Change-Id: Ie8369d2c9c5fac5ce83b3b1b9bc217d7b55502a3
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-11-25 20:52:19 +01:00
Matthias Sohn d2faec27a7 Raise error if FileNotFoundException is caught for an existing file
File, FileInputStream and friends may throw FileNotFoundException even
if the file is existing e.g. when file permissions don't allow to access
the file content. In most cases this is a severe error we should not
suppress hence rethrow the FileNotFoundException in this case.

This may also fix bug 451508.

Bug: 451508
Change-Id: If4a94217fb5b7cfd4c04d881902f3e86193c7008
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-11-24 15:54:20 -05:00
Jonathan Nieder 15e60b646e Merge "RefDirectory.getRef: Treat fake missing symrefs like real ones" 2015-11-24 15:43:06 -05:00
Christian Halstrick 18af2d4265 Let FS_Win32_Cygwin detect symlink support by creating temporary symlink
The class FS_Win32 was always trying out to create a temporary symlink
in order to find out whether symlinks are supported. FS_Win32_Cygwin was
overwriting this method and always returned true. But when the user
running JGit does not have administrative rights then the creation of
symlinks is forbidden even if he is running on FS_Win32_Cygwin. A lot of
tests failed only on the Windows platform because of this. It was
correctly detected that FS_Win32_Cygwin is the filesystem abstraction to
be used but creation of symlinks always failed because of lacking
privileges of the user running the tests.

This fix teaches FS_Win32_Cygwin to behave like FS_Win32 and to test
whether symlinks can be created in order to find out whether symlinks
are supported.

Change-Id: Ie2394631ffc4c489bd37c3ec142ed44bbfcac726
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-11-21 01:49:49 +01:00
Matthias Sohn a6bcc988e0 Remove no longer needed outdated API warning filter
This fixes a warning saying this filter isn't needed anymore.

Change-Id: If77056378befe86c1773950dbe48a82c833fd532
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-11-20 18:19:35 -05:00
Jonathan Nieder 1e47c7058d RefDirectory.getRef: Treat fake missing symrefs like real ones
getRef() loops over its search path to find a ref:

	Ref ref = null;
	for (String prefix : SEARCH_PATH) {
		ref = readRef(prefix + needle, packed);
		if (ref != null) {
			ref = resolve(ref, 0, null, null, packed);
			break;
		}
	}
	fireRefsChanged();
	return ref;

If readRef returns null (indicating that the ref does not exist), the
loop continues so we can find the ref later in the search path.  And
resolve should never return null, so if we return null it should mean
we exhausted the entire search path and didn't find the ref.

... except that resolve can return null: it does so when it has
followed too many symrefs and concluded that there is a symref loop:

	if (MAX_SYMBOLIC_REF_DEPTH <= depth)
		return null; // claim it doesn't exist

Continue the loop instead of returning null immediately.  This makes
the behavior more consistent.

Arguably getRef should throw an exception when a symref loop is
detected.  That would be a more invasive change, so if it's a good
idea it will have to wait for another patch.

Change-Id: Icb1c7fafd4f1e34c9b43538e27ab5bbc17ad9eef
Signed-off-by: Jonathan Nieder <jrn@google.com>
2015-11-19 14:52:56 -08:00
Christian Halstrick 4b114d3c6b Throw IndexReadException if existing index can't be read
If the index file exists but can't be read for example because of wrong
filesystem permissions we should throw a specific exception. This allows
EGit to handle this error situation.

Bug: 482607
Change-Id: I50bfcb719c45caac3cb5550a8b16307c2ea9def4
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-11-19 23:05:22 +01:00
Matthias Sohn d3e61db455 Fix pre-push hook to not set null remoteName as first argument
According to [1] the pre-push hook expects two parameters which provide
the name and location of the destination remote, if a named remote is
not being used both values should be the same.

We did set the first parameter to null in that case which caused
ProcessBuilder to throw a NullPointerException since its start() method
doesn't accept null arguments.

[1] https://git-scm.com/docs/githooks#_pre_push

Bug: 482393
Change-Id: Idb9b0a48cefac01abfcfdf00f6d173f8fa1d9a7b
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-11-18 09:50:51 +01:00
Christian Halstrick 69cd6f5864 Introduce FS.execute() to execute a command defined by a ProcessBuilder
Change-Id: I2ad2c71ad30b969455bdea89637b8e996b1dad8c
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-11-18 00:28:45 +01:00
Christian Halstrick 6389948a81 Add an attribute accessor to CanonicalTreeParser and use it in Treewalk
When checking out a branch we need to access the attributes stored
in the tree to be checked out. E.g. directly after a clone we checkout
the remote HEAD. In this case index and workingtree are still empty.
So we have to search the tree to be checked out for attributes.

Change-Id: I6d96f5d095ed2e3c259d4b12124e404f5215bd9f
2015-11-18 00:28:45 +01:00
Arthur Daussy 12280c02db Adds the git attributes computation on the treewalk
Adds the getAttributes feature to the tree walk. The computation of
attributes needs to be done by the TreeWalk since it needs both a
WorkingTreeIterator and a DirCacheIterator.

Bug: 342372
CQ: 9120
Change-Id: I5e33257fd8c9895869a128bad3fd1e720409d361
Signed-off-by: Arthur Daussy <arthur.daussy@obeo.fr>
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
2015-11-18 00:28:45 +01:00
Andrey Loskutov 2f6959d9f3 Make jgit annotations accessible to other plugins
Other plugins which want to use JGit nullness annotations in their code
cannot do this if the annotations aren't part of the published API.

Unfortunately it looks like although Eclipse JDT allows to use custom
nullness annotation types per project, it does not understand if those
annotations are used mixed with other nullness annotations in other
projects. E.g. EGit can either configure JGit annotations for NPE
analysis and so "understand" nullness from JGit API but so it loses the
ability to use any other nullness annotations to annotate its own code.

Change-Id: Ieeeb578c2fe35223a7561d668dce8e767dc89ef0
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-11-17 12:50:01 -05:00
Andrey Loskutov 864d3899ad Fixed typo in preferences: NonByDefault -> NonNullByDefault
Change-Id: I6ef5fbdb57e7cba010ad23cb3f6af02891e7fe78
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-11-17 18:23:59 +01:00
Andrey Loskutov f1405a337a Added jgit own NonNull annotation type
The annotation is required for example in Repository case (patch
follows), where almost all non-void return methods return Nullable
except few returning NonNull. I definitely do not favor this style, but
it is a nightmare to clients to guess if the null check is needed or
not.

Change-Id: Ib2a778a246c6d84b7c32565f54df2385b59f6498
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-11-17 18:23:59 +01:00
Christian Halstrick d45ee99546 Merge "Fix MissingObjectException in RenameDetector" 2015-11-17 03:27:55 -05:00
Matthias Sohn 4acff5a59e Handle InternalError during symlink support detection on Windows
When JGit tries to detect symlink support the attempt to create a
symlink may fail with a java.lang.InternalError. This was reported for a
case where the application using JGit runs in Windows XP compatibility
mode using Oracle JDK 1.8. Handle this by assuming symlinks are not
supported in this case.

Bug: 471027
Change-Id: I978288754dea0c6fffd3457fad7d4d971e27c6c2
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-11-15 22:56:55 +01:00
Matthias Sohn 070bf8d15f Merge branch 'stable-4.1'
* stable-4.1:
  Prepare 4.1.2-SNAPSHOT builds
  JGit v4.1.1.201511131810-r
  Fallback exactRef: Do not ignore symrefs to unborn branch
  RefDirectory.exactRef: Do not ignore symrefs to unborn branch

Change-Id: I66afb303f355aad8a7eaa7a6dff06de70ae9c490
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-11-14 00:59:36 +01:00
Matthias Sohn 3e2aff196e Prepare 4.1.2-SNAPSHOT builds
Change-Id: I1d1c4d918f2260c866c4392c1abea1e40a1de962
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-11-14 00:53:45 +01:00
Matthias Sohn 3cb5f11398 JGit v4.1.1.201511131810-r
Change-Id: If0246daab39fa279c30874549b198e7aa917bc62
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-11-14 00:09:54 +01:00
Jonathan Nieder 7dcb50a04a Fallback exactRef: Do not ignore symrefs to unborn branch
When asked to read a symref pointing to a branch-yet-to-be-born (such
as HEAD in a newly initialized repository), getRef and getRefs provide
different results.

	getRef: SymbolicRef[HEAD -> refs/heads/master=00000000]
	getRefs and getAdditionalRefs: nothing

exactRef should match the getRef behavior: it is meant to be a
simpler, faster version of getRef that lets you search for a ref
without resolving it using the search path without other semantic
changes.  But the fallback implementation of exactRef relies on getRefs
and produces null for this case.

Luckily the in-tree RefDatabase implementations override exactRef and
get the correct behavior.  But any out-of-tree storage backend that
doesn't inherit from DfsRefDatabase or RefDirectory would still return
null when it shouldn't.

Let the fallback implementation use getRef instead to avoid this.
This means that exactRef would waste some effort traversing the ref
search path when the named ref is not found --- but subclasses tend to
override exactRef for performance already, so in the default
implementation correctness is more important.

Bug: 478865
Change-Id: I60f04e3ce3bf4731640ffd2433d329e621330029
2015-11-12 14:59:51 -05:00
Rüdiger Herrmann e18444de30 Fix MissingObjectException in RenameDetector
When attempting to determine the size of a blob that does not exist,
the RenameDetector throws a MissingObjectException.

The fix is to return a size of zero if the size is requested for a blob
id that doesn't exist.

Bug: 481577
Change-Id: I4e86276039c630617610cc51d0eefa56d7d3952f
Signed-off-by: Rüdiger Herrmann <ruediger.herrmann@gmx.de>
2015-11-12 15:56:36 +01:00
Jonathan Nieder 797f94d331 RefDirectory.exactRef: Do not ignore symrefs to unborn branch
When asked to read a symref pointing to a branch-yet-to-be-born (such
as HEAD in a newly initialized repository), DfsRepository and
FileRepository return different results.

FileRepository:

	exactRef("HEAD") => null

DfsRepository:

	exactRef("HEAD") => SymbolicRef[HEAD -> refs/heads/master=00000000]

getRef("HEAD") returns the same as DfsRepository's exactRef in both
backends.

The intended behavior is the DfsRepository one: exactRef() is supposed
to be like getRef(), but more exact because it doesn't need to
traverse the search path.

The discrepancy is because DfsRefDatabase implements exactRef()
directly with the intended semantics, while RefDirectory uses a
fallback implementation built on top of getRefs().  getRefs() skips
symrefs to an unborn branch.

Override the fallback implementation with a correct implementation
that is similar to getRef() to avoid this.  A followup change will fix
the fallback.

Change-Id: Ic138a5564a099ebf32248d86b93e2de9ab3c94ee
Reported-by: David Pursehouse <david.pursehouse@sonymobile.com>
Improved-by: Christian Halstrick <christian.halstrick@sap.com>
Bug: 478865
2015-11-11 10:56:39 -08:00
Jonathan Nieder 61efddf761 Merge "Revert "Remove PackWriter.Statistics and other deprecated classes"" 2015-11-10 20:20:45 -05:00
Jonathan Nieder 1fa6f3a750 Revert "Remove PackWriter.Statistics and other deprecated classes"
This reverts commit bbcbcab8d3.
These classes were part of the public API and should not be removed
until JGit 5.0.

Change-Id: Ife4bee69f82151de6ef8ea1a4c6c146d91bbf0d5
2015-11-10 20:14:01 -05:00
Jonathan Nieder 3eb272edac Merge "Remove PackWriter.Statistics and other deprecated classes" 2015-11-10 15:57:29 -05:00
Terry Parker bbcbcab8d3 Remove PackWriter.Statistics and other deprecated classes
These classes make improper use of internal classes in the public API
and were replaced by corresponding classes in the JGit 4.1 release.

Change-Id: I3d474210e49089aa788314b4e08f505f0d26619b
Signed-off-by: Terry Parker <tparker@google.com>
2015-11-09 18:55:18 -08:00
Matthias Sohn a74ff164e4 Silence API errors for new methods added to BitmapBuilder
These API changes were introduced in f523f21e and 73474466.

BitmapBuilder is an interface to be implemented by implementors of this
interface. According to OSGi semantic versioning rules breaking API
changes require update of the minor version only if implementors of the
API have to be adapted and the changes do not affect clients of the API.

Change-Id: If45d204181ea9bc788b6b57693ca17b1847564c7
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-11-10 00:59:40 +01:00
Matthias Sohn b37d77997c Add missing javadoc to bitmap index classes
Change-Id: Ib9fd230c9465a719df53cfcb314d8b5015743928
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-11-10 00:50:55 +01:00
Jonathan Nieder deb853cb69 Merge changes from topic 'nullable'
* changes:
  Update dependencies to use the JGit-internal @Nullable
  Use the JGit-internal @Nullable annotation
  Add a JGit-internal Nullable type
2015-11-09 18:04:22 -05:00
Jonathan Nieder 86af34e150 Make BitmapIndexImpl.CompressedBitmap public
PackWriterBitmapPreparer (which is in another package) is already well
aware of the mapping between EWAHCompressedBitmaps and the
higher-level CompressedBitmap objects of the BitmapIndexImpl API.
Making the CompressedBitmap type public makes the translation more
obvious and wouldn't break any abstractions that aren't already
broken.  So expose it.

This is all under org.eclipse.jgit.internal so there are no API
stability guarantees --- we can change the API if internals change
(for example if some day there are bitmaps spanning multiple packs).

In particular this means the confusing toBitmap helper can be removed.

Change-Id: Ifb2e8804a6d5ee46e82a76d276c4f8507eaa2a4c
2015-11-09 17:40:05 -05:00
Terry Parker ca3ea18371 Update dependencies to use the JGit-internal @Nullable
Update the project-specific Eclipse settings to replace the use of the
org.eclipse.jdt.annotation.Nullable class the new JGit-specific
@Nullable annotation. I verified that Eclipse reports errors when the
return value of a method annotated with
@org.eclipse.jgit.annotations.Nullable is dereferenced without a null
check.

Also remove the Maven and MANIFEST.MF dependencies on
org.eclipse.jdt.annotation.

Eclipse null analysis uses three annotations: @Nullable, @NonNull and
@NonNullByDefault. All three are updated in this patch because it is
invalid to set the Eclipse preferences to empty values. So far only
@Nullable has been introduced in org.eclipse.jgit.annotations.

My personal preference is to follow the advice in Effective Java and
avoid the null-return idiom, and to avoid passing null values in
general. This sets the expectation is that arguments and return types
are assumed non-null unless otherwise documented. If that is the
expectation, then consistent application of @NonNull is redundant and
hurts readability by cluttering the code, obscuring the occasional
@Nullable annotation that really requires attention.

If the JGit community decides there is value in using the @NonNull and
@NonNullByDefault annotations we can add them--this change configures
Eclipse to use them.

Change-Id: I9af1b786d1b44b9b0d9c609480dc842df79bf698
Signed-off-by: Terry Parker <tparker@google.com>
2015-11-09 14:27:52 -08:00
Terry Parker 6ddb8e703b Use the JGit-internal @Nullable annotation
Update existing @Nullable uses to use the JGit-internal version of the
annotation. 

Change-Id: I95234ffad4c3110f9597fbd3a2760f653e22ecf7
Signed-off-by: Terry Parker <tparker@google.com>
2015-11-09 14:27:52 -08:00
Terry Parker 3a3bb2ce29 Add a JGit-internal Nullable type
Commit 847b3d1 enabled annotation-based NPE analysis to JGit.

In so doing, it introduced a new dependency on the org.eclipse.jdt that
is undesirable. Follow Gerrit's lead by adding an internal Nullable type
(see
https://gerrit.googlesource.com/gerrit/+/stable-2.11/gerrit-common/src/main/java/com/google/gerrit/common/Nullable.java).

The javax.annotations.Nullable class uses a retention policy of RUNTIME,
whereas the org.eclipse.jdt.annotation.Nullable class used a policy of
CLASS. Since I'm not aware of tools that make use of the annotation at
runtime I chose the CLASS policy. If in the future there is a benefit to
retaining the annotations in the running binary we can update this
class.

Change-Id: I63dc8f9a6dc46b517cbde211bb5e2f8521a54d04
Signed-off-by: Terry Parker <tparker@google.com>
2015-11-09 14:27:47 -08:00
Jonathan Nieder 683bd09092 Make BitmapIndexImpl.CompressedBitmap, CompressedBitmapBuilder static
A CompressedBitmap represents a pair (EWAH bit vector, PackIndex
assigning bit positions to git objects).  The bit vector is a member
field and the PackIndex is implicit via the 'this' reference to the
outer class.

Make this clearer by making CompressedBitmap a static class and
replacing the 'this' reference by an explicit field.

Likewise for CompressedBitmapBuilder.

Change-Id: Id85659fc4fc3ad82034db3370cce4cdbe0c5492c
Suggested-by: Terry Parker <tparker@google.com>
2015-11-09 13:32:04 -08:00
Jonathan Nieder 087b5051ff Skip redundant 'OR-reuse' step in tip commit bitmap setup
When creating bitmaps during gc, the bitmaps in tipCommitBitmaps are
built in setupTipCommitBitmaps using the following procedure:

 0. create a bitmap ('reuse') that lists all ancestors of commits
    whose existing bitmaps will be reused.  I will call this the
    reused part of history.

 1. initialize a bitmap for each of the pack's "want"s by taking
    a copy of the 'reuse' bitmap and setting the bit corresponding
    to the one wanted commit.

 2. walk through ancestors of wants, excluding the reused part of
    history.  Add parents of visited commits to bitmaps that have
    those commits.

 3. AND-NOT each tipCommitBitmap against the 'reuse' bitmap

 4. Sort the bitmaps and AND-NOT each against the previous so they
    partition the new commits.

The OR against 'reuse' in step 1 and the AND-NOT against 'reuse'
cancel each other out, except when commits from the reused part of
history are added to a bitmap in step 2.  So avoid adding commits from
the reused part of history in step 2 and skip the OR and AND-NOT.

Performance impact (thanks to Terry for measuring):

The initial "selecting bitmaps" phase of garbage collection decreased
from (83 + 81 + 85) / 3 = 83 to (56 + 57 + 56) / 3 = 56.3, meaning
nearly a ~50% speedup of that phase.

Tested-by: Terry Parker <tparker@google.com>
Change-Id: I26ea695809594347575d14a1d8e6721b8608eb9c
2015-11-08 16:23:37 -08:00
Jonathan Nieder 65e04a2a92 Avoid repeated sort of tipCommitBitmaps
Change-Id: I0feb2003f58776d50fab2d31d46ac98ae863bea8
2015-11-07 15:36:55 -08:00
Terry Parker 6d19f5dc8f [style] Shorten line lengths and import order in bitmap code
Change-Id: I420fcd308a97e30b8c74026d74b93ed3ec74bb3f
Signed-off-by: Terry Parker <tparker@google.com>
2015-11-07 10:32:45 -08:00
Jonathan Nieder e87f0cd866 Inline PackWriterBitmapWalker.newRevFilter into callers
Instead of using the newRevFilter helper, call the appropriate
RevFilter constructor directly.  This means one less hop to find
documentation about what the RevFilter will do.

Change-Id: Ida6ff1c0457a47a1bd1e4ed0fd1dd42a616d214f
2015-11-05 14:51:47 -08:00
Jonathan Nieder af4ee73454 Convert remaining callers of BitmapBuilder.add to use .addObject
When setupTipCommitBitmaps is called, writeBitmaps does not have any
bitmaps saved, so these calls to .add always add a single commit and
do not OR in a bitmap.

The objects returned by nextObject after a commit walk is finished
are trees and blobs.  Non-commit objects do not have bitmaps
associated so the call to .add also can only add a single object.

Change-Id: I7b816145251a7fa4f1fffe0d03644257ea7f5440
2015-11-05 14:51:47 -08:00
Jonathan Nieder 4009713946 Merge changes I57b1d7c1,I590ac460
* changes:
  Use .addObject and .or instead of .add in AddToBitmapFilter
  Replace anonymous BitmapRevFilter subclasses with explicit classes
2015-11-05 17:51:15 -05:00
Jonathan Nieder 10fe4a5405 Merge changes Ia95da478,I2773aa94,Ib745645f,I92c65f34,Ibb714002, ...
* changes:
  Remove BitmapRevFilter.getCountOfLoadedCommits
  Make BitmapBuilder.getBitmapIndex public
  Deprecate BitmapBuilder.add and introduce simpler addObject method
  Add @Override annotations to BitmapIndexImpl
  Rely on bitmap RevFilter to filter walk during bitmap selection
  Use 'reused' bitmap to filter walk during bitmap selection
  Rely on bitmap RevFilter to filter tip commit setup walk
  Use 'reused' bitmap to filter tip commit setup walk
  Include ancestors of reused bitmap commits in reuse bitmap again
2015-11-05 17:08:26 -05:00
Jonathan Nieder fd1ee636a2 Use .addObject and .or instead of .add in AddToBitmapFilter
This is the caller that the BitmapBuilder.add method was designed
around.  Moving away from .add makes it more verbose but hopefully
clearer.

Change-Id: I57b1d7c1dc8fb800b242b76c606922b5aa36b9b2
2015-11-05 13:03:22 -08:00
Jonathan Nieder f102abf035 Replace anonymous BitmapRevFilter subclasses with explicit classes
This puts the code for include() in each RevFilter returned by
newRevFilter in one place and should make the code easier to
understand and modify.

Change-Id: I590ac4604b61fc1ffe7aba2ed89f8139847ccac3
2015-11-05 12:42:35 -08:00
Jonathan Nieder 42f0a3d51d Remove BitmapRevFilter.getCountOfLoadedCommits
The count of loaded commits is equal to the number of commits returned
by the walk.  Simplify BitmapRevFilter by counting them in the caller.

Change-Id: Ia95da47831d9e89d6f8068470ec4529aaabfa7dd
2015-11-05 12:40:13 -08:00
Jonathan Nieder 73474466eb Make BitmapBuilder.getBitmapIndex public
Every Bitmap in current JGit code has an associated BitmapIndex.  Make
it public in BitmapBuilder to make retrieving bitmaps to OR in from
that index easier.

Change-Id: I2773aa94d8b67f12194608e6317c0792a5de21e2
2015-11-05 12:39:57 -08:00
Jonathan Nieder f523f21e59 Deprecate BitmapBuilder.add and introduce simpler addObject method
The BitmapIndex.BitmapBuilder.add API is subtle:

	/**
	 * Adds the id and the existing bitmap for the id, if one
	 * exists, to the bitmap.
	 *
	 * @return true if the value was not contained or able to be
	 * loaded.
	 */
	boolean add(AnyObjectId objectId, int type);

Reading the name of the method does not make it obvious what it will
do.  Does it add the named object to the bitmap, or all objects
reachable from it?  It depends on whether the BitmapIndex owns an
existing bitmap for that object.  I did not notice this subtlety when
skimming the javadoc, either.  This resulted in enough confusion to
subtly break the bitmap building code (see change
I30844134bfde0cbabdfaab884c84b9809dd8bdb8 for details).

So discourage use of the add() API by deprecating it.

To replace it, provide a addObject() method that adds a single object.
This way, callers can decide whether to use addObject() or or() based
on the context.

For example,

	if (bitmap.add(c, OBJ_COMMIT)) {
		for (RevCommit p : c.getParents()) {
			rememberToAlsoHandle(p);
		}
	}

can be replaced with

	if (bitmap.contains(c)) {
		// already included
	} else if (index.getBitmap(c) != null) {
		bitmap.or(index.getBitmap(c));
	} else {
		bitmap.addObject(c, OBJ_COMMIT);
		for (RevCommit p : c.getParents()) {
			rememberToAlsoHandle(p);
		}
	}

which is more verbose but makes it clearer that the behavior
depends on the content of index.getBitmaps().

Change-Id: Ib745645f187e1b1483f8587e99501dfcb7b867a5
2015-11-05 12:29:27 -08:00
Jonathan Nieder 424aa22b56 Add @Override annotations to BitmapIndexImpl
This makes it easier to distinguish between implementations of methods
from the interface from helpers internal to org.eclipse.jgit.internal.storage.*.

This was illegal in Java 5 but JGit requires newer Java these days.

Change-Id: I92c65f3407a334acddd32ec9e09ab7d1d39c4dc6
2015-11-05 12:27:52 -08:00
Jonathan Nieder 0e403a18e6 Rely on bitmap RevFilter to filter walk during bitmap selection
This RevWalk filters out reused bitmap commits via the 'reuse' bitmap.
Avoid possible wasted time and complexity by not also redundantly
marking them UNINTERESTING.

Change-Id: Ibb714002ddac599963d148a9aab90645fcc73141
2015-11-05 12:27:44 -08:00
Jonathan Nieder 2a2c2f3373 Use 'reused' bitmap to filter walk during bitmap selection
When building fullBitmap in order to determine which ancestor chain to
add this commit to, we were excluding the ancestors of reusedCommits
using markUninteresting.  This use of markUninteresting is a bit
wasteful because we already have a bitmap indicating exactly which
commits should be excluded (which can save some walking).  Use it.

A separate commit will remove the now-redundant markUninteresting
call.

No behavior change intended (except for performance improvement).

Change-Id: I1112641852d72aa05c9a8bd08a552c70342ccedb
2015-11-05 12:27:28 -08:00
Jonathan Nieder b28091e450 Rely on bitmap RevFilter to filter tip commit setup walk
This RevWalk filters out reused bitmap commits via the 'reuse' bitmap.
Avoid possible wasted time and complexity by not redundantly marking
them UNINTERESTING any more.

Change-Id: If467ccd1d75e17cf9367b2a0399fca3f9d52adf9
2015-11-05 12:27:21 -08:00
Jonathan Nieder 9d4e5216a6 Use 'reused' bitmap to filter tip commit setup walk
When garbage collecting, we decide to reuse some bitmaps in older
history from the previous pack to save time.  The remainder of commit
selection only involves commits not covered by those bitmaps.

Currently we carry that out in two ways:

1. by building a bitmap representing the already-covered commits,
   for easy containment checks and AND-NOT-ing against
2. by marking the reused bitmap commits as uninteresting in the
   RevWalk that finds new commits

The mechanism in (2) is less efficient than (1): rw.next() will walk
back from reused bitmap commits to check whether the commit it is
about to emit is an ancestor of them, when using the bitmap from (1)
would let us perform the same check with a single contains() call.
Add a RevFilter teaching the RevWalk to perform that same check
directly using the bitmap from (1).

The next time the RevWalk is used, a different RevFilter is installed
so this does not break that.

A later commit will drop the markUninteresting calls.

No functional change intended except a possible speedup.

Change-Id: Ic375210fa69330948be488bf9dbbe4cb0d069ae6
2015-11-05 12:25:32 -08:00
Mike Williams c4d73fb7cc Insert duplicate objects to prevent race during garbage collection.
Prior to this change, DfsInserter would not insert an object into a pack
if it already existed in another pack in the repository, even if that
pack was unreachable. Consider this sequence of events:

- Object FOO is pushed to a repository.
- Subsequent ref changes make FOO UNREACHABLE_GARBAGE.
- FOO is subsequently re-inserted using a DfsInserter, but skipped
  due to existing in UNREACHABLE_GARBAGE.
- The repository is repacked; FOO will not be written into a new pack
  because it is not yet reachable from a reference. If the
  UNREACHABLE_GARBAGE packs are deleted, FOO disappears.
- A reference is updated to reference FOO. This reference is now broken
  as FOO was removed when the repacking process deleted the
  UNREACHABLE_GARBAGE pack that stored the only copy of FOO.

The garbage collector can't safely delete the UNREACHABLE_GARBAGE
pack because FOO might be in the middle of being re-inserted/re-packed.

This change writes a duplicate copy of an object if it only exists in
UNREACHABLE_GARBAGE. This "freshens" the object to give it a chance to
survive long enough to be made reachable through a reference.

Change-Id: I20f2062230f3af3bccd6f21d3b7342f1152a5532
Signed-off-by: Mike Williams <miwilliams@google.com>
2015-11-04 22:25:07 -08:00
Jonathan Nieder 63e15c7533 Merge "Delta compression: reuse DeltaTask.getAdjustedWeight()" 2015-11-04 12:56:44 -05:00
Shawn Pearce 212f3c54a0 Merge "[performance] Speed up delta packing" 2015-11-04 12:55:22 -05:00
Jonathan Nieder 99d4040094 Include ancestors of reused bitmap commits in reuse bitmap again
Until 320a4142 (Update bitmap selection throttling to fully span
active branches, 2015-10-20), setupTipCommitBitmaps contained code
along the following lines:

	for (PackBitmapIndexRemapper.Entry entry : bitmapRemapper) {
		if (!reuse(entry))
			continue;
		RevCommit rc = (RevCommit) rw.peel(rw.parseAny(entry));

		reuseCommits.add(new BitmapCommit(rc));
		EWAHCompressedBitmap bitmap =
			remap.ofObjectType(remap.getBitmap(rc), OBJ_COMMIT);
		writeBitmaps.addBitmap(rc, bitmap, 0);
		reuse.add(rc, OBJ_COMMIT);
	}
	writeBitmaps.clearBitmaps();	// Remove temporary bitmaps

This loop OR-ed together bitmaps for commits whose bitmaps would be
reused.  A subtle point is the use of the add() method, which ORs in a
bitmap from the BitmapIndex when it exists and falls back to OR-ing in
a single bit when that bitmap does not exist in the BitmapIndex.

Commit 320a4142 removed the addBitmap step, so the bitmap does not
exist in the BitmapIndex and the fallback behavior is triggered.

Simplify and restore the intended behavior by avoiding use of the
subtle use of the add() method --- use or() directly instead.

Change-Id: I30844134bfde0cbabdfaab884c84b9809dd8bdb8
2015-11-03 17:45:06 -08:00
Jonathan Nieder 2e8b8e83e2 Merge "Decrease indentation in setupTipCommitBitmaps" 2015-11-03 19:41:23 -05:00
Jonathan Nieder 938ffa9503 Merge "[style] Add braces to DeltaTask" 2015-11-03 18:33:28 -05:00
Terry Parker 36c6aecbe8 Delta compression: reuse DeltaTask.getAdjustedWeight()
Change-Id: I07ed5207b175735b4e2c46edf652cc35908dad02
Signed-off-by: Terry Parker <tparker@google.com>
2015-11-03 15:10:02 -08:00
Terry Parker 6a3127b257 [performance] Speed up delta packing
When packing is able to reuse lots of deltas from existing packs, those
objects are marked as "doNotAttemptDelta" and do not contribute to
DeltaTask's computeTopPaths() "totalWeight" calculation.

In the extreme case when all packs are reusable, "totalWeight" will be
zero. DeltaTask.partitionTasks() uses "totalWeight" to determine a
"weightPerThread" size it uses to set up DeltaTasks. When "totalWeight"
is small, partitionTasks() ends up creating a DeltaTask for every
unique path.

For a large repository, the small "weightPerThread" can result in the
creation of >100k tasks (for the MSM 3.10 Linux repository, the count
was ~150k). This makes the "task stealing" mechanism in DeltaTask very
inefficient, because every attempt to steal work does a linear walk
through all tasks, searching for the one with the most work remaining,
which is O(N^2) comparisons. For the MSM 3.10 repository when all
deltas were reusable, PackWriter.parallelDeltaSearch() took
(1615+1633+1458)/3 = 1568 seconds.

The error is that DeltaTask treats the weights of objects marked as
"doNotAttemptDelta" inconsistently. It ignores the weights when
calculating "totalWeight" but uses them when partitioning the tasks.
The fix is to also ignore them when partitioning the tasks.

With this patch applied, PackWriter.parallelDeltaSearch() on the
MSM 3.10 repository when all deltas are reused went from taking
1568 seconds to 62ms (>25k speedup).

This patch also fixes a totalWeight initialization error in
DeltaTask.computeTopPaths().

Change-Id: I2ae37efa83bca42b0e716266ae6aa9d182e76d9c
Signed-off-by: Terry Parker <tparker@google.com>
2015-11-03 15:04:37 -08:00
Terry Parker 6d00e007ff [style] Add braces to DeltaTask
Change-Id: I3306cc77544dec6d9273b2c35b8db0ed43799992
Signed-off-by: Terry Parker <tparker@google.com>
2015-11-03 14:17:53 -08:00
Jonathan Nieder 7c98c86ef7 Decrease indentation in setupTipCommitBitmaps
Avoid leaving the reader in suspense by handling the unusual
(!RevCommit) case first.  As a nice side effect, there is less nesting
to keep track of in the rest of the loop body.

No functional change intended.

Change-Id: I1580de444fccde08070f696218c12041151a924a
2015-11-03 11:42:53 -08:00
Marc Strapetz 82edf06311 BaseRepositoryBuilder should trim CR from .git symref
Change-Id: I909c2892100da89f6670ffbf3442f11c9cb7b008
Signed-off-by: Marc Strapetz <marc.strapetz@syntevo.com>
2015-11-03 12:01:11 +01:00
Christian Halstrick edc4daf2e8 Add support for pre-push hooks
When the file <git-dir>/hooks/pre-push exists make sure that is is
executing during a push. The pre-push hook runs during git push, after
the remote refs have been updated but before any objects have been
transferred.

Change-Id: Ibbb58ee3227742d1a2f913134ce11e7a135c7f4c
2015-11-02 22:19:49 +01:00
Christian Halstrick 67a77d402a Enhance FS.runProcess() to support stdin-redirection and binary data
In order to support filters in gitattributes FS.runProcess() is made
public. Support for stdin redirection has been added. Support for binary
data on stdin/stdout (as used be clean/smudge filters) has been added.

Change-Id: Ice2c152e9391368dc5748d7b825a838e3eb755f9
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-11-02 22:19:47 +01:00
Andrey Loskutov 8473bc4f8d Cleaned up various readPipe() threading issues
Fixed random errors in discoverGitSystemConfig() on Linux where the
process error stream was closed by readPipe() before or while
GobblerThread was reading from it.

Marked readPipe() as @Nullable and fixed potential NPE in
discoverGitSystemConfig() on readPipe() return value.

Fixed process error output randomly mixed with other threads log
messages.

Change-Id: Id882af2762cfb75f010f693b2e1c46eb6968ee82
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-11-01 14:03:52 +01:00
Andrey Loskutov 3601c8cdf1 Don't report errors logged by FS with "debug" level
Change-Id: I6a10116cd2e6b58d2300a9e741afe2eeac719b03
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-10-31 00:06:27 +01:00
Terry Parker 1eee0466ca Building bitmaps: Simplify the logic to sort by chains
Change-Id: I3da98e85107154c159093c138893f54dfa7ef435
Signed-off-by: Terry Parker <tparker@google.com>
2015-10-29 11:25:24 -07:00
Jonathan Nieder f6b9cd38ca Merge "Pack bitmaps: improve readability" 2015-10-29 14:11:42 -04:00
Kaloyan Raev 8a53d7e2fd JGit CLI should check if calling itself when invoking native git exe
Bug: 480782
Change-Id: I0d7f7a648671e7ff678f2b19fe39b85f8835c061
Signed-off-by: Kaloyan Raev <kaloyan.r@zend.com>
2015-10-29 04:35:58 -04:00
Terry Parker c87b77bc31 Pack bitmaps: improve readability
Add comments and rename variables in PackWriterBitmapPreparer to improve
readability.

Change-Id: I49e7a1c35307298f7bc32ebfc46ab08e94290125
Signed-off-by: Terry Parker <tparker@google.com>
2015-10-28 15:17:40 -07:00
Andrey Loskutov 3afdaf0b3d [performance] Remove synthetic access$ methods in dfs, diff and merge
Java compiler must generate synthetic access methods for private methods
and fields of the enclosing class if they are accessed from inner
classes and vice versa.

While invisible in the code, those synthetic access methods exist in the
bytecode and seem to produce some extra execution overhead at runtime
(compared with the direct access to this fields or methods), see
https://git.eclipse.org/r/58948/.

By removing the "private" access modifier from affected methods and
fields we help compiler to avoid generation of synthetic access methods
and hope to improve execution performance.

To validate changes, one can either use javap or use Bytecode Outline
plugin in Eclipse. In both cases one should look for "synthetic
access$<number>" methods at the end of the class and inner class files
in question - there should be none.

NB: don't mix this "synthetic access$" methods up with "public synthetic
bridge" methods generated to allow generic method override return types.

Change-Id: I94fb481b68c84841c1db1a5ebe678b13e13c962b
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-10-28 21:18:23 +01:00
Andrey Loskutov 260e092e79 [performance] Remove synthetic access$ methods in lib, util and dircache
Java compiler must generate synthetic access methods for private methods
and fields of the enclosing class if they are accessed from inner
classes and vice versa.

While invisible in the code, those synthetic access methods exist in the
bytecode and seem to produce some extra execution overhead at runtime
(compared with the direct access to this fields or methods), see
https://git.eclipse.org/r/58948/.

By removing the "private" access modifier from affected methods and
fields we help compiler to avoid generation of synthetic access methods
and hope to improve execution performance.

To validate changes, one can either use javap or use Bytecode Outline
plugin in Eclipse. In both cases one should look for "synthetic
access$<number>" methods at the end of the class and inner class files
in question - there should be none.

NB: don't mix this "synthetic access$" methods up with "public synthetic
bridge" methods generated to allow generic method override return types.

Change-Id: Ie7b65f251ec4452d5a5ed48aa0f272cf49a9aecd
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-10-28 20:52:43 +01:00
Andrey Loskutov df876d2e0f [performance] Remove synthetic access$ methods in transport package
Java compiler must generate synthetic access methods for private methods
and fields of the enclosing class if they are accessed from inner
classes and vice versa.

While invisible in the code, those synthetic access methods exist in the
bytecode and seem to produce some extra execution overhead at runtime
(compared with the direct access to this fields or methods), see
https://git.eclipse.org/r/58948/.

By removing the "private" access modifier from affected methods and
fields we help compiler to avoid generation of synthetic access methods
and hope to improve execution performance.

To validate changes, one can either use javap or use Bytecode Outline
plugin in Eclipse. In both cases one should look for "synthetic
access$<number>" methods at the end of the class and inner class files
in question - there should be none.

NB: don't mix this "synthetic access$" methods up with "public synthetic
bridge" methods generated to allow generic method override return types.

Change-Id: I0ebaeb2bc454cd8051b901addb102c1a6688688b
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-10-28 20:24:12 +01:00
Andrey Loskutov 79a7dd026f [performance] Remove synthetic access$ methods in pack and file packages
Java compiler must generate synthetic access methods for private methods
and fields of the enclosing class if they are accessed from inner
classes and vice versa.

While invisible in the code, those synthetic access methods exist in the
bytecode and seem to produce some extra execution overhead at runtime
(compared with the direct access to this fields or methods), see
https://git.eclipse.org/r/58948/.

By removing the "private" access modifier from affected methods and
fields we help compiler to avoid generation of synthetic access methods
and hope to improve execution performance.

To validate changes, one can either use javap or use Bytecode Outline
plugin in Eclipse. In both cases one should look for "synthetic
access$<number>" methods at the end of the class and inner class files
in question - there should be none.

NB: don't mix this "synthetic access$" methods up with "public synthetic
bridge" methods generated to allow generic method override return types.

Change-Id: If53ec94145bae47b74e2561305afe6098012715c
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-10-28 00:02:41 +01:00
Thomas Wolf d9e9015a00 Add best-effort variant of File.getCanonicalFile()
See https://git.eclipse.org/r/#/c/58405/.

Change-Id: I097c4b1369754f59137eb8848a680c61b06510ad
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2015-10-22 15:39:38 -04:00
Terry Parker 80c7884ea6 Expose bitmap selection parameters via PackConfig
Expose the following bitmap selection parameters via PackConfig:
"bitmapContiguousCommitCount", "bitmapRecentCommitCount",
"bitmapRecentCommitSpan", "bitmapDistantCommitSpan",
"bitmapExcessiveBranchCount", and "bitmapInactiveBranchAge".

The value of bitmapContiguousCommitCount, whereby bitmaps are
created for the most recent N commits in a branch, has never
been verified. If experiments show that they are not valuable,
then we can simplify the implementation so that there is only
a concept of recent and distant commit history (defined by
"bitmapRecentCommitCount"), and the only controls we need are
"bitmapRecentCommitSpan" and "bitmapDistantCommitSpan".

Change-Id: I288bf3f97d6fbfdfcd5dde2699eff433a7307fb9
Signed-off-by: Terry Parker <tparker@google.com>
2015-10-21 22:12:52 -07:00
Terry Parker 320a4142ad Update bitmap selection throttling to fully span active branches.
Replace the “bitmapCommitRange” parameter that was recently introduced
with two new parameters: “bitmapExcessiveBranchCount” and
“bitmapInactiveBranchAgeInDays”. If the count of branches does not
exceed “bitmapExcessiveBranchCount”, then the current algorithm is kept
for all branches.

If the branch count is excessive, then the commit time for the tip
commit for each branch is used to determine if a branch is “inactive”.
"Active" branches get full commit selection using the existing
algorithm. "Inactive" branches get fewer bitmaps near the branch tips.

Introduce a "contiguousCommitCount" parameter that always enforces that
the N most recent commits in a branch are selected for bitmaps. The
previous nextSelectionDistance() algorithm created anywhere from 1-100
contiguous bitmaps at branch tips.

For example, consider a branch with commits numbering 0-300, with 0
being the most recent commit. If the most recent 200 commits are not
merge commits and the 200th commit was the last one selected,
nextSelectionDistance() returned 100, causing commits 200-101 to be
ignored. Then a window of size 100 was evaluated, searching for merge
commits. Since no merge commits are found, the next commit (commit 0)
was selected, for a total of 1 commit in the topmost 100 commits.

If instead the 250th commit was selected, then by the same logic
commit 50 is selected. At that point nextSelectionDistance() switches to
selecting consecutive commits, so commits 0-50 in the topmost 100
commits are selected. The "contiguousCommitCount" parameter provides
more determinism by always selecting a constant number or topmost
commits.

Add an optimization to break out of the inner loop of selectCommits() if
all of the commits for the current branch have already been found.

When reusing bitmaps from an existing pack, remove unnecessary
populating and clearing of the writeBitmaps/PackBitmapIndexBuilder.

Add comments to PackWriterBitmapPreparer, rename methods and variables
for readability.

Add tests for bitmap selection with and without merge commits and with
excessive branch pruning triggered.

Note: I will follow up with an additional change that exposes the new
parameters through PackConfig.

Change-Id: I5ccbb96c8849f331c302d9f7840e05f9650c4608
Signed-off-by: Terry Parker <tparker@google.com>
2015-10-21 14:53:37 -07:00
Marc Strapetz d29b2b6762 Refspec: loosen restrictions on wildcard "*"
Since Git 2.6 wildcard restrictions for refspecs have been loosened:
refspecs like "refs/heads/*foo:refs/heads/foo*" are valid now.

See Git commit 8d3981ccbed9fc211b4e67105015179d9d2a5692

Change-Id: Icb78afbd282c425173b3a7bc10eadc4015689bb8
Signed-off-by: Marc Strapetz <marc.strapetz@syntevo.com>
2015-10-21 12:05:03 +02:00
Andrei Pozolotin 504e23b7a5 Adding JGitV1 and JGitV2 Walk Encryption
Building on top of https://git.eclipse.org/r/#/c/56391/

Here we preserve compatibility with JetS3t
and add 2 new native JGit encryption implementations.

For reference, see connection configuration files:
* Version 0: jgit-s3-connection-v-0.properties
* Version 1: jgit-s3-connection-v-1.properties
* Version 2: jgit-s3-connection-v-2.properties

Change-Id: I713290bcacbe92d88e5ef28ce137de73dd1abe2f
Signed-off-by: Andrei Pozolotin <andrei.pozolotin@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-10-18 23:22:56 +02:00
Andrei Pozolotin 81810aff29 Adding AES Walk Encryption support in http://www.jets3t.org/ mode
See previous attempt: https://git.eclipse.org/r/#/c/16674/

Here we preserve as much of JetS3t mode as possible
while allowing to use new Java 8+ PBE algorithms
such as PBEWithHmacSHA512AndAES_256

Summary of changes:
* change pom.xml to control long tests
* add WalkEncryptionTest.launch to run long tests
* add AmazonS3.Keys to to normalize use of constants
* change WalkEncryption to support AES in JetS3t mode
* add WalkEncryptionTest to test remote encryption pipeline
* add support for CI configuration for live Amazon S3 testing
* add log4j based logging for tests in both Eclipse and Maven build

To test locally, check out the review branch, then:
* create amazon test configuration file
* located your home dir: ${user.home}
* named jgit-s3-config.properties
* file format follows AmazonS3 connection settings file:
	accesskey = your-amazon-access-key
	secretkey = your-amazon-secret-key
	test.bucket = your-bucket-for-testing
* finally:
* run in Eclipse: WalkEncryptionTest.launch
* or
* run in Shell: mvn test --define test=WalkEncryptionTest

Change-Id: I6f455fd9fb4eac261ca73d0bec6a4e7dae9f2e91
Signed-off-by: Andrei Pozolotin <andrei.pozolotin@gmail.com>
2015-10-18 19:14:31 +00:00
Matthias Sohn 50d6fbcdae Merge "Don't call reader.close() 2 times on dispose()" 2015-10-10 19:38:54 -04:00
Shawn Pearce 7673d84624 Merge "Limit the range of commits for which bitmaps are created." 2015-10-10 12:04:25 -04:00
Andrey Loskutov 9bdbbd32ae Don't call reader.close() 2 times on dispose()
Bug: 479406
Change-Id: I6645a8f36ea349a5f04fd14d2c1ef2ecac2bcc37
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-10-10 16:21:41 +03:00
Andrey Loskutov a406ebf401 Delete non empty directories before checkout a path
If the checkout path is currently a non-empty directory (and was a link
or a regular file before), this directory will be removed before
performing checkout, but only if the checkout path is specified.

Bug: 474973
Change-Id: Ifc6c61592d9b54d26c66367163acdebea369145c
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-10-09 09:23:30 -04:00
Terry Parker 2524157d3d Limit the range of commits for which bitmaps are created.
A bitmap index contains bitmaps for a set of commits in a pack file.
Creating a bitmap for every commit is too expensive, so heuristics
select the most "important" commits. The most recent commits are the
most valuable. To clone a repository only those for the branch tips are
needed. When fetching, only commits since the last fetch are needed.

The commit selection heuristics generally work, but for some
repositories the number of selected commits is prohibitively high. One
example is the MSM 3.10 Linux kernel. With over 1 million commits on
2820 branches, the current heuristics resulted in +36k selected commits.
Each uncompressed bitmap for that repository is ~413k, making it
difficult to complete a GC operation in available memory.

The benefit of creating bitmaps over the entire history of a repository
like the MSM 3.10 Linux kernel isn't clear. For that repository, most
history for the last year appears to be in the last 100k commits.
Limiting bitmap commit selection to just those commits reduces the count
of selected commits from ~36k to ~10.5k. Dropping bitmaps for older
commits does not affect object counting times for clones or for fetches
on clients that are reasonably up-to-date.

This patch defines a new "bitmapCommitRange" PackConfig parameter to
limit the commit selection process when building bitmaps. The range
starts with the most recent commit and walks backwards. A range of 10k
considers only the 10000 most recent commits. A range of zero creates
bitmaps only for branch tips. A range of -1 (the default) does not limit
the range--all commits in the pack are used in the commit selection
process.

Change-Id: Ied92c70cfa0778facc670e0f14a0980bed5e3bfb
Signed-off-by: Terry Parker <tparker@google.com>
2015-10-08 15:17:27 -07:00
Stefan Beller cd1b00e3fc Align docstring for RepoCommand.setRecordRemoteBranch with argument
Change-Id: Ia3aa1130795d162e482b4088f190956d70857244
Signed-off-by: Stefan Beller <sbeller@google.com>
2015-10-06 14:02:19 -07:00
Jonathan Nieder c2efb5c964 Merge "RepoCommand: Add setRecordRemoteBranch option to record upstream branch" 2015-10-05 19:24:48 -04:00
Stefan Beller cdd7c23446 RepoCommand: Add setRecordRemoteBranch option to record upstream branch
On a server also running Gerrit that is using RepoCommand to
convert from an XML manifest to a git submodule superproject
periodically, it would be handy to be able to use Gerrit's
submodule subscription feature[1] to update the superproject
automatically between RepoCommand runs as changes are merged
in each subprojects.

This requires setting the 'branch' field for each submodule
so that Gerrit knows what branch to watch.  Add an option to
do that.

Setting the branch field also is useful for plain Git users,
since it allows them to use "git submodule update --remote" to
manually update all submodules between RepoCommand runs.

[1] https://gerrit-review.googlesource.com/Documentation/user-submodules.html

Change-Id: I1a10861bcd0df3b3673fc2d481c8129b2bdac5f9
Signed-off-by: Stefan Beller <sbeller@google.com>
2015-10-05 16:01:11 -07:00
Matthias Sohn 0baf81a191 Merge "[ignore rules] fix for handling unmatched '[' brackets" 2015-10-02 02:12:19 -04:00
Matthias Sohn d652a6bfd7 Merge branch 'stable-4.1'
* stable-4.1:
  pgm: Open RevWalk and TreeWalk in try-with-resource
  ant: Open Repository and Git in try-with-resource
  pgm: Create instances of Git in try-with-resource
  FanoutBucket: Create ObjectInserter.Formatter in try-with-resource
  Fix compiler warnings in DiffFormatter.writeGitLinkText

Change-Id: I448ecc9a1334977d9f304dd61ea20c7a8e692b10
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-10-02 01:34:59 +02:00
David Pursehouse 581698331a FanoutBucket: Create ObjectInserter.Formatter in try-with-resource
To prevent potential resource leak.

Change-Id: Ife09be2822bc476199f10da8d1eb7ccc8da05b79
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
2015-10-01 15:17:18 +09:00
Matthias Sohn 100179a101 Use japicmp instead of clirr to detect API changes
Clirr doesn't support Java 8 hence use japicmp instead.
See https://github.com/siom79/japicmp

Change-Id: If4b30a6d6aa849b4d6b3b0c900558c609822840c
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-10-01 01:41:52 +02:00
Andrey Loskutov 1a2b4e246d [ignore rules] fix for handling unmatched '[' brackets
This patch makes JGit parsing of ignore rules containing unmatched '['
bracket compatible to the Git CLI.

Since '[' starts character group, Git tries to parse the ignore rule as
a shell glob pattern and if the character group is not closed, the glob
pattern is invalid and so the ignore rule never matches anything.

See also http://article.gmane.org/gmane.comp.version-control.git/278699.

Bug: 478490
Change-Id: I734a4d14fcdd721070e3f75d57e33c2c0700d503
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2015-09-30 18:20:05 +02:00
David Pursehouse a489b6e6b8 Fix compiler warnings in DiffFormatter.writeGitLinkText
- Remove declaration of IOException that is no longer thrown

- Add missing //$NON-NLS-1$ to prevent "Non-externalized string literal"
  warning.

These warnings seem to have been introduced by If13f7b406.

Change-Id: I30058eed31b92067a6ab22e787732b08e29f8d63
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
2015-09-30 18:20:34 +09:00
Matthias Sohn 6664bc6f1c Prepare 4.2.0-SNAPSHOT builds
Change-Id: If559d3565b1f84c93a533e1ce18d5293605d1950
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-09-28 14:48:41 +02:00
Matthias Sohn 729f085ac2 Prepare 4.1.1-SNAPSHOT builds
Change-Id: I035f3a8d0f0de86e8b8f00e668be5ce008402e82
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-09-28 13:37:39 +02:00
Matthias Sohn fdfd6e2872 JGit v4.1.0.201509280440-r
Change-Id: I9a536870b9f5c1247c52d6c976a954115982fa1c
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-09-28 10:36:08 +02:00
Matthias Sohn 9e5380e7fb Use java.nio.file consistently in FS
Since 4.0 we require Java 7 so there is no longer a need to override the
following methods in FS_POSIX, FS_Win32, FS_Win32_Cygwin
- lastModified()
- setLastModified()
- length()
- isSymlink()
- exists()
- isDirectory()
- isFile()
- isHidden()
Hence implement these methods in FS and remove overrides in subclasses.

Change-Id: I5dbde6ec806c66c86ac542978918361461021294
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2015-09-27 22:24:06 +02:00