From: Robin Rosenberg <robin.rosenberg@dewire.com>
To: git@vger.kernel.org
Cc: "Shawn O. Pearce" <spearce@spearce.org>,
Marek Zawirski <marek.zawirski@gmail.com>,
Robin Rosenberg <robin.rosenberg@dewire.com>
Subject: [PATCH] Take care of errors reported from the server when upload command is started
Date: Sun, 22 Jun 2008 19:46:35 +0200 [thread overview]
Message-ID: <1214156797-29186-1-git-send-email-robin.rosenberg@dewire.com> (raw)
In-Reply-To: <20080622013640.GA18629@spearce.org>
When JSch cannot launch the command our SSH Channel will close immediately
in connect, resulting in a NullPointerException and a closed System.err
silencing an errors.
Using System.err for errors also means we get no feedback when using from
Eclipse.
---
.../spearce/egit/ui/EclipseSshSessionFactory.java | 29 ++++++++++++++++++++
.../jgit/transport/DefaultSshSessionFactory.java | 6 ++++
.../spearce/jgit/transport/SshSessionFactory.java | 10 +++++++
.../spearce/jgit/transport/TransportGitSsh.java | 12 +++++++-
4 files changed, 55 insertions(+), 2 deletions(-)
diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/EclipseSshSessionFactory.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/EclipseSshSessionFactory.java
index 5005494..144d47d 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/EclipseSshSessionFactory.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/EclipseSshSessionFactory.java
@@ -8,6 +8,8 @@
*******************************************************************************/
package org.spearce.egit.ui;
+import java.io.IOException;
+import java.io.OutputStream;
import java.security.AccessController;
import java.security.PrivilegedAction;
@@ -44,4 +46,31 @@ class EclipseSshSessionFactory extends SshSessionFactory {
}
});
}
+
+ @Override
+ public OutputStream getErrorStream() {
+ return new OutputStream() {
+
+ StringBuilder all = new StringBuilder();
+ StringBuilder sb = new StringBuilder();
+
+ public String toString() {
+ return all.toString();
+ }
+
+ @Override
+ public void write(int b) throws IOException {
+ if (b == '\r')
+ return;
+ sb.append((char) b);
+ if (b == '\n') {
+ String s = sb.toString();
+ all.append(s);
+ sb = new StringBuilder();
+ Activator.logError(s, new Throwable());
+ }
+ }
+ };
+ }
+
}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/DefaultSshSessionFactory.java b/org.spearce.jgit/src/org/spearce/jgit/transport/DefaultSshSessionFactory.java
index 8a59904..5924a04 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/DefaultSshSessionFactory.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/DefaultSshSessionFactory.java
@@ -46,6 +46,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.OutputStream;
import java.security.AccessController;
import java.security.PrivilegedAction;
@@ -249,4 +250,9 @@ class DefaultSshSessionFactory extends SshSessionFactory {
return null; // cancel
}
}
+
+ @Override
+ public OutputStream getErrorStream() {
+ return System.err;
+ }
}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/SshSessionFactory.java b/org.spearce.jgit/src/org/spearce/jgit/transport/SshSessionFactory.java
index 7f8136d..4c9eae0 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/SshSessionFactory.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/SshSessionFactory.java
@@ -38,6 +38,8 @@
package org.spearce.jgit.transport;
+import java.io.OutputStream;
+
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
@@ -121,4 +123,12 @@ public abstract class SshSessionFactory {
if (session.isConnected())
session.disconnect();
}
+
+ /**
+ * Find or create an OutputStream for Ssh to use. For a command line client
+ * this is probably System.err.
+ *
+ * @return an OutputStream to receive the SSH error stream.
+ */
+ public abstract OutputStream getErrorStream();
}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/TransportGitSsh.java b/org.spearce.jgit/src/org/spearce/jgit/transport/TransportGitSsh.java
index 8944df7..82723a3 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/TransportGitSsh.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/TransportGitSsh.java
@@ -39,6 +39,7 @@
package org.spearce.jgit.transport;
import java.io.IOException;
+import java.io.OutputStream;
import java.net.ConnectException;
import java.net.UnknownHostException;
@@ -77,6 +78,7 @@ class TransportGitSsh extends PackTransport {
}
final SshSessionFactory sch;
+ OutputStream errStream;
TransportGitSsh(final Repository local, final URIish uri) {
super(local, uri);
@@ -179,7 +181,8 @@ class TransportGitSsh extends PackTransport {
cmd.append(' ');
sqAlways(cmd, path);
channel.setCommand(cmd.toString());
- channel.setErrStream(System.err);
+ errStream = SshSessionFactory.getInstance().getErrorStream();
+ channel.setErrStream(errStream, true);
channel.connect();
return channel;
} catch (JSchException je) {
@@ -198,7 +201,12 @@ class TransportGitSsh extends PackTransport {
try {
session = openSession();
channel = exec(session, getOptionUploadPack());
- init(channel.getInputStream(), channel.getOutputStream());
+
+ if (channel.isConnected())
+ init(channel.getInputStream(), channel.getOutputStream());
+ else
+ throw new TransportException(errStream.toString());
+
} catch (TransportException err) {
close();
throw err;
--
1.5.5.1.178.g1f811
next prev parent reply other threads:[~2008-06-22 19:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-22 1:36 [jgit PATCH] Paper bag fix quoting for SSH transport commands Shawn O. Pearce
2008-06-22 17:46 ` Robin Rosenberg [this message]
2008-06-22 17:46 ` [PATCH] Clone: Handle cancel in clone dialog specially Robin Rosenberg
2008-06-22 17:46 ` [PATCH] Clone: If url is changed was changed, forget the old value Robin Rosenberg
2008-06-22 23:01 ` [PATCH] Take care of errors reported from the server when upload command is started Shawn O. Pearce
2008-06-22 17:54 ` [jgit PATCH] Paper bag fix quoting for SSH transport commands Robin Rosenberg
2008-06-22 22:15 ` Shawn O. Pearce
2008-06-23 2:30 ` Robin Rosenberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1214156797-29186-1-git-send-email-robin.rosenberg@dewire.com \
--to=robin.rosenberg@dewire.com \
--cc=git@vger.kernel.org \
--cc=marek.zawirski@gmail.com \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).