Mercurial > jhg
diff src/org/tmatesoft/hg/repo/HgRemoteRepository.java @ 697:24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 06 Aug 2013 13:34:34 +0200 |
parents | 9859fcea475d |
children | 822f3a83ff57 |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/repo/HgRemoteRepository.java Mon Aug 05 19:03:22 2013 +0200 +++ b/src/org/tmatesoft/hg/repo/HgRemoteRepository.java Tue Aug 06 13:34:34 2013 +0200 @@ -23,7 +23,6 @@ import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -44,7 +43,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.zip.InflaterInputStream; import org.tmatesoft.hg.core.HgBadArgumentException; import org.tmatesoft.hg.core.HgIOException; @@ -61,6 +59,7 @@ import org.tmatesoft.hg.internal.PropertyMarshal; import org.tmatesoft.hg.internal.remote.Connector; import org.tmatesoft.hg.internal.remote.HttpConnector; +import org.tmatesoft.hg.internal.remote.SshConnector; import org.tmatesoft.hg.util.LogFacility.Severity; import org.tmatesoft.hg.util.Outcome; import org.tmatesoft.hg.util.Pair; @@ -115,7 +114,7 @@ } sessionContext = ctx; debug = new PropertyMarshal(ctx).getBoolean("hg4j.remote.debug", false); - remote = new HttpConnector(); + remote = "ssh".equals(url.getProtocol()) ? new SshConnector() : new HttpConnector(); remote.init(url, ctx, null); } @@ -281,7 +280,7 @@ List<Nodeid> _roots = roots.isEmpty() ? Collections.singletonList(Nodeid.NULL) : roots; try { remote.sessionBegin(); - File tf = writeBundle(remote.changegroup(_roots), false, "HG10GZ" /*didn't see any other that zip*/); + File tf = writeBundle(remote.changegroup(_roots)); if (debug) { System.out.printf("Wrote bundle %s for roots %s\n", tf, roots); } @@ -459,18 +458,10 @@ } } - private static File writeBundle(InputStream is, boolean decompress, String header) throws IOException { - InputStream zipStream = decompress ? new InflaterInputStream(is) : is; + private File writeBundle(InputStream is) throws IOException { File tf = File.createTempFile("hg4j-bundle-", null); - FileOutputStream fos = new FileOutputStream(tf); - fos.write(header.getBytes()); - int r; - byte[] buf = new byte[8*1024]; - while ((r = zipStream.read(buf)) != -1) { - fos.write(buf, 0, r); - } - fos.close(); - zipStream.close(); + new FileUtils(sessionContext.getLog(), this).write(is, tf); + is.close(); return tf; }