Mercurial > hg4j
comparison src/org/tmatesoft/hg/repo/HgBundle.java @ 645:14dac192aa26
Push: phase2 - upload bundle with changes to remote server
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 20 Jun 2013 19:15:09 +0200 |
parents | 6526d8adbc0f |
children | 12a4f60ea972 |
comparison
equal
deleted
inserted
replaced
644:1deea2f33218 | 645:14dac192aa26 |
---|---|
15 * contact TMate Software at support@hg4j.com | 15 * contact TMate Software at support@hg4j.com |
16 */ | 16 */ |
17 package org.tmatesoft.hg.repo; | 17 package org.tmatesoft.hg.repo; |
18 | 18 |
19 import java.io.File; | 19 import java.io.File; |
20 import java.io.FileInputStream; | |
20 import java.io.IOException; | 21 import java.io.IOException; |
21 import java.util.ConcurrentModificationException; | 22 import java.util.ConcurrentModificationException; |
22 | 23 |
24 import org.tmatesoft.hg.core.HgIOException; | |
23 import org.tmatesoft.hg.core.Nodeid; | 25 import org.tmatesoft.hg.core.Nodeid; |
24 import org.tmatesoft.hg.core.SessionContext; | 26 import org.tmatesoft.hg.core.SessionContext; |
25 import org.tmatesoft.hg.internal.ByteArrayChannel; | 27 import org.tmatesoft.hg.internal.ByteArrayChannel; |
26 import org.tmatesoft.hg.internal.ByteArrayDataAccess; | 28 import org.tmatesoft.hg.internal.ByteArrayDataAccess; |
27 import org.tmatesoft.hg.internal.Callback; | 29 import org.tmatesoft.hg.internal.Callback; |
28 import org.tmatesoft.hg.internal.DataAccess; | 30 import org.tmatesoft.hg.internal.DataAccess; |
29 import org.tmatesoft.hg.internal.DataAccessProvider; | 31 import org.tmatesoft.hg.internal.DataAccessProvider; |
32 import org.tmatesoft.hg.internal.DataSerializer; | |
30 import org.tmatesoft.hg.internal.DigestHelper; | 33 import org.tmatesoft.hg.internal.DigestHelper; |
31 import org.tmatesoft.hg.internal.Experimental; | 34 import org.tmatesoft.hg.internal.Experimental; |
35 import org.tmatesoft.hg.internal.FileUtils; | |
32 import org.tmatesoft.hg.internal.InflaterDataAccess; | 36 import org.tmatesoft.hg.internal.InflaterDataAccess; |
33 import org.tmatesoft.hg.internal.Internals; | 37 import org.tmatesoft.hg.internal.Internals; |
34 import org.tmatesoft.hg.internal.Lifecycle; | 38 import org.tmatesoft.hg.internal.Lifecycle; |
35 import org.tmatesoft.hg.internal.Patch; | 39 import org.tmatesoft.hg.internal.Patch; |
36 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; | 40 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; |
48 @Experimental(reason="API is not stable") | 52 @Experimental(reason="API is not stable") |
49 public class HgBundle { | 53 public class HgBundle { |
50 | 54 |
51 private final File bundleFile; | 55 private final File bundleFile; |
52 private final DataAccessProvider accessProvider; | 56 private final DataAccessProvider accessProvider; |
53 // private final SessionContext sessionContext; | 57 private final SessionContext ctx; |
54 private Lifecycle.BasicCallback flowControl; | 58 private Lifecycle.BasicCallback flowControl; |
55 | 59 |
56 HgBundle(SessionContext ctx, DataAccessProvider dap, File bundle) { | 60 HgBundle(SessionContext sessionContext, DataAccessProvider dap, File bundle) { |
57 // sessionContext = ctx; | 61 ctx = sessionContext; |
58 accessProvider = dap; | 62 accessProvider = dap; |
59 bundleFile = bundle; | 63 bundleFile = bundle; |
60 } | 64 } |
61 | 65 |
62 private DataAccess getDataStream() throws IOException { | 66 private DataAccess getDataStream() throws IOException { |
531 patchCount = -1; | 535 patchCount = -1; |
532 } | 536 } |
533 return String.format("%s %s %s %s; patches:%d\n", node().shortNotation(), firstParent().shortNotation(), secondParent().shortNotation(), cset().shortNotation(), patchCount); | 537 return String.format("%s %s %s %s; patches:%d\n", node().shortNotation(), firstParent().shortNotation(), secondParent().shortNotation(), cset().shortNotation(), patchCount); |
534 } | 538 } |
535 } | 539 } |
540 | |
541 @Experimental(reason="Work in progress, not an API") | |
542 public class BundleSerializer implements DataSerializer.DataSource { | |
543 | |
544 public void serialize(DataSerializer out) throws HgIOException, HgRuntimeException { | |
545 FileInputStream fis = null; | |
546 try { | |
547 fis = new FileInputStream(HgBundle.this.bundleFile); | |
548 byte[] buffer = new byte[8*1024]; | |
549 int r; | |
550 while ((r = fis.read(buffer, 0, buffer.length)) > 0) { | |
551 out.write(buffer, 0, r); | |
552 } | |
553 | |
554 } catch (IOException ex) { | |
555 throw new HgIOException("Failed to serialize bundle", HgBundle.this.bundleFile); | |
556 } finally { | |
557 new FileUtils(HgBundle.this.ctx.getLog()).closeQuietly(fis, HgBundle.this.bundleFile); | |
558 } | |
559 } | |
560 | |
561 public int serializeLength() throws HgRuntimeException { | |
562 return Internals.ltoi(HgBundle.this.bundleFile.length()); | |
563 } | |
564 } | |
536 } | 565 } |