Examples of PackWriter


Examples of org.eclipse.jgit.storage.pack.PackWriter

      final ProgressMonitor monitor) throws IOException {
    List<ObjectId> remoteObjects = new ArrayList<ObjectId>(getRefs().size());
    List<ObjectId> newObjects = new ArrayList<ObjectId>(refUpdates.size());

    final long start;
    final PackWriter writer = new PackWriter(transport.getPackConfig(),
        local.newObjectReader());
    try {

      for (final Ref r : getRefs())
        remoteObjects.add(r.getObjectId());
      remoteObjects.addAll(additionalHaves);
      for (final RemoteRefUpdate r : refUpdates.values()) {
        if (!ObjectId.zeroId().equals(r.getNewObjectId()))
          newObjects.add(r.getNewObjectId());
      }

      writer.setUseCachedPacks(true);
      writer.setThin(thinPack);
      writer.setDeltaBaseAsOffset(capableOfsDelta);
      writer.preparePack(monitor, newObjects, remoteObjects);
      start = System.currentTimeMillis();
      writer.writePack(monitor, monitor, out);
    } finally {
      writer.release();
    }
    out.flush();
    packTransferTime = System.currentTimeMillis() - start;
  }
View Full Code Here

Examples of org.eclipse.jgit.storage.pack.PackWriter

  private void sendpack(final List<RemoteRefUpdate> updates,
      final ProgressMonitor monitor) throws TransportException {
    String pathPack = null;
    String pathIdx = null;

    final PackWriter writer = new PackWriter(transport.getPackConfig(),
        local.newObjectReader());
    try {
      final List<ObjectId> need = new ArrayList<ObjectId>();
      final List<ObjectId> have = new ArrayList<ObjectId>();
      for (final RemoteRefUpdate r : updates)
        need.add(r.getNewObjectId());
      for (final Ref r : getRefs()) {
        have.add(r.getObjectId());
        if (r.getPeeledObjectId() != null)
          have.add(r.getPeeledObjectId());
      }
      writer.preparePack(monitor, need, have);

      // We don't have to continue further if the pack will
      // be an empty pack, as the remote has all objects it
      // needs to complete this change.
      //
      if (writer.getObjectsNumber() == 0)
        return;

      packNames = new LinkedHashMap<String, String>();
      for (final String n : dest.getPackNames())
        packNames.put(n, n);

      final String base = "pack-" + writer.computeName().name();
      final String packName = base + ".pack";
      pathPack = "pack/" + packName;
      pathIdx = "pack/" + base + ".idx";

      if (packNames.remove(packName) != null) {
        // The remote already contains this pack. We should
        // remove the index before overwriting to prevent bad
        // offsets from appearing to clients.
        //
        dest.writeInfoPacks(packNames.keySet());
        dest.deleteFile(pathIdx);
      }

      // Write the pack file, then the index, as readers look the
      // other direction (index, then pack file).
      //
      final String wt = "Put " + base.substring(0, 12);
      OutputStream os = dest.writeFile(pathPack, monitor, wt + "..pack");
      try {
        os = new BufferedOutputStream(os);
        writer.writePack(monitor, monitor, os);
      } finally {
        os.close();
      }

      os = dest.writeFile(pathIdx, monitor, wt + "..idx");
      try {
        os = new BufferedOutputStream(os);
        writer.writeIndex(os);
      } finally {
        os.close();
      }

      // Record the pack at the start of the pack info list. This
      // way clients are likely to consult the newest pack first,
      // and discover the most recent objects there.
      //
      final ArrayList<String> infoPacks = new ArrayList<String>();
      infoPacks.add(packName);
      infoPacks.addAll(packNames.keySet());
      dest.writeInfoPacks(infoPacks);

    } catch (IOException err) {
      safeDelete(pathIdx);
      safeDelete(pathPack);

      throw new TransportException(uri, JGitText.get().cannotStoreObjects, err);
    } finally {
      writer.release();
    }
  }
View Full Code Here

Examples of org.eclipse.jgit.storage.pack.PackWriter

  public void writeBundle(ProgressMonitor monitor, OutputStream os)
      throws IOException {
    PackConfig pc = packConfig;
    if (pc == null)
      pc = new PackConfig(db);
    PackWriter packWriter = new PackWriter(pc, db.newObjectReader());
    try {
      final HashSet<ObjectId> inc = new HashSet<ObjectId>();
      final HashSet<ObjectId> exc = new HashSet<ObjectId>();
      inc.addAll(include.values());
      for (final RevCommit r : assume)
        exc.add(r.getId());
      packWriter.setThin(exc.size() > 0);
      packWriter.preparePack(monitor, inc, exc);

      final Writer w = new OutputStreamWriter(os, Constants.CHARSET);
      w.write(TransportBundle.V2_BUNDLE_SIGNATURE);
      w.write('\n');

      final char[] tmp = new char[Constants.OBJECT_ID_STRING_LENGTH];
      for (final RevCommit a : assume) {
        w.write('-');
        a.copyTo(tmp, w);
        if (a.getRawBuffer() != null) {
          w.write(' ');
          w.write(a.getShortMessage());
        }
        w.write('\n');
      }
      for (final Map.Entry<String, ObjectId> e : include.entrySet()) {
        e.getValue().copyTo(tmp, w);
        w.write(' ');
        w.write(e.getKey());
        w.write('\n');
      }

      w.write('\n');
      w.flush();
      packWriter.writePack(monitor, monitor, os);
    } finally {
      packWriter.release();
    }
  }
View Full Code Here

Examples of org.eclipse.jgit.storage.pack.PackWriter

    }

    PackConfig cfg = packConfig;
    if (cfg == null)
      cfg = new PackConfig(db);
    final PackWriter pw = new PackWriter(cfg, walk.getObjectReader());
    try {
      pw.setUseCachedPacks(true);
      pw.setDeltaBaseAsOffset(options.contains(OPTION_OFS_DELTA));
      pw.setThin(options.contains(OPTION_THIN_PACK));
      pw.preparePack(pm, wantAll, commonBase);
      if (options.contains(OPTION_INCLUDE_TAG)) {
        for (final Ref r : refs.values()) {
          final RevObject o;
          try {
            o = walk.parseAny(r.getObjectId());
          } catch (IOException e) {
            continue;
          }
          if (o.has(WANT) || !(o instanceof RevTag))
            continue;
          final RevTag t = (RevTag) o;
          if (!pw.willInclude(t) && pw.willInclude(t.getObject()))
            pw.addObject(t);
        }
      }

      pw.writePack(pm, NullProgressMonitor.INSTANCE, packOut);
      packOut.flush();

      if (msgOut != null) {
        String msg = pw.getStatistics().getMessage() + '\n';
        msgOut.write(Constants.encode(msg));
        msgOut.flush();
      }

    } finally {
      pw.release();
    }

    if (sideband)
      pckOut.end();
  }
View Full Code Here

Examples of org.eclipse.jgit.storage.pack.PackWriter

    }

    PackConfig cfg = packConfig;
    if (cfg == null)
      cfg = new PackConfig(db);
    final PackWriter pw = new PackWriter(cfg, walk.getObjectReader());
    try {
      pw.setUseCachedPacks(true);
      pw.setReuseDeltaCommits(true);
      pw.setDeltaBaseAsOffset(options.contains(OPTION_OFS_DELTA));
      pw.setThin(options.contains(OPTION_THIN_PACK));
      pw.setReuseValidatingObjects(false);

      if (commonBase.isEmpty()) {
        Set<ObjectId> tagTargets = new HashSet<ObjectId>();
        for (Ref ref : refs.values()) {
          if (ref.getPeeledObjectId() != null)
            tagTargets.add(ref.getPeeledObjectId());
          else if (ref.getObjectId() == null)
            continue;
          else if (ref.getName().startsWith(Constants.R_HEADS))
            tagTargets.add(ref.getObjectId());
        }
        pw.setTagTargets(tagTargets);
      }

      RevWalk rw = walk;
      if (wantAll.isEmpty()) {
        pw.preparePack(pm, wantIds, commonBase);
      } else {
        walk.reset();

        ObjectWalk ow = walk.toObjectWalkWithSameObjects();
        pw.preparePack(pm, ow, wantAll, commonBase);
        rw = ow;
      }

      if (options.contains(OPTION_INCLUDE_TAG)) {
        for (Ref ref : refs.values()) {
          ObjectId objectId = ref.getObjectId();

          // If the object was already requested, skip it.
          if (wantAll.isEmpty()) {
            if (wantIds.contains(objectId))
              continue;
          } else {
            RevObject obj = rw.lookupOrNull(objectId);
            if (obj != null && obj.has(WANT))
              continue;
          }

          if (!ref.isPeeled())
            ref = db.peel(ref);

          ObjectId peeledId = ref.getPeeledObjectId();
          if (peeledId == null)
            continue;

          objectId = ref.getObjectId();
          if (pw.willInclude(peeledId) && !pw.willInclude(objectId))
            pw.addObject(rw.parseAny(objectId));
        }
      }

      pw.writePack(pm, NullProgressMonitor.INSTANCE, packOut);
      statistics = pw.getStatistics();

      if (msgOut != null) {
        String msg = pw.getStatistics().getMessage() + '\n';
        msgOut.write(Constants.encode(msg));
        msgOut.flush();
      }

    } finally {
      pw.release();
    }

    if (sideband)
      pckOut.end();
View Full Code Here

Examples of org.eclipse.jgit.storage.pack.PackWriter

    }

    PackConfig cfg = packConfig;
    if (cfg == null)
      cfg = new PackConfig(db);
    final PackWriter pw = new PackWriter(cfg, walk.getObjectReader());
    try {
      pw.setUseCachedPacks(true);
      pw.setReuseDeltaCommits(true);
      pw.setDeltaBaseAsOffset(options.contains(OPTION_OFS_DELTA));
      pw.setThin(options.contains(OPTION_THIN_PACK));
      pw.setReuseValidatingObjects(false);

      if (commonBase.isEmpty() && refs != null) {
        Set<ObjectId> tagTargets = new HashSet<ObjectId>();
        for (Ref ref : refs.values()) {
          if (ref.getPeeledObjectId() != null)
            tagTargets.add(ref.getPeeledObjectId());
          else if (ref.getObjectId() == null)
            continue;
          else if (ref.getName().startsWith(Constants.R_HEADS))
            tagTargets.add(ref.getObjectId());
        }
        pw.setTagTargets(tagTargets);
      }

      if (depth > 0)
        pw.setShallowPack(depth, unshallowCommits);

      RevWalk rw = walk;
      if (wantAll.isEmpty()) {
        pw.preparePack(pm, wantIds, commonBase);
      } else {
        walk.reset();

        ObjectWalk ow = walk.toObjectWalkWithSameObjects();
        pw.preparePack(pm, ow, wantAll, commonBase);
        rw = ow;
      }

      if (options.contains(OPTION_INCLUDE_TAG) && refs != null) {
        for (Ref ref : refs.values()) {
          ObjectId objectId = ref.getObjectId();

          // If the object was already requested, skip it.
          if (wantAll.isEmpty()) {
            if (wantIds.contains(objectId))
              continue;
          } else {
            RevObject obj = rw.lookupOrNull(objectId);
            if (obj != null && obj.has(WANT))
              continue;
          }

          if (!ref.isPeeled())
            ref = db.peel(ref);

          ObjectId peeledId = ref.getPeeledObjectId();
          if (peeledId == null)
            continue;

          objectId = ref.getObjectId();
          if (pw.willInclude(peeledId) && !pw.willInclude(objectId))
            pw.addObject(rw.parseAny(objectId));
        }
      }

      pw.writePack(pm, NullProgressMonitor.INSTANCE, packOut);
      statistics = pw.getStatistics();

      if (msgOut != null) {
        String msg = pw.getStatistics().getMessage() + '\n';
        msgOut.write(Constants.encode(msg));
        msgOut.flush();
      }

    } finally {
      pw.release();
    }

    if (sideband)
      pckOut.end();
View Full Code Here

Examples of org.eclipse.jgit.storage.pack.PackWriter

  private void sendpack(final List<RemoteRefUpdate> updates,
      final ProgressMonitor monitor) throws TransportException {
    String pathPack = null;
    String pathIdx = null;

    final PackWriter writer = new PackWriter(transport.getPackConfig(),
        local.newObjectReader());
    try {
      final Set<ObjectId> need = new HashSet<ObjectId>();
      final Set<ObjectId> have = new HashSet<ObjectId>();
      for (final RemoteRefUpdate r : updates)
        need.add(r.getNewObjectId());
      for (final Ref r : getRefs()) {
        have.add(r.getObjectId());
        if (r.getPeeledObjectId() != null)
          have.add(r.getPeeledObjectId());
      }
      writer.preparePack(monitor, need, have);

      // We don't have to continue further if the pack will
      // be an empty pack, as the remote has all objects it
      // needs to complete this change.
      //
      if (writer.getObjectCount() == 0)
        return;

      packNames = new LinkedHashMap<String, String>();
      for (final String n : dest.getPackNames())
        packNames.put(n, n);

      final String base = "pack-" + writer.computeName().name();
      final String packName = base + ".pack";
      pathPack = "pack/" + packName;
      pathIdx = "pack/" + base + ".idx";

      if (packNames.remove(packName) != null) {
        // The remote already contains this pack. We should
        // remove the index before overwriting to prevent bad
        // offsets from appearing to clients.
        //
        dest.writeInfoPacks(packNames.keySet());
        dest.deleteFile(pathIdx);
      }

      // Write the pack file, then the index, as readers look the
      // other direction (index, then pack file).
      //
      final String wt = "Put " + base.substring(0, 12);
      OutputStream os = dest.writeFile(pathPack, monitor, wt + "..pack");
      try {
        os = new BufferedOutputStream(os);
        writer.writePack(monitor, monitor, os);
      } finally {
        os.close();
      }

      os = dest.writeFile(pathIdx, monitor, wt + "..idx");
      try {
        os = new BufferedOutputStream(os);
        writer.writeIndex(os);
      } finally {
        os.close();
      }

      // Record the pack at the start of the pack info list. This
      // way clients are likely to consult the newest pack first,
      // and discover the most recent objects there.
      //
      final ArrayList<String> infoPacks = new ArrayList<String>();
      infoPacks.add(packName);
      infoPacks.addAll(packNames.keySet());
      dest.writeInfoPacks(infoPacks);

    } catch (IOException err) {
      safeDelete(pathIdx);
      safeDelete(pathPack);

      throw new TransportException(uri, JGitText.get().cannotStoreObjects, err);
    } finally {
      writer.release();
    }
  }
View Full Code Here

Examples of org.eclipse.jgit.storage.pack.PackWriter

    }

    PackConfig cfg = packConfig;
    if (cfg == null)
      cfg = new PackConfig(db);
    final PackWriter pw = new PackWriter(cfg, walk.getObjectReader());
    try {
      pw.setDeltaBaseAsOffset(options.contains(OPTION_OFS_DELTA));
      pw.setThin(options.contains(OPTION_THIN_PACK));
      pw.preparePack(pm, wantAll, commonBase);
      if (options.contains(OPTION_INCLUDE_TAG)) {
        for (final Ref r : refs.values()) {
          final RevObject o;
          try {
            o = walk.parseAny(r.getObjectId());
          } catch (IOException e) {
            continue;
          }
          if (o.has(WANT) || !(o instanceof RevTag))
            continue;
          final RevTag t = (RevTag) o;
          if (!pw.willInclude(t) && pw.willInclude(t.getObject()))
            pw.addObject(t);
        }
      }
      pw.writePack(pm, NullProgressMonitor.INSTANCE, packOut);
    } finally {
      pw.release();
    }
    packOut.flush();

    if (sideband)
      pckOut.end();
View Full Code Here

Examples of org.eclipse.jgit.storage.pack.PackWriter

    if (db.getObjectDatabase() instanceof ObjectDirectory) {
      ObjectDirectory odb = (ObjectDirectory) db.getObjectDatabase();
      NullProgressMonitor m = NullProgressMonitor.INSTANCE;

      final File pack, idx;
      PackWriter pw = new PackWriter(db);
      try {
        Set<ObjectId> all = new HashSet<ObjectId>();
        for (Ref r : db.getAllRefs().values())
          all.add(r.getObjectId());
        pw.preparePack(m, all, Collections.<ObjectId> emptySet());

        final ObjectId name = pw.computeName();
        OutputStream out;

        pack = nameFor(odb, name, ".pack");
        out = new BufferedOutputStream(new FileOutputStream(pack));
        try {
          pw.writePack(m, m, out);
        } finally {
          out.close();
        }
        pack.setReadOnly();

        idx = nameFor(odb, name, ".idx");
        out = new BufferedOutputStream(new FileOutputStream(idx));
        try {
          pw.writeIndex(out);
        } finally {
          out.close();
        }
        idx.setReadOnly();
      } finally {
        pw.release();
      }

      odb.openPack(pack, idx);
      updateServerInfo();
      prunePacked(odb);
View Full Code Here

Examples of org.eclipse.jgit.storage.pack.PackWriter

      throws IOException, MissingObjectException,
      StoredObjectRepresentationNotAvailableException {
    ObjectReuseAsIs asis = (ObjectReuseAsIs) reader;
    ObjectToPack target = asis.newObjectToPack(obj);

    PackWriter pw = new PackWriter(reader) {
      @Override
      public void select(ObjectToPack otp, StoredObjectRepresentation next) {
        otp.select(next);
      }
    };
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.