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.

UploadPack.java 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. /*
  2. * Copyright (C) 2008-2010, Google Inc.
  3. * and other copyright owners as documented in the project's IP log.
  4. *
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Distribution License v1.0 which
  7. * accompanies this distribution, is reproduced below, and is
  8. * available at http://www.eclipse.org/org/documents/edl-v10.php
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials provided
  22. * with the distribution.
  23. *
  24. * - Neither the name of the Eclipse Foundation, Inc. nor the
  25. * names of its contributors may be used to endorse or promote
  26. * products derived from this software without specific prior
  27. * written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  30. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  31. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  36. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  38. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  41. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. */
  43. package org.eclipse.jgit.transport;
  44. import java.io.EOFException;
  45. import java.io.IOException;
  46. import java.io.InputStream;
  47. import java.io.OutputStream;
  48. import java.text.MessageFormat;
  49. import java.util.ArrayList;
  50. import java.util.HashSet;
  51. import java.util.List;
  52. import java.util.Map;
  53. import java.util.Set;
  54. import org.eclipse.jgit.JGitText;
  55. import org.eclipse.jgit.errors.MissingObjectException;
  56. import org.eclipse.jgit.errors.PackProtocolException;
  57. import org.eclipse.jgit.lib.Constants;
  58. import org.eclipse.jgit.lib.NullProgressMonitor;
  59. import org.eclipse.jgit.lib.ObjectId;
  60. import org.eclipse.jgit.lib.ProgressMonitor;
  61. import org.eclipse.jgit.lib.Ref;
  62. import org.eclipse.jgit.lib.Repository;
  63. import org.eclipse.jgit.revwalk.AsyncRevObjectQueue;
  64. import org.eclipse.jgit.revwalk.RevCommit;
  65. import org.eclipse.jgit.revwalk.RevFlag;
  66. import org.eclipse.jgit.revwalk.RevFlagSet;
  67. import org.eclipse.jgit.revwalk.RevObject;
  68. import org.eclipse.jgit.revwalk.RevTag;
  69. import org.eclipse.jgit.revwalk.RevWalk;
  70. import org.eclipse.jgit.storage.pack.PackConfig;
  71. import org.eclipse.jgit.storage.pack.PackWriter;
  72. import org.eclipse.jgit.transport.BasePackFetchConnection.MultiAck;
  73. import org.eclipse.jgit.transport.RefAdvertiser.PacketLineOutRefAdvertiser;
  74. import org.eclipse.jgit.util.io.InterruptTimer;
  75. import org.eclipse.jgit.util.io.TimeoutInputStream;
  76. import org.eclipse.jgit.util.io.TimeoutOutputStream;
  77. /**
  78. * Implements the server side of a fetch connection, transmitting objects.
  79. */
  80. public class UploadPack {
  81. static final String OPTION_INCLUDE_TAG = BasePackFetchConnection.OPTION_INCLUDE_TAG;
  82. static final String OPTION_MULTI_ACK = BasePackFetchConnection.OPTION_MULTI_ACK;
  83. static final String OPTION_MULTI_ACK_DETAILED = BasePackFetchConnection.OPTION_MULTI_ACK_DETAILED;
  84. static final String OPTION_THIN_PACK = BasePackFetchConnection.OPTION_THIN_PACK;
  85. static final String OPTION_SIDE_BAND = BasePackFetchConnection.OPTION_SIDE_BAND;
  86. static final String OPTION_SIDE_BAND_64K = BasePackFetchConnection.OPTION_SIDE_BAND_64K;
  87. static final String OPTION_OFS_DELTA = BasePackFetchConnection.OPTION_OFS_DELTA;
  88. static final String OPTION_NO_PROGRESS = BasePackFetchConnection.OPTION_NO_PROGRESS;
  89. /** Database we read the objects from. */
  90. private final Repository db;
  91. /** Revision traversal support over {@link #db}. */
  92. private final RevWalk walk;
  93. /** Configuration to pass into the PackWriter. */
  94. private PackConfig packConfig;
  95. /** Timeout in seconds to wait for client interaction. */
  96. private int timeout;
  97. /**
  98. * Is the client connection a bi-directional socket or pipe?
  99. * <p>
  100. * If true, this class assumes it can perform multiple read and write cycles
  101. * with the client over the input and output streams. This matches the
  102. * functionality available with a standard TCP/IP connection, or a local
  103. * operating system or in-memory pipe.
  104. * <p>
  105. * If false, this class runs in a read everything then output results mode,
  106. * making it suitable for single round-trip systems RPCs such as HTTP.
  107. */
  108. private boolean biDirectionalPipe = true;
  109. /** Timer to manage {@link #timeout}. */
  110. private InterruptTimer timer;
  111. private InputStream rawIn;
  112. private OutputStream rawOut;
  113. private PacketLineIn pckIn;
  114. private PacketLineOut pckOut;
  115. /** The refs we advertised as existing at the start of the connection. */
  116. private Map<String, Ref> refs;
  117. /** Filter used while advertising the refs to the client. */
  118. private RefFilter refFilter;
  119. /** Capabilities requested by the client. */
  120. private final Set<String> options = new HashSet<String>();
  121. /** Objects the client wants to obtain. */
  122. private final List<RevObject> wantAll = new ArrayList<RevObject>();
  123. /** Objects on both sides, these don't have to be sent. */
  124. private final List<RevObject> commonBase = new ArrayList<RevObject>();
  125. /** null if {@link #commonBase} should be examined again. */
  126. private Boolean okToGiveUp;
  127. /** Objects we sent in our advertisement list, clients can ask for these. */
  128. private Set<ObjectId> advertised;
  129. /** Marked on objects the client has asked us to give them. */
  130. private final RevFlag WANT;
  131. /** Marked on objects both we and the client have. */
  132. private final RevFlag PEER_HAS;
  133. /** Marked on objects in {@link #commonBase}. */
  134. private final RevFlag COMMON;
  135. /** Objects where we found a path from the want list to a common base. */
  136. private final RevFlag SATISFIED;
  137. private final RevFlagSet SAVE;
  138. private MultiAck multiAck = MultiAck.OFF;
  139. /**
  140. * Create a new pack upload for an open repository.
  141. *
  142. * @param copyFrom
  143. * the source repository.
  144. */
  145. public UploadPack(final Repository copyFrom) {
  146. db = copyFrom;
  147. walk = new RevWalk(db);
  148. walk.setRetainBody(false);
  149. WANT = walk.newFlag("WANT");
  150. PEER_HAS = walk.newFlag("PEER_HAS");
  151. COMMON = walk.newFlag("COMMON");
  152. SATISFIED = walk.newFlag("SATISFIED");
  153. walk.carry(PEER_HAS);
  154. SAVE = new RevFlagSet();
  155. SAVE.add(WANT);
  156. SAVE.add(PEER_HAS);
  157. refFilter = RefFilter.DEFAULT;
  158. }
  159. /** @return the repository this upload is reading from. */
  160. public final Repository getRepository() {
  161. return db;
  162. }
  163. /** @return the RevWalk instance used by this connection. */
  164. public final RevWalk getRevWalk() {
  165. return walk;
  166. }
  167. /** @return timeout (in seconds) before aborting an IO operation. */
  168. public int getTimeout() {
  169. return timeout;
  170. }
  171. /**
  172. * Set the timeout before willing to abort an IO call.
  173. *
  174. * @param seconds
  175. * number of seconds to wait (with no data transfer occurring)
  176. * before aborting an IO read or write operation with the
  177. * connected client.
  178. */
  179. public void setTimeout(final int seconds) {
  180. timeout = seconds;
  181. }
  182. /**
  183. * @return true if this class expects a bi-directional pipe opened between
  184. * the client and itself. The default is true.
  185. */
  186. public boolean isBiDirectionalPipe() {
  187. return biDirectionalPipe;
  188. }
  189. /**
  190. * @param twoWay
  191. * if true, this class will assume the socket is a fully
  192. * bidirectional pipe between the two peers and takes advantage
  193. * of that by first transmitting the known refs, then waiting to
  194. * read commands. If false, this class assumes it must read the
  195. * commands before writing output and does not perform the
  196. * initial advertising.
  197. */
  198. public void setBiDirectionalPipe(final boolean twoWay) {
  199. biDirectionalPipe = twoWay;
  200. }
  201. /** @return the filter used while advertising the refs to the client */
  202. public RefFilter getRefFilter() {
  203. return refFilter;
  204. }
  205. /**
  206. * Set the filter used while advertising the refs to the client.
  207. * <p>
  208. * Only refs allowed by this filter will be sent to the client. This can
  209. * be used by a server to restrict the list of references the client can
  210. * obtain through clone or fetch, effectively limiting the access to only
  211. * certain refs.
  212. *
  213. * @param refFilter
  214. * the filter; may be null to show all refs.
  215. */
  216. public void setRefFilter(final RefFilter refFilter) {
  217. this.refFilter = refFilter != null ? refFilter : RefFilter.DEFAULT;
  218. }
  219. /**
  220. * Set the configuration used by the pack generator.
  221. *
  222. * @param pc
  223. * configuration controlling packing parameters. If null the
  224. * source repository's settings will be used.
  225. */
  226. public void setPackConfig(PackConfig pc) {
  227. this.packConfig = pc;
  228. }
  229. /**
  230. * Execute the upload task on the socket.
  231. *
  232. * @param input
  233. * raw input to read client commands from. Caller must ensure the
  234. * input is buffered, otherwise read performance may suffer.
  235. * @param output
  236. * response back to the Git network client, to write the pack
  237. * data onto. Caller must ensure the output is buffered,
  238. * otherwise write performance may suffer.
  239. * @param messages
  240. * secondary "notice" channel to send additional messages out
  241. * through. When run over SSH this should be tied back to the
  242. * standard error channel of the command execution. For most
  243. * other network connections this should be null.
  244. * @throws IOException
  245. */
  246. public void upload(final InputStream input, final OutputStream output,
  247. final OutputStream messages) throws IOException {
  248. try {
  249. rawIn = input;
  250. rawOut = output;
  251. if (timeout > 0) {
  252. final Thread caller = Thread.currentThread();
  253. timer = new InterruptTimer(caller.getName() + "-Timer");
  254. TimeoutInputStream i = new TimeoutInputStream(rawIn, timer);
  255. TimeoutOutputStream o = new TimeoutOutputStream(rawOut, timer);
  256. i.setTimeout(timeout * 1000);
  257. o.setTimeout(timeout * 1000);
  258. rawIn = i;
  259. rawOut = o;
  260. }
  261. pckIn = new PacketLineIn(rawIn);
  262. pckOut = new PacketLineOut(rawOut);
  263. service();
  264. } finally {
  265. walk.release();
  266. if (timer != null) {
  267. try {
  268. timer.terminate();
  269. } finally {
  270. timer = null;
  271. }
  272. }
  273. }
  274. }
  275. private void service() throws IOException {
  276. if (biDirectionalPipe)
  277. sendAdvertisedRefs(new PacketLineOutRefAdvertiser(pckOut));
  278. else {
  279. advertised = new HashSet<ObjectId>();
  280. refs = refFilter.filter(db.getAllRefs());
  281. for (Ref ref : refs.values()) {
  282. if (ref.getObjectId() != null)
  283. advertised.add(ref.getObjectId());
  284. }
  285. }
  286. recvWants();
  287. if (wantAll.isEmpty())
  288. return;
  289. if (options.contains(OPTION_MULTI_ACK_DETAILED))
  290. multiAck = MultiAck.DETAILED;
  291. else if (options.contains(OPTION_MULTI_ACK))
  292. multiAck = MultiAck.CONTINUE;
  293. else
  294. multiAck = MultiAck.OFF;
  295. if (negotiate())
  296. sendPack();
  297. }
  298. /**
  299. * Generate an advertisement of available refs and capabilities.
  300. *
  301. * @param adv
  302. * the advertisement formatter.
  303. * @throws IOException
  304. * the formatter failed to write an advertisement.
  305. */
  306. public void sendAdvertisedRefs(final RefAdvertiser adv) throws IOException {
  307. adv.init(db);
  308. adv.advertiseCapability(OPTION_INCLUDE_TAG);
  309. adv.advertiseCapability(OPTION_MULTI_ACK_DETAILED);
  310. adv.advertiseCapability(OPTION_MULTI_ACK);
  311. adv.advertiseCapability(OPTION_OFS_DELTA);
  312. adv.advertiseCapability(OPTION_SIDE_BAND);
  313. adv.advertiseCapability(OPTION_SIDE_BAND_64K);
  314. adv.advertiseCapability(OPTION_THIN_PACK);
  315. adv.advertiseCapability(OPTION_NO_PROGRESS);
  316. adv.setDerefTags(true);
  317. refs = refFilter.filter(db.getAllRefs());
  318. advertised = adv.send(refs);
  319. adv.end();
  320. }
  321. private void recvWants() throws IOException {
  322. HashSet<ObjectId> wantIds = new HashSet<ObjectId>();
  323. boolean isFirst = true;
  324. for (;;) {
  325. String line;
  326. try {
  327. line = pckIn.readString();
  328. } catch (EOFException eof) {
  329. if (isFirst)
  330. break;
  331. throw eof;
  332. }
  333. if (line == PacketLineIn.END)
  334. break;
  335. if (!line.startsWith("want ") || line.length() < 45)
  336. throw new PackProtocolException(MessageFormat.format(JGitText.get().expectedGot, "want", line));
  337. if (isFirst && line.length() > 45) {
  338. String opt = line.substring(45);
  339. if (opt.startsWith(" "))
  340. opt = opt.substring(1);
  341. for (String c : opt.split(" "))
  342. options.add(c);
  343. line = line.substring(0, 45);
  344. }
  345. wantIds.add(ObjectId.fromString(line.substring(5)));
  346. isFirst = false;
  347. }
  348. if (wantIds.isEmpty())
  349. return;
  350. AsyncRevObjectQueue q = walk.parseAny(wantIds, true);
  351. try {
  352. for (;;) {
  353. RevObject o;
  354. try {
  355. o = q.next();
  356. } catch (IOException error) {
  357. throw new PackProtocolException(MessageFormat.format(
  358. JGitText.get().notValid, error.getMessage()), error);
  359. }
  360. if (o == null)
  361. break;
  362. if (o.has(WANT)) {
  363. // Already processed, the client repeated itself.
  364. } else if (advertised.contains(o)) {
  365. o.add(WANT);
  366. wantAll.add(o);
  367. if (o instanceof RevTag) {
  368. o = walk.peel(o);
  369. if (o instanceof RevCommit) {
  370. if (!o.has(WANT)) {
  371. o.add(WANT);
  372. wantAll.add(o);
  373. }
  374. }
  375. }
  376. } else {
  377. throw new PackProtocolException(MessageFormat.format(
  378. JGitText.get().notValid, o.name()));
  379. }
  380. }
  381. } finally {
  382. q.release();
  383. }
  384. }
  385. private boolean negotiate() throws IOException {
  386. ObjectId last = ObjectId.zeroId();
  387. List<ObjectId> peerHas = new ArrayList<ObjectId>(64);
  388. for (;;) {
  389. String line;
  390. try {
  391. line = pckIn.readString();
  392. } catch (EOFException eof) {
  393. throw eof;
  394. }
  395. if (line == PacketLineIn.END) {
  396. last = processHaveLines(peerHas, last);
  397. if (commonBase.isEmpty() || multiAck != MultiAck.OFF)
  398. pckOut.writeString("NAK\n");
  399. if (!biDirectionalPipe)
  400. return false;
  401. pckOut.flush();
  402. } else if (line.startsWith("have ") && line.length() == 45) {
  403. peerHas.add(ObjectId.fromString(line.substring(5)));
  404. } else if (line.equals("done")) {
  405. last = processHaveLines(peerHas, last);
  406. if (commonBase.isEmpty())
  407. pckOut.writeString("NAK\n");
  408. else if (multiAck != MultiAck.OFF)
  409. pckOut.writeString("ACK " + last.name() + "\n");
  410. return true;
  411. } else {
  412. throw new PackProtocolException(MessageFormat.format(JGitText.get().expectedGot, "have", line));
  413. }
  414. }
  415. }
  416. private ObjectId processHaveLines(List<ObjectId> peerHas, ObjectId last)
  417. throws IOException {
  418. if (peerHas.isEmpty())
  419. return last;
  420. // If both sides have the same object; let the client know.
  421. //
  422. AsyncRevObjectQueue q = walk.parseAny(peerHas, false);
  423. try {
  424. for (;;) {
  425. RevObject obj;
  426. try {
  427. obj = q.next();
  428. } catch (MissingObjectException notFound) {
  429. continue;
  430. }
  431. if (obj == null)
  432. break;
  433. last = obj;
  434. if (obj.has(PEER_HAS))
  435. continue;
  436. obj.add(PEER_HAS);
  437. if (obj instanceof RevCommit)
  438. ((RevCommit) obj).carry(PEER_HAS);
  439. addCommonBase(obj);
  440. switch (multiAck) {
  441. case OFF:
  442. if (commonBase.size() == 1)
  443. pckOut.writeString("ACK " + obj.name() + "\n");
  444. break;
  445. case CONTINUE:
  446. pckOut.writeString("ACK " + obj.name() + " continue\n");
  447. break;
  448. case DETAILED:
  449. pckOut.writeString("ACK " + obj.name() + " common\n");
  450. break;
  451. }
  452. }
  453. } finally {
  454. q.release();
  455. }
  456. // If we don't have one of the objects but we're also willing to
  457. // create a pack at this point, let the client know so it stops
  458. // telling us about its history.
  459. //
  460. for (int i = peerHas.size() - 1; i >= 0; i--) {
  461. ObjectId id = peerHas.get(i);
  462. if (walk.lookupOrNull(id) == null) {
  463. if (okToGiveUp()) {
  464. switch (multiAck) {
  465. case OFF:
  466. break;
  467. case CONTINUE:
  468. pckOut.writeString("ACK " + id.name() + " continue\n");
  469. break;
  470. case DETAILED:
  471. pckOut.writeString("ACK " + id.name() + " ready\n");
  472. break;
  473. }
  474. }
  475. break;
  476. }
  477. }
  478. peerHas.clear();
  479. return last;
  480. }
  481. private void addCommonBase(final RevObject o) {
  482. if (!o.has(COMMON)) {
  483. o.add(COMMON);
  484. commonBase.add(o);
  485. okToGiveUp = null;
  486. }
  487. }
  488. private boolean okToGiveUp() throws PackProtocolException {
  489. if (okToGiveUp == null)
  490. okToGiveUp = Boolean.valueOf(okToGiveUpImp());
  491. return okToGiveUp.booleanValue();
  492. }
  493. private boolean okToGiveUpImp() throws PackProtocolException {
  494. if (commonBase.isEmpty())
  495. return false;
  496. try {
  497. for (RevObject obj : wantAll) {
  498. if (wantSatisfied(obj))
  499. return false;
  500. }
  501. return true;
  502. } catch (IOException e) {
  503. throw new PackProtocolException(JGitText.get().internalRevisionError, e);
  504. }
  505. }
  506. private boolean wantSatisfied(final RevObject want) throws IOException {
  507. if (want.has(SATISFIED))
  508. return true;
  509. if (!(want instanceof RevCommit)) {
  510. want.add(SATISFIED);
  511. return true;
  512. }
  513. walk.resetRetain(SAVE);
  514. walk.markStart((RevCommit) want);
  515. for (;;) {
  516. final RevCommit c = walk.next();
  517. if (c == null)
  518. break;
  519. if (c.has(PEER_HAS)) {
  520. addCommonBase(c);
  521. want.add(SATISFIED);
  522. return true;
  523. }
  524. }
  525. return false;
  526. }
  527. private void sendPack() throws IOException {
  528. final boolean sideband = options.contains(OPTION_SIDE_BAND)
  529. || options.contains(OPTION_SIDE_BAND_64K);
  530. ProgressMonitor pm = NullProgressMonitor.INSTANCE;
  531. OutputStream packOut = rawOut;
  532. SideBandOutputStream msgOut = null;
  533. if (sideband) {
  534. int bufsz = SideBandOutputStream.SMALL_BUF;
  535. if (options.contains(OPTION_SIDE_BAND_64K))
  536. bufsz = SideBandOutputStream.MAX_BUF;
  537. packOut = new SideBandOutputStream(SideBandOutputStream.CH_DATA,
  538. bufsz, rawOut);
  539. if (!options.contains(OPTION_NO_PROGRESS)) {
  540. msgOut = new SideBandOutputStream(
  541. SideBandOutputStream.CH_PROGRESS, bufsz, rawOut);
  542. pm = new SideBandProgressMonitor(msgOut);
  543. }
  544. }
  545. PackConfig cfg = packConfig;
  546. if (cfg == null)
  547. cfg = new PackConfig(db);
  548. final PackWriter pw = new PackWriter(cfg, walk.getObjectReader());
  549. try {
  550. pw.setUseCachedPacks(true);
  551. pw.setDeltaBaseAsOffset(options.contains(OPTION_OFS_DELTA));
  552. pw.setThin(options.contains(OPTION_THIN_PACK));
  553. pw.preparePack(pm, wantAll, commonBase);
  554. if (options.contains(OPTION_INCLUDE_TAG)) {
  555. for (final Ref r : refs.values()) {
  556. final RevObject o;
  557. try {
  558. o = walk.parseAny(r.getObjectId());
  559. } catch (IOException e) {
  560. continue;
  561. }
  562. if (o.has(WANT) || !(o instanceof RevTag))
  563. continue;
  564. final RevTag t = (RevTag) o;
  565. if (!pw.willInclude(t) && pw.willInclude(t.getObject()))
  566. pw.addObject(t);
  567. }
  568. }
  569. pw.writePack(pm, NullProgressMonitor.INSTANCE, packOut);
  570. packOut.flush();
  571. if (msgOut != null) {
  572. String msg = pw.getStatistics().getMessage() + '\n';
  573. msgOut.write(Constants.encode(msg));
  574. msgOut.flush();
  575. }
  576. } finally {
  577. pw.release();
  578. }
  579. if (sideband)
  580. pckOut.end();
  581. }
  582. }