Commit Graph

1301 Commits

Author SHA1 Message Date
Christian Halstrick 475461d052 Fix usage of FileSnapshot in RefDirectory
RefDirectory was not using FileSnapshot correctly in all places. This
is fixed with this commit. Additionally the constructors for the
different types of refs have been changed to take a FileSnapshot
instead of a modification time.

Change-Id: Ifb6a59e87e8b058a398c38cdfb9d648f0bad4bf8
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
2011-05-31 00:22:40 +02:00
Matthias Sohn 03a6f572b5 Merge "Use the stored password instead of prompting for it all the time" 2011-05-25 12:08:17 -04:00
Shawn O. Pearce b8c508e54d DHT: Add sequence RefData
RefData now uses a sequence number as part of the field, ensuring
that updates always increase the sequence number by one whenever
a reference is modified.

Attaching a sequence number to RefData will help with storing
reference log entries during updates. As the sequence number should
be unique within the reference name space, log entries can be keyed
by the sequence number and remain unique.  Making this work over
reference delete-create cycles will require an additional RefTable
API to return the oldest sequence number previously used in the
reference log to seed the recreated reference.

Change-Id: I11cfff2a96ef962e57f29925a3eef41bdbf9f9bb
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-05-25 09:08:33 -05:00
Chris Aniszczyk aa05559fd6 Merge "Let RefDirectory use FileSnapShot to handle fast updates" 2011-05-25 09:46:49 -04:00
Stefan Lay 05fa1713da Add a DiffFormatter which calculates a patch-id
Adds a class which can be used to calculates a SHA1 of the diff
associated with a patch, similar to git patch-id.

In this version whitespace is not ignored.

Change-Id: I421d15ea905e23df543082786786841cbe3ef10d
Signed-off-by: Stefan Lay <stefan.lay@sap.com>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-05-24 18:08:47 -05:00
Abhishek Bhatnagar 7d380e9c5e Add CleanCommandTest and fix CleanCommand
Bug: 334767
Change-Id: I0a836451ceb668f943b1f353dc65420157810b23
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-05-24 17:32:19 -05:00
Abhishek Bhatnagar 08f0e1ffed Add CleanCommand to JGit API
Bug: 334767
Change-Id: I2650c77bc4af2d8f401bbcce5384b44ff2a64ba2
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-05-24 17:07:10 -05:00
Carsten Pfeiffer 486e22c91f Use the stored password instead of prompting for it all the time
EGit change Iba3b87293c22e5fe7d989fc312184aa7463c4387 is also required
to make this work for EGit.

Change-Id: Iedc80e133e66d72e78ff0980b6e12634f75eca36
Signed-off-by: Carsten Pfeiffer <carsten.pfeiffer@gebit.de>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2011-05-24 00:17:01 +02:00
Christian Halstrick 2302a6d3ce Let RefDirectory use FileSnapShot to handle fast updates
Since this change may affect performance and memory consumption on every
access to a loose ref I explicitly made it a RFC to collect opinions.

Previously RefDirectory.scanRef() was not detecting an update of a
loose ref when the update didn't changed the modification time of
the backing file. RefDirectory cached loose refs and the way to detect
outdated cache entries was to compare lastmodification timestamp on the
file representing the ref. If two updates to the same ref happen faster
than the filesystem-timer granularity (for linux this is 2 seconds)
there is the possiblity that we don't detect the update.

Because of this bug EGit's PushOperationTest only works with 2 second
sleeps inside.

This change let RefDirectory use FileSnapshot to detect such situations.
FileSnapshot helps to remember when a file was last read from disk and
therefore enables to decide when to load a file from disk although
modification time has not changed.

Change-Id: I03b9a137af097ec69c4c5e2eaa512d2bdd7fe080
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-05-23 14:48:10 -05:00
Kevin Sawicki 16e810b2ec Add shortening of note ref names to NoteMap
Change-Id: I224190bbb41c7cbea38388d0148ecc6dc68f3a14
Signed-off-by: Kevin Sawicki <kevin@github.com>
2011-05-23 11:39:33 -07:00
Bernard Leach cf846cfb0b Remove rebase temporary files on checkout failure
A checkout conflict during rebase setup should leave the repository
in SAFE state which means ensuring that the rebase temporary files
need to be removed.

Bug: 346813
Change-Id: If8b758fde73ed5a452a99a195a844825a03bae1a
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-05-23 08:24:30 -05:00
Christoph Brill e170c314fb Add LsRemoteCommand to JGit API
Bug: 343801
Change-Id: Ic651e8e09143e15ed459461b50b2222e13da56c4
Also-by: Chris Aniszczyk <caniszczyk@gmail.com>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-05-19 14:43:23 -05:00
Bernard Leach 5ec4977bb5 Create a MergeResult for deleted/modified files
Change Ia2ab4f8dc95020f2914ff01c2bf3b1bc62a9d45d added merge
support for when OURS or THEIRS was simultaneously deleted
and modified.  That changeset however did not add create an
entry in the conflicts table so clients would see a CONFLICTING
result but getConflicts() would return null.

This change creates a MergeResult for the conflicting file.

Bug: 345684
Change-Id: I52acb81c1729b49c9fb3e7a477c6448d8e55c317
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-05-19 09:22:25 -05:00
Bernard Leach 37fe0988b2 Add reset with paths support to ResetCommand
Bug: 338701
Change-Id: Id7cbce47131b459e632ddc2c9a94628c7d0b75cd
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-05-19 09:04:09 -05:00
Ketan Padegaonkar f953a35e9a Fix NPE in URIish when parsing an empty URI
Change-Id: Id1c42dc9843f62c581b9904b02150de53cf7777c
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-05-19 08:58:17 -05:00
Chris Aniszczyk 557ea857e3 Implement rebase ff for upstream branches with merge commits
Change Ib9898fe0f982fa08e41f1dca9452c43de715fdb6 added support for
the 'cherry-pick' fast forward case where the upstream commit history
does not include any merge commits.  This change adds support for the
case where merge commits exist and the local branch has no changes.

Bug: 344779
Change-Id: If203ce5aa1b4e5d4d7982deb621b710e71f4ee10
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-05-18 11:40:21 -05:00
Piotr Janik 7449b9a297 Fix path filtering in LogCommand
Bug: 346257
Change-Id: Ib897e1b4962162da9670164479a844aeea7dfcd1
Signed-off-by: Piotr Janik <janikpiotrek@gmail.com>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-05-18 10:35:25 -05:00
Robin Rosenberg d781554b79 Merge "Optimize MergeAlgorithm if ours or theirs is empty" 2011-05-17 08:54:18 -04:00
Christian Halstrick 0461ff4f0c Optimize MergeAlgorithm if ours or theirs is empty
Previously when merging two contents with a non-empty base and one of
the contents was empty (size == 0) and the other was modified there
was a potentially expensive calculation until we finally always come
to the same result -> the complete non-deleted content should collide
with the empty content.

This proposal adds an optimization to detect empty input content and
to produce the appropriate result immediatly.

Change-Id: Ie6a837260c19d808f0e99173f570ff96dd22acd3
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
2011-05-17 10:59:17 +02:00
Stefan Lay b13ca9121b Merge "Fix diff bug on inserted line" 2011-05-16 21:15:25 -04:00
Shawn O. Pearce c2b87d59a0 Fix diff bug on inserted line
For the following patch on the linux 2.6.32 tag:
--- a/kernel/sched_fair.c
+++ b/kernel/sched_fair.c
@@ -685,6 +685,7 @@ static void enqueue_sleeper(struct cfs_rq *cfs_rq, struct sc

 static void check_spread(struct cfs_rq *cfs_rq, struct sched_entity *se)
 {
+#if 0
 #ifdef CONFIG_SCHED_DEBUG
        s64 d = se->vruntime - cfs_rq->min_vruntime;

@@ -694,6 +695,7 @@ static void check_spread(struct cfs_rq *cfs_rq, struct
sched
        if (d > 3*sysctl_sched_latency)
                schedstat_inc(cfs_rq, nr_spread_over);
 #endif
+#endif
 }

 static void

JGit produced an incorrect diff, attempting to add a new "}" instead
of the new "#endif" at the end of the hunk. This was caused by a prior
fix for bug 328895 where we wanted to "slide" a diff down in the file
when adding a new method/function and want to show the closing curly
brace as being added after the new method, rather than added onto the
end of the prior function or method just before the insertion point.

Bug: 345956
Change-Id: I32b9e24f1e2980258b1b39dd1807919ab1c5f9b2
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-05-16 11:28:23 -07:00
Piotr Janik 2e43e1e904 Add getConflicting() method in Status API
Bug: 345899
Change-Id: I133b9dd3e9a9c3c749547a884df3ce371929f38e
Signed-off-by: Piotr Janik <janikpiotrek@gmail.com>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-05-16 08:45:19 -05:00
Shawn Pearce 4b4df4ccf8 Merge "Fix diff when first text is the start of the other" 2011-05-15 15:17:52 -04:00
Robin Rosenberg 51a5cc7f1a Fix diff when first text is the start of the other
The problem occurred when the first text ends in the middle
of the last line of the other text and the first text has no
end of line.

Bug: 344975
Change-Id: I1f0dd9f8062f2148a7c1341c9122202e082ad19d
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
2011-05-15 20:34:05 +02:00
Chris Aniszczyk c22eab4948 Add RebaseResult.FAST_FORWARD_RESULT
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-05-13 09:56:09 -05:00
Robin Stocker a31590ff63 RevertCommand: Add "." after reverted commit id
This makes the message look the same as in C Git (the "."):

  This reverts commit <sha1>.

Change-Id: I4c254c122277b127e7b039c0d1c7f7a0d691530d
Signed-off-by: Robin Stocker <robin@nibor.org>
2011-05-13 13:39:54 +02:00
Christian Halstrick 858408f8c3 Merge "Formatter for relative dates" 2011-05-09 09:23:37 -04:00
Matthias Sohn c05c6f3327 Formatter for relative dates
Change-Id: I78b307177c68c578e10101a0ee7b6306880a08f7
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2011-05-09 14:46:38 +02:00
Kevin Sawicki 425d17b72d Remove unused serialVersionUID from non-serializable classes.
Change-Id: I819e2ca88577382b54d38b7a1247e94a5127ef9e
Signed-off-by: Kevin Sawicki <kevin@github.com>
2011-05-08 17:51:45 -07:00
Stefan Lay 05bb92980b Fix getHumanishName broken for windows paths
Since d1718a the method getHumanishName was broken on windows since
the URIish is not normalized anymore. For a path like
"C:\gitRepositories\egit" the whole path was returned instead of
"egit".

Bug: 343519
Change-Id: I95056009072b99d32f288966302d0f8188b47836
Signed-off-by: Stefan Lay <stefan.lay@sap.com>
2011-05-06 10:42:51 +02:00
Bernard Leach 298486a7c3 IndexDiff: conflicting files aren't properly shown
Before this change any files in the conflicting set would
also be listed in the the other IndexDiff Sets which is
confusing.  With this change a conflicting file will not
be included in any of the other sets.

Change-Id: Ife9f2652685220bcfddc1f9820423acdcd5acfdc
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-05-05 13:48:57 -05:00
Robin Rosenberg 5f22d67270 Ignore submodule commits during checkout
Submodules are supposed to be handled by separate operations, so
we should ignore them on checkout, just like C Git does.

This fix does not add submodule support. We just try harder
to ignore them.

Bug: 343566
Change-Id: I2c5ae1024ea7bb57adf27072da6acc9643018eda
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
2011-05-05 10:45:57 -07:00
Shawn Pearce 18b7e9400e Merge "Fix "into" part of merge message for HEAD" 2011-05-05 13:38:40 -04:00
Shawn O. Pearce de8946c0c2 Store Git on any DHT
jgit.storage.dht is a storage provider implementation for JGit that
permits storing the Git repository in a distributed hashtable, NoSQL
system, or other database.  The actual underlying storage system is
undefined, and can be plugged in by implementing 7 small interfaces:

  *  Database
  *  RepositoryIndexTable
  *  RepositoryTable
  *  RefTable
  *  ChunkTable
  *  ObjectIndexTable
  *  WriteBuffer

The storage provider interface tries to assume very little about the
underlying storage system, and requires only three key features:

  *  key -> value lookup (a hashtable is suitable)
  *  atomic updates on single rows
  *  asynchronous operations (Java's ExecutorService is easy to use)

Most NoSQL database products offer all 3 of these features in their
clients, and so does any decent network based cache system like the
open source memcache product.  Relying only on key equality for data
retrevial makes it simple for the storage engine to distribute across
multiple machines.  Traditional SQL systems could also be used with a
JDBC based spi implementation.

Before submitting this change I have implemented six storage systems
for the spi layer:

  * Apache HBase[1]
  * Apache Cassandra[2]
  * Google Bigtable[3]
  * an in-memory implementation for unit testing
  * a JDBC implementation for SQL
  * a generic cache provider that can ride on top of memcache

All six systems came in with an spi layer around 1000 lines of code to
implement the above 7 interfaces.  This is a huge reduction in size
compared to prior attempts to implement a new JGit storage layer.  As
this package shows, a complete JGit storage implementation is more
than 17,000 lines of fairly complex code.

A simple cache is provided in storage.dht.spi.cache.  Implementers can
use CacheDatabase to wrap any other type of Database and perform fast
reads against a network based cache service, such as the open source
memcached[4].  An implementation of CacheService must be provided to
glue this spi onto the network cache.

[1] https://github.com/spearce/jgit_hbase
[2] https://github.com/spearce/jgit_cassandra
[3] http://labs.google.com/papers/bigtable.html
[4] http://memcached.org/

Change-Id: I0aa4072781f5ccc019ca421c036adff2c40c4295
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-05-05 10:21:12 -07:00
Robin Stocker 7546e3b4c5 Fix "into" part of merge message for HEAD
Merging into a non-master branch would result in the following message:

  Merge branch 'a' into HEAD

Now the merge message is correct:

  Merge branch 'a' into b

Change-Id: I488f97190e4c1711c23a7a3cbd64f8b13a87bbac
Signed-off-by: Robin Stocker <robin@nibor.org>
2011-05-05 17:50:44 +02:00
Robin Rosenberg e2413ce2f6 Present reset in the reflog like C Git does nowadays
Confirmed for v1.7.4.1

Change-Id: I4f1c3cd6b2cf543be213f061afb94223062dde51
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
2011-05-04 00:31:32 +02:00
Bernard Leach 98b019f4bd Implemented merge for parallel delete/modification
Duplicates cgit behaviour for merging the case where
OURS is deleted and THEIRS is modified as well as
OURS is modified and THEIRS id deleted.

Change-Id: Ia2ab4f8dc95020f2914ff01c2bf3b1bc62a9d45d
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-05-03 12:11:52 -05:00
Chris Aniszczyk 7a9ebbfa9f Merge "Attempt to make git prefix detection more reliable" 2011-05-03 12:53:49 -04:00
Stefan Lay f2a146d033 Merge "Add path support to checkout command." 2011-05-03 11:39:11 -04:00
Kevin Sawicki ec92f8f59e Add path support to checkout command.
Change-Id: I89e8edfc6dd87d5bf8fd08704df2432720084330
Signed-off-by: Kevin Sawicki <kevin@github.com>
2011-05-03 08:07:15 -07:00
Matthias Sohn f9d7b0d21e Qualify post-0.12 builds
Change-Id: I70fe2671321efb5c3d271121ce00299533d1b388
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2011-05-03 00:19:54 +02:00
Matthias Sohn d085a8954f Merge branch 'stable-0.12'
* stable-0.12:
  JGit 0.12.1
2011-05-03 00:11:47 +02:00
Robin Rosenberg ea5df16404 Attempt to make git prefix detection more reliable
This fix makes sure the readPipe methods drains the stderr
pipe and close the subprocess' stdin stream before reading
the process outputs.

I never managed to repeat the reported problem myself, so this
may help in diagnosing the probelm on other peoples machines.

Bug: 337533
Change-Id: I299555f09768c34d5868327e574326946ee265e1
2011-05-02 22:50:49 +02:00
Matthias Sohn b2b58feba7 JGit 0.12.1
Change-Id: Ia6e58b466fa3ef7ddd61b40f2ad44141fe8786c4
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2011-05-02 18:24:45 +02:00
Shawn O. Pearce d05d351f3b Merge branch 'stable-0.12'
* stable-0.12:
  Implement the no-done capability
2011-04-21 16:33:56 -07:00
Shawn O. Pearce b209671d04 Implement the no-done capability
Smart HTTP clients may request both multi_ack_detailed and no-done in
the same request to prevent the client from needing to send a "done"
line to the server in response to a server's "ACK %s ready".

For smart HTTP, this can save 1 full HTTP RPC in the fetch exchange,
improving overall latency when incrementally updating a client that
has not diverged very far from the remote repository.

Unfortuantely this capability cannot be enabled for the traditional
bi-directional connections.  multi_ack_detailed has the client sending
more "have" lines at the same time that the server is creating the
"ACK %s ready" and writing out the PACK stream, resulting in some race
conditions and/or deadlock, depending on how the pipe buffers are
implemented.  For very small updates, a server might actually be able
to send "ACK %s ready", then the PACK, and disconnect before the
client even finishes sending its first batch of "have" lines.  This
may cause the client to fail with a broken pipe exception.  To avoid
all of these potential problems, "no-done" is restricted only to the
smart HTTP variant of the protocol.

Change-Id: Ie0d0a39320202bc096fec2e97cb58e9efd061b2d
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-04-21 16:14:31 -07:00
Shawn O. Pearce b9691b94a3 Merge branch 'stable-0.12'
* stable-0.12:
  Fix sorting of names in RefDirectory
  Make running static checks configurable in maven build
  Add constants for gerrit change id configuration
2011-04-21 15:41:10 -07:00
Shawn O. Pearce 33e65ec691 Fix sorting of names in RefDirectory
RefDirectory did not correctly follow the contract of RefList.  The
contract says if you use add() method of RefList builder, you MUST
sort() it afterwards, and later every other method assumes that list
is properly sorted (especially the binary search in the find() and
get() methods).  Instead RefDirectory class tried to scan the refs
recursively while sorting every folder in the process before
processing and did not call sort().

For example, when scanning the contents of refs/tags project1 string
is smaller than project1-*, so it will recursively go into the folder
and add these tags first and only then will add project-* ones. This
will result in a broken list (any project1-* string is less than
project1/* one, but they all appear after them in the list), that's
why binary search will fail making loose RefList and the whole local
RefMap completely unusable.

Change-Id: Ibad90017e3b2435b1396b69a22520db4b1b022bb
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-04-21 12:40:26 -07:00
Bernard Leach 1a867d10b9 Added support to IndexDiff to return information on conflicts
Change-Id: I43c13eb72a44f80135c93525fce0c0280b0e64a2
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-04-19 17:11:01 -05:00
Shawn Pearce 502508f028 Merge "Make running static checks configurable in maven build" into stable-0.12 2011-04-18 11:46:47 -04:00
Matthias Sohn df85978aae Make running static checks configurable in maven build
In order to run the static checks run:

mvn -P static-checks clean install

Change-Id: I14077498a04be986ded123ddbfc97da8f9bc3130
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2011-04-18 17:38:58 +02:00
Stefan Lay ce2de7db4c Add constants for gerrit change id configuration
Change-Id: I22fc46dff6cc5dfd975f6e82161d265781778cde
Signed-off-by: Stefan Lay <stefan.lay@sap.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2011-04-14 21:57:22 +02:00
Leonard Broman 09be3948cd Hande latin-1 encoding
Bug: 342259
Change-Id: Ie285b8819b5ea6f9892ebafc4ebbd9c6d091d1fe
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-04-11 11:55:55 -05:00
Chris Aniszczyk e109529d6f Add NotesCommand to the JGit API
Bug: 334765
Change-Id: Ie0fb79671e7a741eb85651f507b8ade930bfcc20
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-04-10 21:25:14 -05:00
Robin Stocker 5dbef3fa51 Add "Conflicts" section to merge message on conflict
The same as with cherry-pick, the commit message of a merge should
include a "Conflicts" section when the merge resulted in conflicts.

Change-Id: I6261dc898262322924af5ca1bef841a654b0df55
Signed-off-by: Robin Stocker <robin@nibor.org>
2011-04-06 22:57:49 +02:00
Robin Stocker 3151657404 Refactor reading and writing heads in Repository
Add private methods which are used for reading and writing MERGE_HEAD
and CHERRY_PICK_HEAD files, as suggested in the comments on change
I947967fdc2f1d55016c95106b104c2afcc9797a1.

Change-Id: If4617a05ee57054b8b1fcba36a06a641340ecc0e
Signed-off-by: Robin Stocker <robin@nibor.org>
2011-04-06 22:40:28 +02:00
Robin Stocker 6e10aa42e9 Add CHERRY_PICK_HEAD for cherry-pick conflicts
Add handling of CHERRY_PICK_HEAD file in .git (similar to MERGE_HEAD),
which is written in case of a conflicting cherry-pick merge.

It is used so that Repository.getRepositoryState can return the new
states CHERRY_PICKING and CHERRY_PICKING_RESOLVED. These states, as well
as CHERRY_PICK_HEAD can be used in EGit to properly show the merge tool.

Also, in case of a conflict, MERGE_MSG is written with the original
commit message and a "Conflicts" section appended. This way, the
cherry-picked message is not lost and can later be re-used in the commit
dialog.

Bug: 339092
Change-Id: I947967fdc2f1d55016c95106b104c2afcc9797a1
Signed-off-by: Robin Stocker <robin@nibor.org>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-04-06 13:28:10 -05:00
Stefan Lay fbf35fea4e Add parameters for timeout and branches to clone
The timeout is also used in the FetchCommand called by the
CloneCommand. 

The possibility to provide a list of branches to fetch initially is a
feature offered by EGit. To implement it here is a prerequisite for
EGit to be able to use the CloneCommand.

Change-Id: I21453de22e9ca61919a7c3386fcc526024742f5f
Signed-off-by: Stefan Lay <stefan.lay@sap.com>
2011-04-06 15:00:22 +02:00
Stefan Lay 792b93bc62 Try to checkout branch after cloning
When no branch was specified in the clone command, HEAD pointed to a
commit after clone. Now the clone command tries to find a branch which
points to the same commit and checks out this branch.

Bug: 339354
Change-Id: Ie3844465329f213dee4a8868dbf434ac3ce23a08
Signed-off-by: Stefan Lay <stefan.lay@sap.com>
2011-04-06 14:58:48 +02:00
Philipp Thun e24005de2d Fix DirCache.isModified()
Change I61a1b45db2d60fdcc0f87373ac6fd75ac4c4a202 fixed a possible NPE
occurring for newly created repositories - but in that case a wrong
value (false = not modified) was returned.

If a current version of the index file exists (liveFile), but there is
no snapshot, this means that there have been modifications (i.e. true
has to be returned).

Change-Id: I698f78112249f9924860fc58eb7eab7afdf87eb7
Signed-off-by: Philipp Thun <philipp.thun@sap.com>
2011-04-04 18:04:21 +02:00
Matthias Sohn efad7327ca [findbugs] Use explicit initialization
Findbugs doesn't like using implicitly initialized field in 
initializer.

Change-Id: Ic1ff9011813cc02950a71df587f31ed9f8415b49
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2011-04-04 02:19:16 +02:00
Matthias Sohn 7aec8247c1 [findbugs] Make mutable static field final
Change-Id: I310bc2093571bf22a58106f09706cc3eb43a2453
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2011-04-03 00:32:37 +02:00
Chris Aniszczyk 7b3a6ef530 Merge "Make DeltaBaseCache per-ObjectReader" 2011-04-02 13:35:54 -04:00
Chris Aniszczyk 2b42869912 Merge "Fix ReceivePack connectivity validation with alternates" 2011-04-02 09:44:26 -04:00
Christian Halstrick 12d7e3af1a Merge "Add open(File) and wrap(Repository) to Git" 2011-04-02 03:38:07 -04:00
Christian Halstrick 82372d36f8 Add open(File) and wrap(Repository) to Git
When a new Git instance for an exisiting git repository should be
created there are two use-cases: either the application has already a
Repository instance in hand or the application knows where the
repository resides in the filesystem. Two methods are added to
explicitly support these use-cases: wrap(Repository db) and open(File
gitDir)

Change-Id: I2970e4aa8d4602cb1298f01e5b76bf0f96c492e5
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
2011-04-02 09:33:45 +02:00
Carsten Pfeiffer 11e2e746c1 Support reading first SHA-1 from large FETCH_HEAD files
When reading refs, avoid reading huge files that were put there
accidentally, but still read the top of e.g. FETCH_HEAD, which
may be longer than our limit. We're only interested in the first line
anyway.

Bug: 340880
Change-Id: I11029b9b443f22019bf80bd3dd942b48b531bc11
Signed-off-by: Carsten Pfieffer <carsten.pfeiffer@gebit.de>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-04-01 20:26:15 -05:00
Shawn Pearce 1e03d52f33 Merge "Let LockFile.unlock use FileUtils.delete()" 2011-04-01 20:46:33 -04:00
Shawn O. Pearce 53fb027284 Make DeltaBaseCache per-ObjectReader
The 'Counting objects' phase of PackWriter requires good hit rates
from the DeltaBaseCache while walking trees, the deltas need to find
their bases in the cache in order to inflate in a reasonable time.

If JGit is running in a multi-threaded server, such as Gerrit Code
Review, each thread needs its own DeltaBaseCache to prevent one thread
from evicting the other thread's relevant bases.  Move the cache to be
per-ObjectReader, lazily allocated when required by a PackFile.

Change-Id: If9d5ed06728e813632ae96dcfb811f4860b276e8
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-04-01 20:42:06 -04:00
Shawn O. Pearce 3609dde4cd Fix ReceivePack connectivity validation with alternates
If a repository has an alternate object database, the alternate has
its references advertised as ".have" lines, which permits the client
to use these as delta base candidates when generating the pack.  If
setCheckReferencedObjectsAreReachable(true) is used, these additional
have lines need to be considered in addition to the advertised refs.

Change-Id: Ie39c6696f9d3ff147ef4405cd5624f6011700ce5
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-04-01 20:23:51 -04:00
Christian Halstrick d8bcc84154 Let LockFile.unlock use FileUtils.delete()
We sometimes face the problem that the file .git/index.lock
can't deleted causing JGit operations to fail. Problem is
that LockFile.unlock() simply deletes the lockfile and ignores the
return value of File.delete(). Instead use
FileUtils.delete() with retry option. This method will retry the
deletion of the file at most 10 times with sleeps inbetween.

Bug: 335959
Change-Id: I9598edea9f2304fe12e6f470301211b503434848
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
2011-04-02 02:20:58 +02:00
Christian Halstrick ffbaf694e2 Enhance RefDatabase with a refresh() method
There should be a way to explictly refresh the refs cached in the
RefDirectory. Since commit c261b28 (use of FileSnapshot) this is
not needed anymore for storage in the filesystem. But for DHT based
storage an explicit refresh may be needed.

Change-Id: I7d30c3496c05e1fb6e9519f3af9f23c6adb93bf9
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
2011-04-02 02:14:01 +02:00
Shawn O. Pearce c261b28f67 RefDirectory: Use FileSnapshot for packed-refs
Instead of tracking the length and modification time by hand, rely
on FileSnapshot to tell RefDirectory when the $GIT_DIR/packed-refs
file has been changed or should be re-read from disk.

Change-Id: I067d268dfdca1d39c72dfa536b34e6a239117cc3
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-04-01 17:49:09 -05:00
Shawn O. Pearce 64b524e3ca UploadPack: Add a PreUploadHook to monitor and control behavior
Embedding applications can use this hook to watch actions within
UploadPack and possibly reject them. This could be useful to prevent
clones of a large repository from this server, or to stop abusive
negotiation rounds that offer thousands of objects in a single batch.

Change-Id: Id96f1885ac4d61f22c80b6418fff54184b7348ba
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-04-01 17:40:33 -04:00
Shawn O. Pearce 8ac65d33ed PackWriter: Fix the way delta chain cycles are prevented
Take a very simple approach to avoiding delta chains during object
reuse: objects are now always selected from the oldest pack that
contains them.  This prevents cycles because a pack must not have
a cycle in the delta chain.  If both objects A and B are chosen
out of the same source pack then there cannot be an A->B->A cycle.

The oldest pack is also the most likely to have the smallest deltas.
Its the biggest pack in the system and probably came from the clone
(or last GC) of this repository, where all objects were previously
considered and packed tightly together.  If an object appears again
(for example due to a revert and a push into this repository) the
newer copy of won't be nearly as small as the older delta version
of it, even if the newer one is also itself a delta.

ObjectDirectory already enumerates objects during selection in this
newest->oldest order, so it already is supplying these assumptions
to PackWriter.  Taking advantage of this can speed up selection by
a tiny amount by avoiding some tests, but can also help to prevent
a cycle needing to be broken on the fly during writing.

The previous cycle breaking logic wasn't fully correct either.
If a different delta base was chosen, the new delta base might not
have been written into the output pack before the current object,
forcing the use of REF_DELTA when OFS_DELTA is always smaller.
This logic has now been reworked to always re-check the delta base
and ensure it gets written before the current object.

If a cycle occurs, it gets broken the same way as before, by
disabling delta reuse and finding an alternative form of the
object, which may require inflating/deflating in whole format.

Change-Id: I9953ab8be54ceb8b588e1280d6f7edd688887747
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-04-01 17:40:33 -04:00
Shawn O. Pearce 36a38adf71 PackWriter: Combine small reuse batches together
If the total number of objects to look for reuse on is under 4096
this is really close to a reasonable batch size for the DHT storage
system to lookup at once.  Combine all of the objects into a single
temporary list, perform reuse, and then prune the main lists if any
duplicate objects were detected from a selected CachedPack.

The intention here is to try and avoid 4 tiny sequential lookups
on the storage system when the time to wait for each of those to
finish is higher than the CPU time required to build (and later
GC) this temporary list.

Change-Id: I528daf9d2f7744dc4a6281750c2d61d8f9da9f3a
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-04-01 17:40:33 -04:00
Shawn O. Pearce 0be24ebf33 PackWriter: Remove dummy list 0
Instead of looping over the objectsLists array, always set slot 0 to
null and explicitly work on the 4 indexes that matter.  This kills
some loops and increases the length of the code slightly, but I've
always really disliked that dummy 0 slot.

Change-Id: I5ad938501c1c61f637ffdaff0d0d88e3962d8942
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-04-01 17:40:33 -04:00
Shawn O. Pearce 9f5bbb5dd4 PackWriter: Speed up pruning of objects from cached packs
During object enumeration for the thin pack, very few objects come
out that are duplicated with the cached pack. Typically these are
only cases where a blob or tree was cherry-picked forward, got a
copy or rename, or was reverted... all relatively infrequent events.

Speed up pruning of the thin pack object list by combining the phase
with the object representation selection. Implementers should already
be offering to reuse the object from the cached pack if it is stored
there, at which point the implementation can perform a very fast type
of containment test using the cached pack's identity rather than yet
another index lookup.  For the local disk case this is probably not a
big improvement, but it does help on the DHT implementation where the
two passes combined into one reduces latency.

Change-Id: I6a07fc75d9075bf6233e967360b6546f9e9a2b33
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-04-01 17:40:33 -04:00
Shawn O. Pearce 00eae14a7f Make PacketLineIn public
PacketLineOut is already public. Make PacketLineIn partially public
in case an application needs to use some of the pkt-line protocol.

Change-Id: I5b383eca980bd9e16a7dbdb5aed040c6586d4f46
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-04-01 17:35:43 -04:00
Shawn Pearce a4c142286e Merge changes I2c8e917a,Ica9e50c0
* changes:
  Do not normalize URIishes
  Use Ignore to bypass unused test
2011-04-01 15:20:37 -04:00
Shawn Pearce bc42a780eb Merge "Fix broken git prefix detection" 2011-04-01 15:05:34 -04:00
Christian Halstrick 6935db4ec2 Let CloneCommand not checkout HEAD on bare repos
If the clone command clones into a bare repository it should not try
to checkout HEAD in the end. For bare repos checkout is not possible.

Change-Id: I359719d421b93c9d2e962e3c0eccc2b59235c3d1
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
2011-03-30 02:53:08 +02:00
Christian Halstrick eac2dc18f1 Allow InitCommand to run on existing git repos
To be more consistent with what native git does we should allow
to run the InitCommand also on existing git repos.

Change-Id: I833637842631b37dce96ed9729b3a6ed24054056
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
2011-03-29 15:10:33 +02:00
Christian Halstrick c8b698abb9 Merge "Do not categorize merge failures as 'abnormal'" 2011-03-29 04:23:56 -04:00
Philipp Thun 475672866a Fix possible NPE in DirCache.isModified()
The snapshot field of a DirCache object for a newly created repository
can be null. This fix prevents a NPE when isModified() is called in
such a situation.

Change-Id: I61a1b45db2d60fdcc0f87373ac6fd75ac4c4a202
Signed-off-by: Philipp Thun <philipp.thun@sap.com>
2011-03-28 17:54:24 +02:00
Philipp Thun 761b9285f0 Do not categorize merge failures as 'abnormal'
This change contains a simple renaming. Instead of using the
expression 'abnormal failure', we just treat this kind of situation
as 'failure'. This is specific enough as conflicts are already handled
separately.

Change-Id: I535acdc7d022543ed0f5ac6151b09a6985f4ef38
Signed-off-by: Philipp Thun <philipp.thun@sap.com>
2011-03-28 16:01:44 +02:00
Robin Rosenberg d1718a34d3 Do not normalize URIishes
We used to normalize URI's since it seems simple. This however causes
inconsistencies to the user and to out tests. Just pass backslashes
through and make sure our parser can handle them.

Bug: 341062
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
Change-Id: I2c8e917a086faabcd8749160c2acc9dd05a42838
2011-03-28 07:41:48 +02:00
Robin Rosenberg 76d25273cc Fix broken git prefix detection
If JGit got a cygwin path it would fail to resolve directories
relative to it.

Also add system property to debug problems with the FS utilities.
Enable debug using -Djgit.fs.debug=1

Furthermore use -Djgit.gitprefix=<path> to set the git prefix
manually.

Change-Id: I5a58ee45c2d2ae5322f87fd6972526169b2918c8
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
2011-03-28 07:41:34 +02:00
Shawn Pearce 23967441fc Merge "Detaching HEAD when checking out the same commit." 2011-03-27 16:55:54 -04:00
Shawn Pearce 6e10c1da00 Merge "Fix: possible IndexOutOfBoundsException in ReflogReader" 2011-03-27 16:48:45 -04:00
Sasa Zivkov 3a86868c08 Detaching HEAD when checking out the same commit.
Detaching HEAD didn't work in some corner checkout cases.  If, for example,
HEAD is symbolic ref to refs/heads/master, refs/heads/master is ref to commit
c0ffee... then:

    checkout c0ffee...

would leave the HEAD unchanged.

The same symptom occurs when checking out a remote tracking branch or a tag
that references the same commit as refs/heads/master.

In the above case, the RefUpdate class didn't have enough information to decide
if the update needed to detach symbolic ref because it dealt only with new/old
objectIDs. Therefore, this fix introduced the RefUpdate.detachingSymbolicRef
flag.

Bug: 315166
Change-Id: I085c98b77ea8f9104a213978ea0d4ac6fd58f49b
Signed-off-by: Sasa Zivkov <sasa.zivkov@sap.com>
2011-03-25 15:02:49 +01:00
Matthias Sohn 5152ed8e2e Prevent NPE during fetch and push via SSH
Bug: 340928
Change-Id: I870b77eeffa70a57891d7253a06ad7d44d808ee4
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2011-03-24 19:01:50 -07:00
Philipp Thun 0b5ad24915 Introduce FAILED result for RebaseCommand
In case an underlying cherry-pick fails due to uncommitted changes, a
RebaseCommand shall fail and roll-back changes.

Change-Id: Ic22eb047fb03ac2c8391f777036b7dbf22a1b061
Signed-off-by: Philipp Thun <philipp.thun@sap.com>
2011-03-24 12:24:23 +01:00
Mathias Kinzler 55b7bd247e Merge "Introduce CherryPickResult" 2011-03-24 03:18:32 -04:00
Christian Halstrick c160293d71 Add status command to GIT api
Allow users of the GIT api to get to know the state of their
workingtree and index by adding a status command. The implementation
is mainly a wrapper around IndexDiff class. Better support for multiple
stages in the index (conflict situations) is still missing. An
appropriate change to IndexDiff and StatusCommand will come in a
subsequent commit.

Bug: 337296
Change-Id: Idb390375a68611853c1c903299ec678c89b081dc
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-03-23 11:08:21 -05:00
Roland Schulz ccd3d83719 Create RemoteSession interface
The RemoteSession interface operates like a simplified version of
java.lang.Runtime with a single exec method (and a disconnect
method). It returns a java.lang.Process, which should begin execution
immediately. Note that this greatly simplifies the interface for
running commands. There is no longer a connect method, and most
implementations will contain the bulk of their code inside
Process.exec, or a constructor called by Process.exec. (See the
revised implementations of JschSession and ExtSession.)
Implementations can now configure their connections properly without
either ignoring the proper use of the interface or trying to adhere
to an overly strict interface with odd rules about what methods are
called first.  For example, Jsch needs to create the output stream
before executing, which it now does in the process constructor. These
changes should make it much easier to add alternate session
implementations in the future.

Also-by: John D Eblen <jdeblen@comcast.net>
Bug: 336749
CQ: 5004
Change-Id: Iece43632086afadf175af6638255041ccaf2bfbb
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-03-23 10:48:08 -05:00
Philipp Thun a21e508a31 Introduce CherryPickResult
In order to distinguish cherry-pick failures caused by conflicts vs.
'abnormal failures' (e.g. due to unstaged changes or a dirty
worktree), a CherryPickResult class is introduced and returned by
CherryPickCommand.call() instead of a RevCommit. This new class is
similar to MergeResult and RebaseResult. The CherryPickResult contains
all necessary information, e.g. paths causing the cherry-pick (a merge
called within, respectively) to fail. This allows callers to better
react on failures.

Change-Id: I5db57b9259e82ed118e4bf4ec94463efe68b8c1f
Signed-off-by: Philipp Thun <philipp.thun@sap.com>
Signed-off-by: Mathias Kinzler <mathias.kinzler@sap.com>
2011-03-23 10:24:14 +01:00
Robin Stocker 770c733687 PullCommand: Use short ref name in merge message
Add a test case for PullCommand for the successful merge case and test
that the short ref name is used.

Change-Id: I16cbbc88595f73e5512f984e67f93f87ee0fe242
Signed-off-by: Robin Stocker <robin@nibor.org>
2011-03-22 19:46:18 +01:00
Marc Strapetz a327770433 Fix: possible IndexOutOfBoundsException in ReflogReader
java.lang.IndexOutOfBoundsException
at java.nio.ByteBuffer.wrap(ByteBuffer.java:352)
at org.eclipse.jgit.util.RawParseUtils.decodeNoFallback(RawParseUtils.java:913)
at org.eclipse.jgit.util.RawParseUtils.decode(RawParseUtils.java:880)
at org.eclipse.jgit.util.RawParseUtils.decode(RawParseUtils.java:839)
at org.eclipse.jgit.storage.file.ReflogReader$Entry.<init>(ReflogReader.java:102)
at org.eclipse.jgit.storage.file.ReflogReader.getReverseEntries(ReflogReader.java:183)
at org.eclipse.jgit.storage.file.ReflogReader.getReverseEntries(ReflogReader.java:162)

Change-Id: I22a18bc7193962e5018c40a75337f9976b585c40
2011-03-22 17:33:45 +01:00
Philipp Thun dcf7bd9a8f Improve MergeResult
Add paths causing abnormal merge failures (e.g. due to unstaged
changes) to the MergeResult returned by MergeCommand. This helps
callers to better handle (e.g. present) merge results.

Change-Id: Idb8cf04c5cecfb6a12cb880e16febfc3b9358564
Signed-off-by: Philipp Thun <philipp.thun@sap.com>
2011-03-21 12:33:58 +01:00
Chris Aniszczyk a62abbe180 Merge "PackWriter: Collect stats by object type" 2011-03-19 12:33:19 -04:00
Chris Aniszczyk 9cde331c2b Merge "BlockList: Micro-optimize appending from another BlockList" 2011-03-19 12:32:19 -04:00
Chris Aniszczyk 817d1a334b Merge "PackFile: Cache the packName string" 2011-03-18 17:28:05 -04:00
Shawn O. Pearce bb1956e647 PackWriter: Collect stats by object type
Frequently enough I'm wondering how much of a pack is commits vs.
trees, and the total line doesn't really tell us this because its
a gross total from the pack. Computing the counts per object type
is simple during packing, as PackWriter already has everything in
memory broken up by object type.  Its virtually free to get these
values and track them.

Change-Id: Id5e6b1902ea909c72f103a0fbca5d8bc316f9ab3
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-18 11:31:12 -07:00
Shawn O. Pearce 62fe7c7313 BlockList: Micro-optimize appending from another BlockList
Simple variant of addAll() that knows how to copy large segments
quickly using System.arraycopy() rather than looping through with
an Iterator object.

Change-Id: Icb50a8f87fe9180ea28b6920f473bb9e70c300f1
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-18 09:11:56 -07:00
Shawn O. Pearce 48fb404a3f PackFile: Cache the packName string
Instead of computing this on every request, compute it once and
hold onto the result. This improves performance for LocalCachedPack
which does a lot of tests against the pack name string.

Change-Id: I3803745e3a5dda7b5f0faf39aae9423e2c777e7f
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-18 09:11:47 -07:00
Philipp Thun bf05108d0b Abort merge when file to be checked out is dirty
In case a file needs to be checked out (from THEIRS) during a merge
operation, it has to be checked if the worktree version of this file
is dirty. If this is true, merge shall fail.

Change-Id: I17c24845584700aad953c3d4f2bea77a0d665ec4
Signed-off-by: Philipp Thun <philipp.thun@sap.com>
2011-03-18 17:04:50 +01:00
Christian Halstrick 28ffed2307 Merge "Refactor ResolveMerger" 2011-03-18 11:34:15 -04:00
Philipp Thun fdb0a34abf Refactor ResolveMerger
1. Perform an explicit check for untracked files.
2. Extract 'dirty checks' into separate methods
3. Clean up comments.
4. Tests: also check contents of files not affected by merge.

Change-Id: Ieb089668834d0a395c9ab192c555538917dfdc47
Signed-off-by: Philipp Thun <philipp.thun@sap.com>
2011-03-18 13:33:36 +01:00
Chris Aniszczyk a443043080 Add path filtering to LogCommand
Bug: 340049
Change-Id: I825b93b3412a3041aca225962fc8463a8f180650
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-03-17 14:47:41 -05:00
Shawn O. Pearce 04f7acb7e7 Assume refs of alternates are reachable during fetch
When fetching from a remote peer, consider all of the refs of any
alternate repository to be reachable locally, in addition to the refs
of the local repository.  This mirrors the push protocol and may avoid
unnecessary object transfer when the local repository is empty, but
its alternate and the remote share a lot of common history.

Junio C Hamano recently proposed a similar change to C Git's fetch
client, in order to work around a performance bug I identified when
fetching between two repositories that actually shared the same
alternate repository on the local system.

Change-Id: Iffb0b70e1223901ce2caac3b87ba7e0d6634d265
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-17 10:54:15 -07:00
Shawn O. Pearce c9a6980a42 UploadPack: Report invalid want lines with ERR
Instead of aborting hard with a server-side exception, report an error
to the client with "ERR %s" in a context where the client is expecting
ACK/NAK.  Older clients will report this text to the user, but newer
ones know how to format this message in a more user-friendly way.

Change-Id: I1879b38988ba66f648c069c10dbfa14c3f34adb2
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-17 10:53:19 -07:00
Shawn O. Pearce b0a29c3fcf Handle "ERR %s" when ACK/NAK is expected
If the remote peer replies with "ERR %s" instead of "ACK %s common" or
"NAK" during ancestor negotiation in the fetch-pack/upload-pack
protocol, treat that as an exception that aborts processing with the
error text as supplied by the remote system.

This matches behavior with "ERR %s" during the advertisements, which
is also a way for the remote to abort processing.

Change-Id: I2fe818e75c7f46156744ef4f703c40173cbc76d0
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-17 10:51:31 -07:00
Shawn O. Pearce 00a5040147 PacketLineIn: Reuse internal lineBuffer for small strings
Most "ACK %s continue", "ACK %s common", "NAK" strings that are read
by the readACK() method and readString() are shorter than the
lineBuffer already available.  Reuse that buffer when reading from
the network stream and converting to a string with RawParseUtils to
avoid unnecessary temporary byte array allocations.

Change-Id: Ibc778d9f7721943a065041d80fc427ea50d90fff
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-17 10:48:05 -07:00
Shawn Pearce 5aab335f45 Merge "Expose if name or email is based on a guess" 2011-03-17 13:45:52 -04:00
Jens Baumgart fd963a9180 CommitCommand: add option to insert a change id
An option to insert a change id into the commit message was added
to CommitCommand.
This change is a prerequisite for removing GitIndex from EGit.

Change-Id: Iff9e26a8aaf21d8224bfd6ce3c98821c077bcd82
Signed-off-by: Jens Baumgart <jens.baumgart@sap.com>
Signed-off-by: Philipp Thun <philipp.thun@sap.com>
Signed-off-by: Mathias Kinzler <mathias.kinzler@sap.com>
2011-03-17 18:15:41 +01:00
Mathias Kinzler 6e2e7280d0 Merge "Remove deprecated Repository.mapTree" 2011-03-17 07:07:15 -04:00
Matthias Sohn 157a996e1d Expose if name or email is based on a guess
This enables applications to differentiate between explicitly set
configuration parameters and best effort attempts to guess these
parameters from the operating system.

Change-Id: I67cc4099238a40c6dca795e64f0155ced6008ef1
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2011-03-16 16:23:14 +01:00
Philipp Thun c0112f97a1 Use parent directory in InitCommand if directory is "."
If no directory is set before executing an InitCommand, the current
directory (".") is used by default. By calling File.getParentFile() we
get the actual directory this points to. Using this directory makes it
easier to read paths.

Change-Id: I6245941395dae920e4f90b8985be6ef3cce570d3
Signed-off-by: Philipp Thun <philipp.thun@sap.com>
2011-03-16 01:36:56 +01:00
Chris Aniszczyk 8aef29c114 Merge "Improve native Git transport when following repository" 2011-03-15 12:03:38 -04:00
Shawn O. Pearce f18e1fd1d1 TransportProtocol: Allow null Repository in canHandle()
This allows callers to determine if a URI is supported, before
worrying about the local repository.

Suggested-by: Dariusz Luksza <dariusz@luksza.org>
Change-Id: Ifc76a4ba841f2e2e7354bd51306b87b3b9d7f6ab
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-03-15 10:11:01 -05:00
Chris Aniszczyk dffc50267e Merge "FS: Allow cloning an FS instance" 2011-03-15 11:09:16 -04:00
Chris Aniszczyk 786707fdfe Merge "FS: Allow userHome to be set and cached" 2011-03-15 11:05:37 -04:00
Chris Aniszczyk aa5f9ecdf2 Merge "FS: Allow gitPrefix to be set and cached" 2011-03-15 11:00:08 -04:00
Chris Aniszczyk e16e976e04 Merge "FS: Overload detect() with no arguments" 2011-03-15 10:57:58 -04:00
Shawn O. Pearce 74a129328e PushCommand: Allow adding any reference string
The simplified form of add(String) makes it easier for applications
to pass down user input and allow PushCommand to convert it to the
internal RefSpec object.

Change-Id: Ibd2e95852db0e52ea4a36032942c4c42a7fb4261
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-15 09:53:23 -05:00
Shawn O. Pearce 506ab8caa5 PushCommand: Add utilities for --all, --tags
The --all flag on the command line implies using refs/heads/* as
a push specification. Add this to the standard command object.

The --tags flag on the command line implies using refs/tags/* as
a push specification. Add this to the standard command object.

Change-Id: Iaef200b17cce77604548dbfb15cf2499b10687b5
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-15 09:49:10 -05:00
Chris Aniszczyk 599a55e447 Merge "PushCommand: Default to pushing HEAD" 2011-03-15 10:01:04 -04:00
Chris Aniszczyk 582fb91f92 Merge "PushCommand: Set force-update in-place" 2011-03-15 10:00:33 -04:00
Chris Aniszczyk 2df51d9427 Merge "Make --git-dir optional for 'jgit init'" 2011-03-15 09:59:24 -04:00
Philipp Thun 8e1b581d39 Make --git-dir optional for 'jgit init'
For compatibility reasons with regards to native git and also to
make the init command easier to use from the command line,
argument --git-dir should not be required.

Additionally the path created in case --git-dir is not supplied now is
canonical and thus easier to read.

Change-Id: Idb7d77e983a78c4b21fbf232fc1e75ef581e5ed1
Signed-off-by: Philipp Thun <philipp.thun@sap.com>
2011-03-15 13:57:15 +01:00
Philipp Thun 79ad15924a Replace 'occured' by 'occurred'
This change fixes a common typo.

Signed-off-by: Philipp Thun <philipp.thun@sap.com>
2011-03-15 13:55:58 +01:00
Shawn O. Pearce 9b917ac169 Improve native Git transport when following repository
If the client is only following the remote repository and has not
created any new non-common commits, the client will wind up sending
a "have %s" line for each tag in the repository.  For some projects
like git.git, this is 339 tags and growing, resulting in more than
16 KiB needing to be POSTed over 12 HTTP requests.

Teach UploadPack (server side) to always execute the okToGiveUp()
logic at least once per negotiation round to determine if the server
can compute a pack right now.  If it can, shove in an "ACK %s ready"
message to tell the client this and try to prevent receiving ancient
tags in future negotiation rounds.

Teach BasePackFetchConnection (client side) to honor a "ACK %s ready"
from the remote and break out of its SEND_HAVE loop once the remote
knows it can create a pack.  This avoids sending the remaining 307
tags of git.git.

These two changes together reduce the number of HTTP RPCs from 13
down to 3 in order to fetch from git.git over smart HTTP.  If either
side is missing the change, the older behavior (and its 13 RPCs)
is used.

Change-Id: I64736318fd0abf9ee5e56bd0b737707adb580b37
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-14 16:57:54 -07:00
Chris Aniszczyk 317d8e2e8d Merge "PackWriter: Rename getObjectsNumber to getObjectCount" 2011-03-14 18:09:40 -04:00
Chris Aniszczyk b4b5178e82 Merge "Always fetch tags during clone" 2011-03-14 17:33:36 -04:00
Jens Baumgart 9830baf48d CommitCommand: set correct Reflog message when amending
Change-Id: I2322d31b09ca63bdcee50e90340e326467dc5021
Signed-off-by: Jens Baumgart <jens.baumgart@sap.com>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-03-14 15:51:31 -05:00
Shawn O. Pearce ae1f7947de FS: Allow cloning an FS instance
This permits an application to create its own copy of FS.DETECTED
before manually setting the userHome or gitPrefix.

Bug: 337101
Change-Id: Ieea33c8d0ebdc801a4656b829d2a4b398559fd45
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-14 09:19:39 -07:00
Shawn O. Pearce a4a00ea8f1 FS: Allow userHome to be set and cached
This permits callers to modify the meaning of userHome, which
may be useful if their application allows the user to select
different user settings locations.

Bug: 337101
Change-Id: I076815edeec1c20dea028f7840be3930337dff77
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-14 09:17:39 -07:00
Shawn O. Pearce 5f82569cab FS: Allow gitPrefix to be set and cached
This permits callers to modify the meaning of gitPrefix, which
may be useful if their application allows the user to select
the location where C Git is installed.

Bug: 337101
Change-Id: I07362a5772da4955e01406bdeb8eaf87416be1d6
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-14 09:07:53 -07:00
Shawn O. Pearce 2f705ad240 FS: Overload detect() with no arguments
This allows callers to perform the logic that constructed the
current FS.DETECTED value.

Change-Id: Id8517d131dcc3f675c60b2d935730872695ed1b0
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-14 09:06:16 -07:00
Shawn O. Pearce 3b91e3fe49 Always fetch tags during clone
C Git always fetches tags during clone, even if the tag doesn't
point to an object that was fetched by the branch specifications.
Match that behavior, as users expect it.

Bug: 326611
Change-Id: I81a82b7359a9649f18a172219da44ed54e77ca2f
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-14 08:53:41 -07:00
Shawn O. Pearce c3c4398b64 PushCommand: Default to pushing HEAD
If no RefSpec was specified, push the branch that is currently
checked out as HEAD.

Change-Id: I6f13ef6346188698a14e000fc590850afbc34b21
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-14 08:02:35 -07:00
Shawn O. Pearce a0ead25a09 PushCommand: Set force-update in-place
Rather than copying the entire list, just replace each element
with the version that has setForceUpdate(true) invoked on it.

Change-Id: I2eaa4466d497cb2408ce61dc62ca26e0c32fe841
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-14 08:02:35 -07:00
Shawn O. Pearce 7a9bf1e2e0 PackWriter: Rename getObjectsNumber to getObjectCount
This better matches with PackFile and CachedPack's methods
that return the same value.

Change-Id: Idb9b7c71d2048dd2344a62c2cde20b4e34529ab7
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-14 08:01:52 -07:00
Shawn O. Pearce 65f9a6e58b Fix dumb transport push
PackWriter incorrectly returned 0 from getObjectsNumber() when the
pack has not been written yet. This caused dumb transports like
amazon-s3:// and sftp:// to abort early and never write out a pack,
under the assumption that the pack had no objects.

Until the pack header is written to the output stream, compute the
current object count each time it is requested. Once the header is
started, use the object count from the stats object.

Change-Id: I041a2368ae0cfe6f649ec28658d41a6355933900
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-14 08:01:51 -07:00
Mathias Kinzler 9b941d0172 Avoid NullPointerException in PlotCommit
Bug: 339289
Change-Id: Idf36f080ae6638c2bdbe11d69a4ad870851622b1
Signed-off-by: Mathias Kinzler <mathias.kinzler@sap.com>
2011-03-14 15:40:22 +01:00
Shawn O. Pearce bd970007be ObjectIdOwnerMap: More lightweight map for ObjectIds
OwnerMap is about 200 ms faster than SubclassMap, more friendly to the
GC, and uses less storage: testing the "Counting objects" part of
PackWriter on 1886362 objects:

  ObjectIdSubclassMap:
    load factor 50%
    table: 4194304 (wasted 2307942)
    ms spent 36998 36009 34795 34703 34941 35070 34284 34511 34638 34256
    ms avg 34800 (last 9 runs)

  ObjectIdOwnerMap:
    load factor 100%
    table: 2097152 (wasted 210790)
    directory: 1024
    ms spent 36842 35112 34922 34703 34580 34782 34165 34662 34314 34140
    ms avg 34597 (last 9 runs)

The major difference with OwnerMap is entries must extend from
ObjectIdOwnerMap.Entry, where the OwnerMap has injected its own
private "next" field into each object. This allows the OwnerMap to use
a singly linked list for chaining collisions within a bucket. By
putting collisions in a linked list, we gain the entire table back for
the SHA-1 bits to index their own "private" slot.

Unfortunately this means that each object can appear in at most ONE
OwnerMap, as there is only one "next" field within the object instance
to thread into the map. For types that are very object map heavy like
RevWalk (entity RevObject) and PackWriter (entity ObjectToPack) this
is sufficient, these entity types are only put into one map by their
container.  By introducing a new map type, we don't break existing
applications that might be trying to use ObjectIdSubclassMap to track
RevCommits they obtained from a RevWalk.

The OwnerMap uses less memory. Each object uses 1 reference more (so
we're up 1,886,362 references), but the table is 1/2 the size (2^20
rather than 2^21). The table itself wastes only 210,790 slots, rather
than 2,307,942. So OwnerMap is wasting 200k fewer references.

OwnerMap is more friendly to the GC, because it hardly ever generates
garbage. As the map reaches its 100% load factor target, it doubles in
size by allocating additional segment arrays of 2048 entries. (So the
first grow allocates 1 segment, second 2 segments, third 4 segments,
etc.)  These segments are hooked into the pre-allocated directory of
1024 spaces. This permits the map to grow to 2 million objects before
the directory itself has to grow. By using segments of 2048 entries,
we are asking the GC to acquire 8,204 bytes in a 32 bit JVM. This is
easier to satisfy then 2,307,942 bytes (for the 512k table that is
just an intermediate step in the SubclassMap). By reusing the
previously allocated segments (they are re-hashed in-place) we don't
release any memory during a table grow.

When the directory grows, it does so by discarding the old one and
using one that is 4x larger (so the directory goes to 4096 entries on
its first grow). A directory of size 4096 can handle up to 8 millon
objects. The second directory grow (16384) goes to 33 million objects.
At that point we're starting to really push the limits of the JVM
heap, but at least its many small arrays. Previously SubclassMap would
need a table of 67108864 entries to handle that object count, which
needs a single contiguous allocation of 256 MiB. That's hard to come
by in a 32 bit JVM. Instead OwnerMap uses 8192 arrays of about 8 KiB
each. This is much easier to fit into a fragmented heap.

Change-Id: Ia4acf5cfbf7e9b71bc7faa0db9060f6a969c0c50
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-13 16:39:30 -07:00
Shawn O. Pearce b4f2913556 Merge "ObjectIdSubclassMap: Micro-optimize wrapping at end of table" 2011-03-13 19:28:01 -04:00
Shawn O. Pearce 565fa6f9b1 Register TransportProtocols using services
Use the Java 6 like services approach to find all supported
TransportProtocols within the CLASSPATH and load them all for use.

This allows users to inject additional protocol implementations simply
by putting their JARs on the application CLASSPATH, provided the
protocol author has written the proper services file.

Change-Id: I7a82d8846e4c4ed012c769f03d4bb2461f1bd148
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-13 16:23:56 -07:00
Shawn O. Pearce 305a8ac45f Make the supported Transports extensible and discoverable
The new TransportProtocol type describes what a particular Transport
implementation wants in order to support a connection.  3rd parties
can now plug into the Transport.open() logic by implementing their
own TransportProtocol and Transport classes, and registering with
Transport.register().

GUI applications can help the user configure a connection by looking
at the supported fields of a particular TransportProtocol type, which
makes the GUI more dynamic and may better support new Transports.

Change-Id: Iafd8e3a6285261412aac6cba8e2c333f8b7b76a5
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-13 16:23:56 -07:00
Shawn O. Pearce 2a137d8dea Merge "Don't auto follow non-annotated tags in fetch" 2011-03-13 19:22:31 -04:00
Philipp Thun a490afedba Add -o option to commit command
This change adds the --only/ -o option to the commit command.

Change-Id: I44352d56877f8204d985cb7a35a2e0faffb7d341
Signed-off-by: Philipp Thun <philipp.thun@sap.com>
2011-03-11 14:25:46 +01:00
Shawn O. Pearce d1e47df0da ObjectIdSubclassMap: Micro-optimize wrapping at end of table
During a review of the class, Josh Bloch pointed out we can use
"i = (i + 1) & mask" to wrap around at the end of the table, instead
of a conditional with a branch.  This is generally faster due to one
less branch that will be mis-predicted by the CPU.

Change-Id: Ic88c00455ebc6adde9708563a6ad4d0377442bba
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-10 10:09:58 -08:00
Shawn O. Pearce 42f0b11153 Merge changes I0d797533,I128522af,I6dd076eb,Ief6f81b9,I83d01e5c
* changes:
  ObjectIdSubclassMap: Avoid field loads in inner loops
  ObjectIdSubclassMap: Manually inline index()
  ObjectIdSubclassMap: Change initial size to 2048
  ObjectIdSubclassMap: Grow before insertions
  ObjectIdSubclassMap: Use & rather than % for hashing
2011-03-10 13:02:59 -05:00
Shawn Pearce 09d2b9f0ed Merge "Cache gitPrefix in FS_Win32" 2011-03-10 13:02:24 -05:00
Matthias Sohn 561aa98041 Fix Bundle-Version of jgit source bundle
Bug: 339033
Change-Id: Idaf965cb684d5ed3f3634b0f3d256c92182d7c58
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2011-03-10 14:25:17 +01:00
Marc Strapetz 6f066dec02 Cache gitPrefix in FS_Win32
readPipe() may consume rather much time, so
gitPrefix should be cached. If the git executable changes,
users should run FS.detect() again to get a new
instance of FS_Win32.
2011-03-10 13:17:57 +01:00
Shawn O. Pearce c11756ca4e ObjectIdSubclassMap: Avoid field loads in inner loops
Ensure the JIT knows the table cannot be changed during the critical
inner loop of get() or insert() by loading the field into a final
local variable.  This shouldn't be necessary, but the instance member
is declared non-final (to resizing) and it is not very obvious to the
JIT that the table cannot be modified by AnyObjectId.equals().

Simplify the JIT's decision making by making it obvious, these
values cannot change during the critical inner loop, allowing
for better register allocation.

Change-Id: I0d797533fc5327366f1207b0937c406f02cdaab3
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-09 16:55:10 -08:00
Shawn O. Pearce df7b192e26 ObjectIdSubclassMap: Manually inline index()
This method is trivial in definition, and is called in only 3
places. Inline the method manually to ensure its really going
to be inlined by the JIT at runtime.

Change-Id: I128522af8167c07d2de6cc210573599038871dda
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-09 16:55:09 -08:00
Shawn O. Pearce 16350bf9e4 ObjectIdSubclassMap: Change initial size to 2048
32 is way to small for the map. Most applications using the map
will need to load more than 16 objects just from the root refs
being read from the Repository.

Default the initial size to 2048. This cuts out 6 expansions in
the early life of the table, reducing garbage and rehashing time.

Change-Id: I6dd076ebc0b284f1755855d383b79535604ac547
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-09 14:34:27 -08:00
Shawn O. Pearce da548dfd2b ObjectIdSubclassMap: Grow before insertions
If the table needs to be grown, do it before the current insertion
rather than after. This is a tiny micro-optimization that allows
the compiler to reuse the result of "++size" to compare against
previously pre-computed size at which the table should rehash itself.

Change-Id: Ief6f81b91c10ed433d67e0182f558ca70d58a2b0
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-09 14:32:43 -08:00
Shawn O. Pearce 47c2a3a98d ObjectIdSubclassMap: Use & rather than % for hashing
Bitwise and is faster than integer modulus operations, and since
the table size is always a power of 2, this is simple to use for
index operation.

Change-Id: I83d01e5c74fd9e910c633a98ea6f90b59092ba29
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-09 14:30:43 -08:00
Shawn O. Pearce ff6ac0aaef ObjectIdSubclassMap: Fix non-standard naming conventions
obj_hash doesn't match our naming conventions, camelCaseNames
are the preferred format.

Change-Id: I72da199daccb60a98d17b6af1e498189bf149515
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-09 14:28:14 -08:00
Jesse Greenwald c68aba2a48 Fixed ordering of Config.getSubsections(...)
A standard HashSet was being used to store the list of subsections as
they were being parsed.  This was changed to use a LinkedHashSet so
that iterating over the set would return values in the same order as
they are listed in the config file.

Change-Id: I4251f95b8fe0ad59b07ff563c9ebb468f996c37d
2011-03-09 10:00:24 -08:00
Matthias Sohn c7e9f013b7 [findbugs] ProgressReportingFilter can be a static inner class
Change-Id: I628b1f25f04c9297655d5ac451ae5a133db53896
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2011-03-09 00:05:36 +01:00
Matthias Sohn a02e8e3d26 [findbugs] Avoid futile attempt to change max pool size
Javadoc for ScheduledThreadPoolExecutor says [1]:
While ScheduledThreadPoolExecutor inherits from ThreadPoolExecutor, a
few of the inherited tuning methods are not useful for it. In
particular, because it acts as a fixed-sized pool using corePoolSize
threads and an unbounded queue, adjustments to maximumPoolSize have no
useful effect. 

[1]
http://download.oracle.com/javase/6/docs/api/java/util/concurrent/ScheduledThreadPoolExecutor.html

Change-Id: I8eccb7d6544aa6e27f5fa064c19dddb2a706523f
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2011-03-08 23:41:47 +01:00
Shawn O. Pearce f67e5602af PackWriter: Reduce GC during enumeration
Instead of resizing an ArrayList until all objects have been added,
append objects into a specialized List type that uses small arrays
of 1024 entries for each 1024 objects added.

For a large repository like linux-2.6, PackWriter will now allocate
1,758 smaller arrays to hold the object list, without creating any
garbage from the intermediate states due to list expansion.

1024 was chosen as the block size (and initial directory size) as this
is a reasonable balance for the PackWriter code.  Each block uses
approximately 4096 bytes in a 32 bit JVM, as does the default top
level block directory.  The top level directory doesn't expand until 1
million items have been added to the list, which for linux-2.6 won't
yet occur as the lists are per-object-type and are thus bounded to
about 1/3 of 1.8 million.

Change-Id: If9e4092eb502394c5d3d044b58cf49952772f6d6
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-07 18:23:39 -08:00
Shawn O. Pearce ef822fe3cd Remove deprecated Repository.mapTree
The mapTree() routines have been deprecated for a long time, and their
sibilings for mapCommit() and mapTag() were already removed from the
main Repository API.

Remove mapTree().  Application callers who only need the tree's name
can use resolve("^{tree}") syntax to resolve to the tree ObjectId, or
fail if the input is not a tree.

Applications that want to read a tree should use DirCache or TreeWalk.

Change-Id: I85726413790fc87721271c482f6636f81baf8b82
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-07 12:36:51 -08:00
Shawn O. Pearce 1f57061684 Remove deprecated TreeVisitor
This type and its associated methods has been deprecated for a while
now.  Time to remove it.  Applications can use a TreeWalk instead to
access the elements of any tree-like object.

Change-Id: I047e552ac77b77e2de086f63cb4fb318da57c208
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-07 12:30:04 -08:00
Shawn O. Pearce 6c3badea7a Remove deprecated TreeIterator
This interface has been deprecated for a while now.
Applications can use a TreeWalk instead.

Change-Id: I751d6e919e4b501c36fc36e5f816b8a8c5379cb9
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-07 12:26:51 -08:00
Shawn O. Pearce 5ecc6e32cd Remove deprecated IndexTreeVisitor
This has been deprecated for some time now.  Applications should
instead use DirCache within a TreeWalk.

Change-Id: I8099d93f07139c33fe09bdeef8d739782397da17
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-07 12:23:15 -08:00
Shawn O. Pearce c88d34b067 Remove deprecated WriteTree
This class has been deprecated for a long time now.
Time to remove it.  Applications can use the newer
DirCache.writeTree() as a replacement.

Change-Id: I91dc9507668d8a3ecadd6acd4f1c8b7bd7760cc3
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-07 12:20:44 -08:00
Shawn O. Pearce d72b932853 Remove deprecated WorkDirCheckout
This class has been deprecated for a long time now.
Time to remove it.  Applications can use the newer
DirCacheCheckout class as a replacement.

Change-Id: Id66d29fcca5a7286b8f8838303d83f40898918d2
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-07 12:18:12 -08:00
Shawn O. Pearce 9013e9e993 Remove deprecated Treeish interface
This interface has been deprecated for a long time now.
Time to remove it.

Change-Id: I29a938657e4637b2a9d0561940b38d70866613f7
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-07 12:12:20 -08:00
Tomasz Zarna cda64073fd Allow to amend a commit with CommitCommand
Bug: 339088
Change-Id: I57dc727688c4bb6968ac076b176661c857c05afa
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-03-07 10:19:20 -06:00
Shawn O. Pearce 4e187d898a PackFile: Fix copy as-is for small objects
When I disabled validation I broke the code that handled copying small
objects whose contents were below 8192 bytes in size but spanned over
the end of one window and into the next window.  These objects did not
ever populate the temporary write buffer, resulting in garbage writing
into the output stream instead of valid object contents.

Change-Id: Ie26a2aaa885d0eee4888a9b12c222040ee4a8562
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-04 18:56:16 -08:00
Shawn Pearce b9df3e6019 Merge "Fix DirCache re-read." 2011-03-04 10:19:06 -05:00
Shawn O. Pearce a78b79cc30 Don't auto follow non-annotated tags in fetch
When fetch TagOpt is AUTO_FOLLOW do not follow refs/tags/ names that
point directly to commits which are on unreleated side branches.

Change-Id: Iea6eee5a05ae7402a7f256fd9c1e3d3b5ccb58dd
Reported-by: Slawomir Ginter <sginter@atlassian.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-04 07:14:50 -08:00
Robin Rosenberg 3947bd25d9 Fix DirCache re-read.
During unit tests and most likely elsewhere, updates come too fast for
a simple timestamp comparison (with one seconds resolution) to work.
I.e. DirCache thinks it hasn't changed. 

Use FileSnapshot instead which has more advanced logic.

Change-Id: Ib850f84398ef7d4b8a8a6f5a0ae6963e37f2b470
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
2011-03-04 16:00:25 +01:00
Shawn O. Pearce b21c82fdb0 resolve(): Fix wrong parsing of branch "foo-gbed2-dev"
When parsing a string such as "foo-gbed2" resolve() was assuming the
suffix was from git describe output.  This lead to JGit trying to find
the completion for the object abbreviation "bed2", rather than using
the current value of the reference.  If there was only one such object
in the repository, JGit might actually use the wrong value here, as
resolve() would return the completion of the abbreviation "bed2"
rather than the current value of the reference "refs/heads/foo-gbed2".

Move the parsing of git describe abbreviations out of the operator
portion of the resolve() method and into the simple portion that is
supposed to handle only object ids or reference names, and only do the
describe parsing after all other approaches have already failed to
provide a resolution.

Add new unit tests to verify the behavior is as expected by users.

Bug: 338839
Change-Id: I52054d7b89628700c730f9a4bd7743b16b9042a9
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-03 16:17:29 -08:00
Shawn O. Pearce 3ee3588b86 RemoteRefUpdate: Accept Ref and ObjectId arguments for source
Applications may already have a Ref or ObjectId on hand that they want
the remote to be updated to.  Instead of converting these into a
String and relying on the parsing rules of resolve(), allow the
application to supply the Ref or ObjectId directly.

Bug: 338839
Change-Id: If5865ac9eb069de1c8f224090b6020fc422f9f12
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-03 15:13:33 -08:00
Shawn O. Pearce a468cb57c2 PackWriter: Validate reused cached packs
If object reuse validation is enabled, the output pack is going to
probably be stored locally.  When reusing an existing cached pack
to save object enumeration costs, ensure the cached pack has not
been corrupted by checking its SHA-1 trailer.  If it has, writing
will abort and the output pack won't be complete.  This prevents
anyone from trying to use the output pack, and catches corruption
before it can be carried any further.

Change-Id: If89d0d4e429d9f4c86f14de6c0020902705153e6
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-02 12:49:00 -08:00
Shawn O. Pearce 1b2062fe37 PackWriter: Avoid CRC-32 validation when feeding IndexPack
There is no need to validate the object contents during
copyObjectAsIs if the result is going to be parsed by unpack-objects
or index-pack.  Both programs will compute the SHA-1 of the object,
and also validate most of the pack structure.  For git daemon
like servers, this work is already done on the client end of the
connection, so the server doesn't need to repeat that work itself.

Disable object validation for the 3 transport cases where we know
the remote side will handle object validation for us (push, bundle
creation, and upload pack).  This improves performance on the server
side by reducing the work that must be done.

Change-Id: Iabb78eec45898e4a17f7aab3fb94c004d8d69af6
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-02 12:23:58 -08:00
Shawn O. Pearce bd6853e90a PackWriter: Position tags after commits
Annotated tags need to be parsed by many viewing tools, but putting
them at the end of the pack hurts because kernel prefetching might
not have loaded them, since they are so far from the commits they
reference.

Position tags right behind the commits, but before the trees.
Typically the annotated tag set for a repository is very small,
so the extra prefetch burden it puts on tools that don't need
annotated tags (but do need commits and trees) is fairly low.

Change-Id: Ibbabdd94e7d563901c0309c79a496ee049cdec50
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-01 10:07:08 -08:00
Shawn O. Pearce 26dffbe04d PackWriter: Refactor object writing loop
This simple refactoring makes it easier to pre-process each of the
object lists before its handed into the actual write routine.

Change-Id: Iea95e5ecbc7374f6bcbb43d1c75285f4f564d09d
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-01 10:07:08 -08:00
Shawn O. Pearce 751c329b35 PackWriter: Don't reuse commit or tag deltas
JGit doesn't generate deltas for commit or tag objects when it packs
a repository from scratch.  This is an explicit design decision that
is (mostly) justified by the fact that these objects do not delta
compress well.

Annotated tags are made once on stable points of the project history,
it is unlikely they will ever appear again with sufficient common
text to justify using a delta over just deflating the raw content.
JGit never tries to delta compress annotated tags and I take the
stance that these are best stored as non-deltas given how frequently
they might be accessed by repository viewers.

Commits only have sufficient common text when they are cherry-picked
to forward-port or back-port a change from one branch to another.
Even in these cases the distance between the commits as returned
by the log traversal has to be small enough that they would both
appear in the delta search window at the same time in order to
delta compress one of the messages against the other.  JGit never
tries to delta compress commits, as it requires a lot of CPU time
but typically does not produce a smaller pack file.

Avoid reusing deltas for either of these types when constructing a
new pack.  To avoid killing performance during serving of network
clients, UploadPack disables this code change by allowing PackWriter
to reuse delta commits.  Repositories that were already repacked by
C Git will not have their delta commits decompressed and recompressed
on the fly during object writing, saving server-side CPU resources.

Change-Id: I749407e7c5c677e05e4d054b40db7656cfa7fca8
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-01 10:07:08 -08:00
Shawn O. Pearce 67b064fc9f PackWriter: Do not delta compress already packed objects
This is a tiny optimization to how delta search works.  Checking for
isReuseAsIs() avoids doing delta compression search on non-delta
objects already stored in packs within the repository.  Such objects
are not likely to be delta compressable, as they were already delta
searched when their containing pack was generated and they were
not delta compressed at that time.  Doing delta compression now is
unlikely to produce a different result, but would waste a lot of CPU.

The isReuseAsIs() flag is checked before isDoNotDelta() because it
is very common to reuse objects in the output pack.  Most objects
get reused, and only a handful have the isDoNotDelta() bit set.
Moving the check earlier allows the loop to more quickly skip
through objects that will never need to be considered.

Change-Id: Ied757363f775058177fc1befb8ace20fe9759bac
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-01 10:07:08 -08:00
Shawn O. Pearce bf1b970de1 Paper bag fix BatchingProgressMonitor alarm queue
The alarm queue threads were started with an empty task body, which
meant the thread started and terminated immediately, leaving the
queue itself with no worker.

Change-Id: I2a9b5fe9c2bdff4a5e0f7ec7ad41a54b41a4ddd6
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-03-01 10:07:08 -08:00
Shawn O. Pearce 68ab451d39 ProgressMonitor: Refactor to use background alarms
Instead of polling the system clock on every update(1) method call,
use a scheduled executor to toggle a volatile once per second until
the task is done.  Check the volatile on each update(int), looking
to see if output should occur.

This limits progress output to either once per 1% complete, or once
per second.  To save time during update calls the timer isn't reset
during each 1% of output, which means we may see one unnecessary
output trigger if at least 1% completed during the one second of the
alarm time.

Change-Id: I8fdd7e31c37bef39a5d1b3da7105da0ef879eb84
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-02-28 19:36:56 -08:00
Matthias Sohn 2fba1e65e1 Fix NPE on checkout of remote tracking branch
Checkout of remote tracking branch failed when no local branch
existed. Also enhance RepositoryTestCase to enable checking index
state of another test repository.

Bug: 337695
Change-Id: Idf4c05bdf23b5161688818342b2bf9a45b49f479
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2011-03-01 00:21:14 +01:00
Shawn O. Pearce 03f78fc3bc UnpackedObject: Fix readSome() when initial read is short
JDK7 changed behavior slightly on some InputStream types, resulting in
the first read being shorter than the count requested.  That caused us
to overwrite the earlier part of the buffer with later data, as the
offset index wasn't updated in the loop.

Fix the loop to increment offset by the number of bytes read in this
iteration, so the next read appends to the buffer rather than doing an
overwrite.

Bug: 338119
Change-Id: I222fb2f993cd9b637b6b8d93daab5777ef7ec7a6
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-02-25 17:20:14 -08:00
Chris Aniszczyk 7e1f18c079 Merge "RevWalk: Don't release during inMergeBase()" 2011-02-24 11:23:47 -05:00
Shawn Pearce 2c9a192505 Merge "Fix formatting of pom.xml" 2011-02-24 10:29:47 -05:00
Matthias Sohn e0a8398f1f FetchCommand: do not set a null credentials provider
FetchCommand now does not set a null credentials provider on
Transport because in this case the default provider is replaced with
null and the default mechanism for providing credentials is not
working.

Change-Id: I44096aa856f031545df39d4b09af198caa2c21f6
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2011-02-24 16:05:05 +01:00
Matthias Sohn 8d000bd578 Fix formatting of pom.xml
Change-Id: I508def09cb2d4e5bd27b412f4ad5d43984388749
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2011-02-24 16:04:33 +01:00
Shawn O. Pearce e757975fcd RevWalk: Don't release during inMergeBase()
In bc1af8459e ("RevWalk: Don't reset ObjectReader when stopping") we
stopped releasing the reader when the current log traversal is over.
This should have also been applied to the merge base logic that is
buried within MergeGenerator, but got missed.

Change-Id: I8328f43f02cba06fd545e22134872e781b9d4d36
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-02-24 06:55:25 -08:00
Shawn Pearce 2902c7679b Merge "Respect core.excludesfile to enable global ignore rules " 2011-02-23 18:08:50 -05:00
Matthias Sohn e703b6c640 Respect core.excludesfile to enable global ignore rules
Also use FS.resolve() to properly resolve files from path strings.

Bug: 328428 (partial fix)
Change-Id: I41d94694f220dcb85605c9acadfffb1fa23beaeb
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2011-02-23 23:44:50 +01:00
Shawn O. Pearce 7505b93546 PackWriter: Add missing timers to Statistics
We did not record the time spent on the object reuse search or the
object size lookup, both of which occur between the counting phase and
the compressing phase.  If there are enough objects involved, these
times can be significant so its worth timing them and recording it.

Change-Id: I89084acfc598bb6533d75d90cb8de459f0ed93be
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-02-23 11:56:19 -08:00
Sasa Zivkov 5f3d577e5a Show notes in Log CLI command
Support for --no-standard-notes and --show-notes=REF options is added
to the Log command. The --show-notes option can be specified more than
once if more than one notes branch should be used for showing notes.

The notes are displayed from note branches in the order how the note
branches are specified in the command line. However, the standard note,
from the refs/notes/commits, is always displayed as first unless
the --no-standard-notes options is given.

Change-Id: I4e7940804ed9d388b625b8e8a8e25bfcf5ee15a6
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-02-23 09:32:23 -06:00