git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[JGIT PATCH 00/13] Add receive-pack server side support

From
Shawn O. Pearce <spearce@spearce.org>
Date
Dec 23, 2008, 00:27 UTC
Message-ID
<1229992043-1053-1-git-send-email-spearce@spearce.org>

This is a simple implementation of the receive-pack part of the send-pack/receive-pack protocol used by push. Most of the logic the server implements can be customized by implementing your own PreReceiveHook implementation.

I'm actually going to use this within Gerrit 2 so users can push into the special ref name "refs/changes/new" and have an anonymous topic branch be created instead.

A basic "jgit daemon" for the git:// protocol is also included. This daemon still has some major limitations over "git daemon":

 - Only "receive-pack" is supported.  We do not have a Java
   version of "upload-pack" so we do not support it here.
 - Virtual hosting is not supported; the "host=" header (if sent
   by the client) is discarded.
 - User escapes ("git://host/~user/foo.git") are not honored.
 - No receive timeouts.  Evil clients can connect and do nothing,
   pinning the server thread indefinitely.  This can cause the
   server to consume resources until it crashes.
 - No connection limits.  Evil clients can DOS the server by just
   opening a ton of connections.
 - "jgit daemon" must be started within a git repository, even if
   it won't publish that repository over the network.  This is due
   to a limitation in the way TextBuiltin initializes itself.

Providing "jgit receive-pack" should be trivial if the last item is fixed, permitting jgit commands to be executed from outside of a Git repository.

JSch does not have an SSH server implementation, so we cannot easily provide an SSH daemon for our new push support. Apache MINA SSHD has a nice daemon under development, and I plan on using it in Gerrit 2. Perhaps someone will eventually contribute an extension library for JGit which provides the binding glue necessary for MINA SSHD to invoke JGit.

JGit's ReceivePack class does not invoke the standard hooks honored by "git receive-pack", because doing so would require executing an external process. There's enough data available in memory that someone could easily contribute a PreReceiveHook and PostRecieveHook implementation that honored these.

The early part of the series has some code cleanups to ensure we are thread-safe, and to reduce the thrasing on the InflaterCache.

Shawn O. Pearce (13):
  Fix invalid "double checked locking" in InflaterCache
  Cleanup stupid release of the cached Inflater in IndexPack
  Cache an Inflater inside a WindowCursor and reuse it as much as
    possible
  Make RefDatabase thread-safe
  Make PackFile thread-safe
  Make Repository thread-safe
  Don't open a PackFile multiple times on scanForPacks
  Expose RepositoryConfig.getBoolean so applications can use it
  Add AnyObjectId.copyTo(StringBuilder)
  Add compare-and-swap semantics to RefUpdate
  Allow null new ObjectId during RefUpdate.delete
  Implement the git-receive-pack process in Java
  Add basic git daemon support to publish receive-pack
 .../services/org.spearce.jgit.pgm.TextBuiltin      |    1 +
 .../src/org/spearce/jgit/pgm/Daemon.java           |  125 +++
 .../src/org/spearce/jgit/lib/AnyObjectId.java      |   17 +-
 .../jgit/lib/DeltaRefPackedObjectLoader.java       |    2 +-
 .../src/org/spearce/jgit/lib/InflaterCache.java    |   31 +-
 .../src/org/spearce/jgit/lib/PackFile.java         |   14 +-
 .../src/org/spearce/jgit/lib/RefDatabase.java      |   29 +-
 .../src/org/spearce/jgit/lib/RefUpdate.java        |   32 +-
 .../src/org/spearce/jgit/lib/Repository.java       |   90 ++-
 .../src/org/spearce/jgit/lib/RepositoryConfig.java |    4 +-
 .../src/org/spearce/jgit/lib/WindowCursor.java     |   33 +-
 .../src/org/spearce/jgit/lib/WindowedFile.java     |   17 +-
 .../src/org/spearce/jgit/revwalk/RevWalk.java      |    4 +-
 .../src/org/spearce/jgit/transport/Daemon.java     |  309 ++++++++
 .../org/spearce/jgit/transport/DaemonClient.java   |  106 +++
 .../org/spearce/jgit/transport/DaemonService.java  |  120 +++
 .../src/org/spearce/jgit/transport/IndexPack.java  |   17 +-
 .../org/spearce/jgit/transport/PacketLineIn.java   |   12 +
 .../spearce/jgit/transport/PostReceiveHook.java    |   77 ++
 .../org/spearce/jgit/transport/PreReceiveHook.java |   94 +++
 .../org/spearce/jgit/transport/ReceiveCommand.java |  223 ++++++
 .../org/spearce/jgit/transport/ReceivePack.java    |  793 ++++++++++++++++++++
 .../spearce/jgit/transport/TransportGitAnon.java   |    3 +-
 23 files changed, 2060 insertions(+), 93 deletions(-)
 create mode 100644 org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Daemon.java
 create mode 100644 org.spearce.jgit/src/org/spearce/jgit/transport/Daemon.java
 create mode 100644 org.spearce.jgit/src/org/spearce/jgit/transport/DaemonClient.java
 create mode 100644 org.spearce.jgit/src/org/spearce/jgit/transport/DaemonService.java
 create mode 100644 org.spearce.jgit/src/org/spearce/jgit/transport/PostReceiveHook.java
 create mode 100644 org.spearce.jgit/src/org/spearce/jgit/transport/PreReceiveHook.java
 create mode 100644 org.spearce.jgit/src/org/spearce/jgit/transport/ReceiveCommand.java
 create mode 100644 org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java
Next: Shawn O. Pearce
Message 1 of 17 in “Add receive-pack server side support”
  1. 00/13 Add receive-pack server side supportShawn O. Pearce, Dec 23, 2008
  2. 01/13 Fix invalid "double checked locking" in InflaterCacheShawn O. Pearce, Dec 23, 2008
  3. 02/13 Cleanup stupid release of the cached Inflater in IndexPackShawn O. Pearce, Dec 23, 2008
  4. 03/13 Cache an Inflater inside a WindowCursor and reuse it as much as possibleShawn O. Pearce, Dec 23, 2008
  5. 04/13 Make RefDatabase thread-safeShawn O. Pearce, Dec 23, 2008
  6. 05/13 Make PackFile thread-safeShawn O. Pearce, Dec 23, 2008
  7. 06/13 Make Repository thread-safeShawn O. Pearce, Dec 23, 2008
  8. 07/13 Don't open a PackFile multiple times on scanForPacksShawn O. Pearce, Dec 23, 2008
  9. 08/13 Expose RepositoryConfig.getBoolean so applications can use itShawn O. Pearce, Dec 23, 2008
  10. 09/13 Add AnyObjectId.copyTo(StringBuilder)Shawn O. Pearce, Dec 23, 2008
  11. 10/13 Add compare-and-swap semantics to RefUpdateShawn O. Pearce, Dec 23, 2008
  12. 11/13 Allow null new ObjectId during RefUpdate.deleteShawn O. Pearce, Dec 23, 2008
  13. 12/13 Implement the git-receive-pack process in JavaShawn O. Pearce, Dec 23, 2008
  14. 13/13 Add basic git daemon support to publish receive-packShawn O. Pearce, Dec 23, 2008
  15. Robin RosenbergJan 3, 2009
  16. Permit a wider range of repository names in jgit daemon requestsShawn O. Pearce, Jan 5, 2009
  17. Robin RosenbergJan 5, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.