{"thread":{"id":"14269","subject":"[JGIT PATCH 1/1] Use 'git upload-pack' for local transport and not 'git-upload-pack'","startedAt":"2008-07-03T03:58:09Z","lastAt":"2008-07-03T03:58:09Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":1},"messages":[{"id":"82064","messageId":"1215057489-10415-1-git-send-email-spearce@spearce.org","threadId":"14269","inReplyTo":null,"subject":"[JGIT PATCH 1/1] Use 'git upload-pack' for local transport and not 'git-upload-pack'","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-07-03T03:58:09Z","receivedAt":"2008-07-03T03:58:09Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Since Git 1.6.0 and later is heading towards moving the dash form\nof commands out of the user's $PATH and into the libexec directory\nwe may not have 'git-upload-pack' or 'git-receive-pack' in $PATH\nwhen the JRE tries to startup C Git for a local transport.  Instead\nwe should use the git wrapper, as it can select the right libexec\ndirectory and start the correct helper program, or perform the task\ninternally if it is a builtin command.\n\nIn the future we should eliminate this reliance on C Git for any\nsort of local transport operation.  We have direct filesystem IO\navailable to read from the source repository, so there is little\nexecuse for us to be invoking C Git for this special case.  Until\nwe fix it, we should at least try to ensure it works for any user.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../org/spearce/jgit/transport/TransportLocal.java |   25 ++++++++++++++++---\n 1 files changed, 21 insertions(+), 4 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/TransportLocal.java b/org.spearce.jgit/src/org/spearce/jgit/transport/TransportLocal.java\nindex b112267..b41d4af 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/transport/TransportLocal.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/TransportLocal.java\n@@ -59,13 +59,15 @@ import org.spearce.jgit.util.FS;\n  * process.\n  */\n class TransportLocal extends PackTransport {\n+\tprivate static final String PWD = \".\";\n+\n \tstatic boolean canHandle(final URIish uri) {\n \t\tif (uri.getHost() != null || uri.getPort() > 0 || uri.getUser() != null\n \t\t\t\t|| uri.getPass() != null || uri.getPath() == null)\n \t\t\treturn false;\n \n \t\tif (\"file\".equals(uri.getScheme()) || uri.getScheme() == null)\n-\t\t\treturn FS.resolve(new File(\".\"), uri.getPath()).isDirectory();\n+\t\t\treturn FS.resolve(new File(PWD), uri.getPath()).isDirectory();\n \t\treturn false;\n \t}\n \n@@ -74,7 +76,7 @@ class TransportLocal extends PackTransport {\n \tTransportLocal(final Repository local, final URIish uri) {\n \t\tsuper(local, uri);\n \n-\t\tFile d = FS.resolve(new File(\".\"), uri.getPath()).getAbsoluteFile();\n+\t\tFile d = FS.resolve(new File(PWD), uri.getPath()).getAbsoluteFile();\n \t\tif (new File(d, \".git\").isDirectory())\n \t\t\td = new File(d, \".git\");\n \t\tremoteGitDir = d;\n@@ -94,8 +96,23 @@ class TransportLocal extends PackTransport {\n \tprotected Process startProcessWithErrStream(final String cmd)\n \t\t\tthrows TransportException {\n \t\ttry {\n-\t\t\tfinal Process proc = Runtime.getRuntime().exec(\n-\t\t\t\t\tnew String[] { cmd, \".\" }, null, remoteGitDir);\n+\t\t\tfinal String[] args;\n+\t\t\tfinal Process proc;\n+\n+\t\t\tif (cmd.startsWith(\"git-\")) {\n+\t\t\t\targs = new String[] { \"git\", cmd.substring(4), PWD };\n+\t\t\t} else {\n+\t\t\t\tfinal int gitspace = cmd.indexOf(\"git \");\n+\t\t\t\tif (gitspace >= 0) {\n+\t\t\t\t\tfinal String git = cmd.substring(0, gitspace + 3);\n+\t\t\t\t\tfinal String subcmd = cmd.substring(gitspace + 4);\n+\t\t\t\t\targs = new String[] { git, subcmd, PWD };\n+\t\t\t\t} else {\n+\t\t\t\t\targs = new String[] { cmd, PWD };\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tproc = Runtime.getRuntime().exec(args, null, remoteGitDir);\n \t\t\tnew StreamRewritingThread(cmd, proc.getErrorStream()).start();\n \t\t\treturn proc;\n \t\t} catch (IOException err) {\n-- \n1.5.6.74.g8a5e\n"}]}