You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BasePackFetchConnection.java 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. /*
  2. * Copyright (C) 2008-2010, Google Inc.
  3. * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
  4. * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
  5. * and other copyright owners as documented in the project's IP log.
  6. *
  7. * This program and the accompanying materials are made available
  8. * under the terms of the Eclipse Distribution License v1.0 which
  9. * accompanies this distribution, is reproduced below, and is
  10. * available at http://www.eclipse.org/org/documents/edl-v10.php
  11. *
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or
  15. * without modification, are permitted provided that the following
  16. * conditions are met:
  17. *
  18. * - Redistributions of source code must retain the above copyright
  19. * notice, this list of conditions and the following disclaimer.
  20. *
  21. * - Redistributions in binary form must reproduce the above
  22. * copyright notice, this list of conditions and the following
  23. * disclaimer in the documentation and/or other materials provided
  24. * with the distribution.
  25. *
  26. * - Neither the name of the Eclipse Foundation, Inc. nor the
  27. * names of its contributors may be used to endorse or promote
  28. * products derived from this software without specific prior
  29. * written permission.
  30. *
  31. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  32. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  33. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  34. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  35. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  36. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  37. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  38. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  39. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  40. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  41. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  42. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  43. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44. */
  45. package org.eclipse.jgit.transport;
  46. import java.io.IOException;
  47. import java.io.InputStream;
  48. import java.text.MessageFormat;
  49. import java.util.Collection;
  50. import java.util.Collections;
  51. import java.util.Date;
  52. import java.util.Set;
  53. import org.eclipse.jgit.JGitText;
  54. import org.eclipse.jgit.errors.PackProtocolException;
  55. import org.eclipse.jgit.errors.TransportException;
  56. import org.eclipse.jgit.lib.AnyObjectId;
  57. import org.eclipse.jgit.lib.Config;
  58. import org.eclipse.jgit.lib.Constants;
  59. import org.eclipse.jgit.lib.MutableObjectId;
  60. import org.eclipse.jgit.lib.ObjectId;
  61. import org.eclipse.jgit.lib.ObjectInserter;
  62. import org.eclipse.jgit.lib.ProgressMonitor;
  63. import org.eclipse.jgit.lib.Ref;
  64. import org.eclipse.jgit.lib.Config.SectionParser;
  65. import org.eclipse.jgit.revwalk.RevCommit;
  66. import org.eclipse.jgit.revwalk.RevCommitList;
  67. import org.eclipse.jgit.revwalk.RevFlag;
  68. import org.eclipse.jgit.revwalk.RevObject;
  69. import org.eclipse.jgit.revwalk.RevSort;
  70. import org.eclipse.jgit.revwalk.RevWalk;
  71. import org.eclipse.jgit.revwalk.filter.CommitTimeRevFilter;
  72. import org.eclipse.jgit.revwalk.filter.RevFilter;
  73. import org.eclipse.jgit.storage.file.PackLock;
  74. import org.eclipse.jgit.transport.PacketLineIn.AckNackResult;
  75. import org.eclipse.jgit.util.TemporaryBuffer;
  76. /**
  77. * Fetch implementation using the native Git pack transfer service.
  78. * <p>
  79. * This is the canonical implementation for transferring objects from the remote
  80. * repository to the local repository by talking to the 'git-upload-pack'
  81. * service. Objects are packed on the remote side into a pack file and then sent
  82. * down the pipe to us.
  83. * <p>
  84. * This connection requires only a bi-directional pipe or socket, and thus is
  85. * easily wrapped up into a local process pipe, anonymous TCP socket, or a
  86. * command executed through an SSH tunnel.
  87. * <p>
  88. * If {@link BasePackConnection#statelessRPC} is {@code true}, this connection
  89. * can be tunneled over a request-response style RPC system like HTTP. The RPC
  90. * call boundary is determined by this class switching from writing to the
  91. * OutputStream to reading from the InputStream.
  92. * <p>
  93. * Concrete implementations should just call
  94. * {@link #init(java.io.InputStream, java.io.OutputStream)} and
  95. * {@link #readAdvertisedRefs()} methods in constructor or before any use. They
  96. * should also handle resources releasing in {@link #close()} method if needed.
  97. */
  98. public abstract class BasePackFetchConnection extends BasePackConnection
  99. implements FetchConnection {
  100. /**
  101. * Maximum number of 'have' lines to send before giving up.
  102. * <p>
  103. * During {@link #negotiate(ProgressMonitor)} we send at most this many
  104. * commits to the remote peer as 'have' lines without an ACK response before
  105. * we give up.
  106. */
  107. private static final int MAX_HAVES = 256;
  108. /**
  109. * Amount of data the client sends before starting to read.
  110. * <p>
  111. * Any output stream given to the client must be able to buffer this many
  112. * bytes before the client will stop writing and start reading from the
  113. * input stream. If the output stream blocks before this many bytes are in
  114. * the send queue, the system will deadlock.
  115. */
  116. protected static final int MIN_CLIENT_BUFFER = 2 * 32 * 46 + 8;
  117. static final String OPTION_INCLUDE_TAG = "include-tag";
  118. static final String OPTION_MULTI_ACK = "multi_ack";
  119. static final String OPTION_MULTI_ACK_DETAILED = "multi_ack_detailed";
  120. static final String OPTION_THIN_PACK = "thin-pack";
  121. static final String OPTION_SIDE_BAND = "side-band";
  122. static final String OPTION_SIDE_BAND_64K = "side-band-64k";
  123. static final String OPTION_OFS_DELTA = "ofs-delta";
  124. static final String OPTION_SHALLOW = "shallow";
  125. static final String OPTION_NO_PROGRESS = "no-progress";
  126. static final String OPTION_NO_DONE = "no-done";
  127. static enum MultiAck {
  128. OFF, CONTINUE, DETAILED;
  129. }
  130. private final RevWalk walk;
  131. /** All commits that are immediately reachable by a local ref. */
  132. private RevCommitList<RevCommit> reachableCommits;
  133. /** Marks an object as having all its dependencies. */
  134. final RevFlag REACHABLE;
  135. /** Marks a commit known to both sides of the connection. */
  136. final RevFlag COMMON;
  137. /** Like {@link #COMMON} but means its also in {@link #pckState}. */
  138. private final RevFlag STATE;
  139. /** Marks a commit listed in the advertised refs. */
  140. final RevFlag ADVERTISED;
  141. private MultiAck multiAck = MultiAck.OFF;
  142. private boolean thinPack;
  143. private boolean sideband;
  144. private boolean includeTags;
  145. private boolean allowOfsDelta;
  146. private boolean noDone;
  147. private String lockMessage;
  148. private PackLock packLock;
  149. /** RPC state, if {@link BasePackConnection#statelessRPC} is true. */
  150. private TemporaryBuffer.Heap state;
  151. private PacketLineOut pckState;
  152. /**
  153. * Create a new connection to fetch using the native git transport.
  154. *
  155. * @param packTransport
  156. * the transport.
  157. */
  158. public BasePackFetchConnection(final PackTransport packTransport) {
  159. super(packTransport);
  160. final FetchConfig cfg = local.getConfig().get(FetchConfig.KEY);
  161. includeTags = transport.getTagOpt() != TagOpt.NO_TAGS;
  162. thinPack = transport.isFetchThin();
  163. allowOfsDelta = cfg.allowOfsDelta;
  164. walk = new RevWalk(local);
  165. reachableCommits = new RevCommitList<RevCommit>();
  166. REACHABLE = walk.newFlag("REACHABLE");
  167. COMMON = walk.newFlag("COMMON");
  168. STATE = walk.newFlag("STATE");
  169. ADVERTISED = walk.newFlag("ADVERTISED");
  170. walk.carry(COMMON);
  171. walk.carry(REACHABLE);
  172. walk.carry(ADVERTISED);
  173. }
  174. private static class FetchConfig {
  175. static final SectionParser<FetchConfig> KEY = new SectionParser<FetchConfig>() {
  176. public FetchConfig parse(final Config cfg) {
  177. return new FetchConfig(cfg);
  178. }
  179. };
  180. final boolean allowOfsDelta;
  181. FetchConfig(final Config c) {
  182. allowOfsDelta = c.getBoolean("repack", "usedeltabaseoffset", true);
  183. }
  184. }
  185. public final void fetch(final ProgressMonitor monitor,
  186. final Collection<Ref> want, final Set<ObjectId> have)
  187. throws TransportException {
  188. markStartedOperation();
  189. doFetch(monitor, want, have);
  190. }
  191. public boolean didFetchIncludeTags() {
  192. return false;
  193. }
  194. public boolean didFetchTestConnectivity() {
  195. return false;
  196. }
  197. public void setPackLockMessage(final String message) {
  198. lockMessage = message;
  199. }
  200. public Collection<PackLock> getPackLocks() {
  201. if (packLock != null)
  202. return Collections.singleton(packLock);
  203. return Collections.<PackLock> emptyList();
  204. }
  205. /**
  206. * Execute common ancestor negotiation and fetch the objects.
  207. *
  208. * @param monitor
  209. * progress monitor to receive status updates.
  210. * @param want
  211. * the advertised remote references the caller wants to fetch.
  212. * @param have
  213. * additional objects to assume that already exist locally. This
  214. * will be added to the set of objects reachable from the
  215. * destination repository's references.
  216. * @throws TransportException
  217. * if any exception occurs.
  218. */
  219. protected void doFetch(final ProgressMonitor monitor,
  220. final Collection<Ref> want, final Set<ObjectId> have)
  221. throws TransportException {
  222. try {
  223. markRefsAdvertised();
  224. markReachable(have, maxTimeWanted(want));
  225. if (statelessRPC) {
  226. state = new TemporaryBuffer.Heap(Integer.MAX_VALUE);
  227. pckState = new PacketLineOut(state);
  228. }
  229. if (sendWants(want)) {
  230. negotiate(monitor);
  231. walk.dispose();
  232. reachableCommits = null;
  233. state = null;
  234. pckState = null;
  235. receivePack(monitor);
  236. }
  237. } catch (CancelledException ce) {
  238. close();
  239. return; // Caller should test (or just know) this themselves.
  240. } catch (IOException err) {
  241. close();
  242. throw new TransportException(err.getMessage(), err);
  243. } catch (RuntimeException err) {
  244. close();
  245. throw new TransportException(err.getMessage(), err);
  246. }
  247. }
  248. @Override
  249. public void close() {
  250. walk.release();
  251. super.close();
  252. }
  253. private int maxTimeWanted(final Collection<Ref> wants) {
  254. int maxTime = 0;
  255. for (final Ref r : wants) {
  256. try {
  257. final RevObject obj = walk.parseAny(r.getObjectId());
  258. if (obj instanceof RevCommit) {
  259. final int cTime = ((RevCommit) obj).getCommitTime();
  260. if (maxTime < cTime)
  261. maxTime = cTime;
  262. }
  263. } catch (IOException error) {
  264. // We don't have it, but we want to fetch (thus fixing error).
  265. }
  266. }
  267. return maxTime;
  268. }
  269. private void markReachable(final Set<ObjectId> have, final int maxTime)
  270. throws IOException {
  271. for (final Ref r : local.getAllRefs().values()) {
  272. ObjectId id = r.getPeeledObjectId();
  273. if (id == null)
  274. id = r.getObjectId();
  275. if (id == null)
  276. continue;
  277. parseReachable(id);
  278. }
  279. for (ObjectId id : local.getAdditionalHaves())
  280. parseReachable(id);
  281. for (ObjectId id : have)
  282. parseReachable(id);
  283. if (maxTime > 0) {
  284. // Mark reachable commits until we reach maxTime. These may
  285. // wind up later matching up against things we want and we
  286. // can avoid asking for something we already happen to have.
  287. //
  288. final Date maxWhen = new Date(maxTime * 1000L);
  289. walk.sort(RevSort.COMMIT_TIME_DESC);
  290. walk.markStart(reachableCommits);
  291. walk.setRevFilter(CommitTimeRevFilter.after(maxWhen));
  292. for (;;) {
  293. final RevCommit c = walk.next();
  294. if (c == null)
  295. break;
  296. if (c.has(ADVERTISED) && !c.has(COMMON)) {
  297. // This is actually going to be a common commit, but
  298. // our peer doesn't know that fact yet.
  299. //
  300. c.add(COMMON);
  301. c.carry(COMMON);
  302. reachableCommits.add(c);
  303. }
  304. }
  305. }
  306. }
  307. private void parseReachable(ObjectId id) {
  308. try {
  309. RevCommit o = walk.parseCommit(id);
  310. if (!o.has(REACHABLE)) {
  311. o.add(REACHABLE);
  312. reachableCommits.add(o);
  313. }
  314. } catch (IOException readError) {
  315. // If we cannot read the value of the ref skip it.
  316. }
  317. }
  318. private boolean sendWants(final Collection<Ref> want) throws IOException {
  319. final PacketLineOut p = statelessRPC ? pckState : pckOut;
  320. boolean first = true;
  321. for (final Ref r : want) {
  322. try {
  323. if (walk.parseAny(r.getObjectId()).has(REACHABLE)) {
  324. // We already have this object. Asking for it is
  325. // not a very good idea.
  326. //
  327. continue;
  328. }
  329. } catch (IOException err) {
  330. // Its OK, we don't have it, but we want to fix that
  331. // by fetching the object from the other side.
  332. }
  333. final StringBuilder line = new StringBuilder(46);
  334. line.append("want ");
  335. line.append(r.getObjectId().name());
  336. if (first) {
  337. line.append(enableCapabilities());
  338. first = false;
  339. }
  340. line.append('\n');
  341. p.writeString(line.toString());
  342. }
  343. if (first)
  344. return false;
  345. p.end();
  346. outNeedsEnd = false;
  347. return true;
  348. }
  349. private String enableCapabilities() throws TransportException {
  350. final StringBuilder line = new StringBuilder();
  351. if (includeTags)
  352. includeTags = wantCapability(line, OPTION_INCLUDE_TAG);
  353. if (allowOfsDelta)
  354. wantCapability(line, OPTION_OFS_DELTA);
  355. if (wantCapability(line, OPTION_MULTI_ACK_DETAILED)) {
  356. multiAck = MultiAck.DETAILED;
  357. if (statelessRPC)
  358. noDone = wantCapability(line, OPTION_NO_DONE);
  359. } else if (wantCapability(line, OPTION_MULTI_ACK))
  360. multiAck = MultiAck.CONTINUE;
  361. else
  362. multiAck = MultiAck.OFF;
  363. if (thinPack)
  364. thinPack = wantCapability(line, OPTION_THIN_PACK);
  365. if (wantCapability(line, OPTION_SIDE_BAND_64K))
  366. sideband = true;
  367. else if (wantCapability(line, OPTION_SIDE_BAND))
  368. sideband = true;
  369. if (statelessRPC && multiAck != MultiAck.DETAILED) {
  370. // Our stateless RPC implementation relies upon the detailed
  371. // ACK status to tell us common objects for reuse in future
  372. // requests. If its not enabled, we can't talk to the peer.
  373. //
  374. throw new PackProtocolException(uri, MessageFormat.format(JGitText.get().statelessRPCRequiresOptionToBeEnabled, OPTION_MULTI_ACK_DETAILED));
  375. }
  376. return line.toString();
  377. }
  378. private void negotiate(final ProgressMonitor monitor) throws IOException,
  379. CancelledException {
  380. final MutableObjectId ackId = new MutableObjectId();
  381. int resultsPending = 0;
  382. int havesSent = 0;
  383. int havesSinceLastContinue = 0;
  384. boolean receivedContinue = false;
  385. boolean receivedAck = false;
  386. boolean receivedReady = false;
  387. if (statelessRPC)
  388. state.writeTo(out, null);
  389. negotiateBegin();
  390. SEND_HAVES: while (!receivedReady) {
  391. final RevCommit c = walk.next();
  392. if (c == null)
  393. break SEND_HAVES;
  394. pckOut.writeString("have " + c.getId().name() + "\n");
  395. havesSent++;
  396. havesSinceLastContinue++;
  397. if ((31 & havesSent) != 0) {
  398. // We group the have lines into blocks of 32, each marked
  399. // with a flush (aka end). This one is within a block so
  400. // continue with another have line.
  401. //
  402. continue;
  403. }
  404. if (monitor.isCancelled())
  405. throw new CancelledException();
  406. pckOut.end();
  407. resultsPending++; // Each end will cause a result to come back.
  408. if (havesSent == 32 && !statelessRPC) {
  409. // On the first block we race ahead and try to send
  410. // more of the second block while waiting for the
  411. // remote to respond to our first block request.
  412. // This keeps us one block ahead of the peer.
  413. //
  414. continue;
  415. }
  416. READ_RESULT: for (;;) {
  417. final AckNackResult anr = pckIn.readACK(ackId);
  418. switch (anr) {
  419. case NAK:
  420. // More have lines are necessary to compute the
  421. // pack on the remote side. Keep doing that.
  422. //
  423. resultsPending--;
  424. break READ_RESULT;
  425. case ACK:
  426. // The remote side is happy and knows exactly what
  427. // to send us. There is no further negotiation and
  428. // we can break out immediately.
  429. //
  430. multiAck = MultiAck.OFF;
  431. resultsPending = 0;
  432. receivedAck = true;
  433. if (statelessRPC)
  434. state.writeTo(out, null);
  435. break SEND_HAVES;
  436. case ACK_CONTINUE:
  437. case ACK_COMMON:
  438. case ACK_READY:
  439. // The server knows this commit (ackId). We don't
  440. // need to send any further along its ancestry, but
  441. // we need to continue to talk about other parts of
  442. // our local history.
  443. //
  444. markCommon(walk.parseAny(ackId), anr);
  445. receivedAck = true;
  446. receivedContinue = true;
  447. havesSinceLastContinue = 0;
  448. if (anr == AckNackResult.ACK_READY)
  449. receivedReady = true;
  450. break;
  451. }
  452. if (monitor.isCancelled())
  453. throw new CancelledException();
  454. }
  455. if (statelessRPC)
  456. state.writeTo(out, null);
  457. if (receivedContinue && havesSinceLastContinue > MAX_HAVES) {
  458. // Our history must be really different from the remote's.
  459. // We just sent a whole slew of have lines, and it did not
  460. // recognize any of them. Avoid sending our entire history
  461. // to them by giving up early.
  462. //
  463. break SEND_HAVES;
  464. }
  465. }
  466. // Tell the remote side we have run out of things to talk about.
  467. //
  468. if (monitor.isCancelled())
  469. throw new CancelledException();
  470. if (!receivedReady || !noDone) {
  471. // When statelessRPC is true we should always leave SEND_HAVES
  472. // loop above while in the middle of a request. This allows us
  473. // to just write done immediately.
  474. //
  475. pckOut.writeString("done\n");
  476. pckOut.flush();
  477. }
  478. if (!receivedAck) {
  479. // Apparently if we have never received an ACK earlier
  480. // there is one more result expected from the done we
  481. // just sent to the remote.
  482. //
  483. multiAck = MultiAck.OFF;
  484. resultsPending++;
  485. }
  486. READ_RESULT: while (resultsPending > 0 || multiAck != MultiAck.OFF) {
  487. final AckNackResult anr = pckIn.readACK(ackId);
  488. resultsPending--;
  489. switch (anr) {
  490. case NAK:
  491. // A NAK is a response to an end we queued earlier
  492. // we eat it and look for another ACK/NAK message.
  493. //
  494. break;
  495. case ACK:
  496. // A solitary ACK at this point means the remote won't
  497. // speak anymore, but is going to send us a pack now.
  498. //
  499. break READ_RESULT;
  500. case ACK_CONTINUE:
  501. case ACK_COMMON:
  502. case ACK_READY:
  503. // We will expect a normal ACK to break out of the loop.
  504. //
  505. multiAck = MultiAck.CONTINUE;
  506. break;
  507. }
  508. if (monitor.isCancelled())
  509. throw new CancelledException();
  510. }
  511. }
  512. private void negotiateBegin() throws IOException {
  513. walk.resetRetain(REACHABLE, ADVERTISED);
  514. walk.markStart(reachableCommits);
  515. walk.sort(RevSort.COMMIT_TIME_DESC);
  516. walk.setRevFilter(new RevFilter() {
  517. @Override
  518. public RevFilter clone() {
  519. return this;
  520. }
  521. @Override
  522. public boolean include(final RevWalk walker, final RevCommit c) {
  523. final boolean remoteKnowsIsCommon = c.has(COMMON);
  524. if (c.has(ADVERTISED)) {
  525. // Remote advertised this, and we have it, hence common.
  526. // Whether or not the remote knows that fact is tested
  527. // before we added the flag. If the remote doesn't know
  528. // we have to still send them this object.
  529. //
  530. c.add(COMMON);
  531. }
  532. return !remoteKnowsIsCommon;
  533. }
  534. @Override
  535. public boolean requiresCommitBody() {
  536. return false;
  537. }
  538. });
  539. }
  540. private void markRefsAdvertised() {
  541. for (final Ref r : getRefs()) {
  542. markAdvertised(r.getObjectId());
  543. if (r.getPeeledObjectId() != null)
  544. markAdvertised(r.getPeeledObjectId());
  545. }
  546. }
  547. private void markAdvertised(final AnyObjectId id) {
  548. try {
  549. walk.parseAny(id).add(ADVERTISED);
  550. } catch (IOException readError) {
  551. // We probably just do not have this object locally.
  552. }
  553. }
  554. private void markCommon(final RevObject obj, final AckNackResult anr)
  555. throws IOException {
  556. if (statelessRPC && anr == AckNackResult.ACK_COMMON && !obj.has(STATE)) {
  557. StringBuilder s;
  558. s = new StringBuilder(6 + Constants.OBJECT_ID_STRING_LENGTH);
  559. s.append("have "); //$NON-NLS-1$
  560. s.append(obj.name());
  561. s.append('\n');
  562. pckState.writeString(s.toString());
  563. obj.add(STATE);
  564. }
  565. obj.add(COMMON);
  566. if (obj instanceof RevCommit)
  567. ((RevCommit) obj).carry(COMMON);
  568. }
  569. private void receivePack(final ProgressMonitor monitor) throws IOException {
  570. InputStream input = in;
  571. if (sideband)
  572. input = new SideBandInputStream(input, monitor, getMessageWriter());
  573. ObjectInserter ins = local.newObjectInserter();
  574. try {
  575. PackParser parser = ins.newPackParser(input);
  576. parser.setAllowThin(thinPack);
  577. parser.setObjectChecking(transport.isCheckFetchedObjects());
  578. parser.setLockMessage(lockMessage);
  579. packLock = parser.parse(monitor);
  580. ins.flush();
  581. } finally {
  582. ins.release();
  583. }
  584. }
  585. private static class CancelledException extends Exception {
  586. private static final long serialVersionUID = 1L;
  587. }
  588. }