Commit Graph

1678 Commits

Author SHA1 Message Date
Shawn O. Pearce 58ed0cb840 smart HTTP: Return errors inside payload
When the client is clearly making a smart HTTP request to our smart
HTTP server, return any errors like RepositoryNotFoundException or
ServiceNotEnabledException inside of the payload as a Git level ERR
message, rather than an HTTP error code.

This prevents the C Git command line client from retrying a failed
"$URL/info/refs?service=git-upload-pack" request without the smart
service URL, only to fail again with "403 Forbidden" when the dumb
as-is service has been disabled by the server configuration, or is
unavailable because the repository is not on the local filesystem.

Change-Id: I57e8756d5026e885e0ca615979bfcd729703be6c
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2011-04-01 17:40:34 -04: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 af3562f7f7 Allow application filters on smart HTTP operations
Permit applications embedding GitServlet to wrap the
info/refs?service=$name and /$name operations with a
servlet Filter.

To help applications inspect state of the operation,
expose the UploadPack or ReceivePack object into a
request attribute.  This can be useful for logging,
or to implement throttling of requests like Gerrit
Code Review uses to prevent server overload.

Change-Id: Ib8773c14e2b7a650769bd578aad745e6651210cb
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
Anatol Pomozov 74419e1474 Bump jsch to 0.1.44
It fixes 'Corrupted MAC on input' ssh issue.

CQ: 4728
Change-Id: I7de63cb3482488ac938566706edebee8a1cdad3a
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-03-31 09:43:15 -05: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 153283f05a Added Merge command to the CLI
This merge command accepts the merge strategy as option and uses the
resolve strategy as default. It expects exactly one other
revision which is merged with current head.

Change-Id: Ia8c188b93ade4afabe6a9ccf267faf045f359a3a
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
2011-03-29 12:27:45 -05: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 73602c448c Use Ignore to bypass unused test
Change-Id: Ica9e50c0d512865d217f55bf0d100f27878031b9
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
2011-03-28 07:41:45 +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
Shawn Pearce fc5d521e4b Merge "Registering the Checkout command and fixed a typo." 2011-03-27 16:46:39 -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
Sasa Zivkov 13fffa7513 Registering the Checkout command and fixed a typo.
The Checkout command line command was added to JGit but it wasn't
registered in the list of available commands.
Additionally, the 'force' option was named '---force' (triple '-').

Change-Id: I259773932fa9aec3bb29e215740e67c834566f6f
Signed-off-by: Sasa Zivkov <sasa.zivkov@sap.com>
2011-03-24 11:22:17 +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
Philipp Thun dcefc660f1 Refactor test cases
This change moves commonly used methods into the RepositoryTestCase
base class.

Change-Id: I56a46c31ee1661c7ce22eb755ab23da8bc9f5da2
Signed-off-by: Philipp Thun <philipp.thun@sap.com>
2011-03-21 09:40:14 +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
Mathias Kinzler 264d3141a3 Merge "Moved tests for commit -o option to own test class" 2011-03-18 02:58:19 -04:00
Christian Halstrick 26f907a6cb Moved tests for commit -o option to own test class
We test the -o option of the commit command very accurate by
writing tests for each line of a decision table. In order to
still be able to point new jgit users to the CommitAndLogCommandTest
to find out how to use log() and commit() I factored out these 1200
lines of very specific tests into their own class.

Change-Id: Icf7c517f790a8fa79c8afd9b7f4a2805cf79196e
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
2011-03-18 07:54:35 +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