Package org.eclipse.jgit.storage.pack

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 SafeBufferedOutputStream(os);
        writer.writePack(monitor, monitor, os);
      } finally {
        os.close();
      }

      os = dest.writeFile(pathIdx, monitor, wt + "..idx");
      try {
        os = new SafeBufferedOutputStream(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


    }

    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

      pc.setIndexVersion(2);
      pc.setDeltaCompress(false);
      pc.setReuseDeltas(true);
      pc.setReuseObjects(true);

      PackWriter pw = new PackWriter(pc, ctx);
      try {
        pw.setDeltaBaseAsOffset(true);
        pw.setReuseDeltaCommits(false);

        addObjectsToPack(pw, ctx, pm);
        if (pw.getObjectCount() == 0)
          return;

        boolean rollback = true;
        DfsPackDescription pack = objdb.newPack(COMPACT);
        try {
          writePack(objdb, pack, pw, pm);
          writeIndex(objdb, pack, pw);

          PackWriter.Statistics stats = pw.getStatistics();
          pw.release();
          pw = null;

          pack.setPackStats(stats);
          objdb.commitPack(Collections.singletonList(pack), toPrune());
          newPacks.add(pack);
          newStats.add(stats);
          rollback = false;
        } finally {
          if (rollback)
            objdb.rollbackPack(Collections.singletonList(pack));
        }
      } finally {
        if (pw != null)
          pw.release();
      }
    } finally {
      ctx.release();
    }
  }
View Full Code Here

  private void packHeads(ProgressMonitor pm) throws IOException {
    if (allHeads.isEmpty())
      return;

    PackWriter pw = newPackWriter();
    try {
      pw.preparePack(pm, allHeads, Collections.<ObjectId> emptySet());
      if (0 < pw.getObjectCount())
        writePack(GC, pw, pm).setTips(allHeads);
    } finally {
      pw.release();
    }
  }
View Full Code Here

  private void packRest(ProgressMonitor pm) throws IOException {
    if (nonHeads.isEmpty() || objectsPacked == getObjectsBefore())
      return;

    PackWriter pw = newPackWriter();
    try {
      for (DfsPackFile pack : newPackList)
        pw.excludeObjects(pack.getPackIndex(ctx));
      pw.preparePack(pm, nonHeads, allHeads);
      if (0 < pw.getObjectCount())
        writePack(GC, pw, pm);
    } finally {
      pw.release();
    }
  }
View Full Code Here

    // TODO(sop) This is ugly. The garbage pack needs to be deleted.
    List<PackIndex> newIdx = new ArrayList<PackIndex>(newPackList.size());
    for (DfsPackFile pack : newPackList)
      newIdx.add(pack.getPackIndex(ctx));

    PackWriter pw = newPackWriter();
    try {
      RevWalk pool = new RevWalk(ctx);
      for (DfsPackFile oldPack : packsBefore) {
        PackIndex oldIdx = oldPack.getPackIndex(ctx);
        pm.beginTask("Finding garbage", (int) oldIdx.getObjectCount());
        for (PackIndex.MutableEntry ent : oldIdx) {
          pm.update(1);
          ObjectId id = ent.toObjectId();
          if (pool.lookupOrNull(id) != null || anyIndexHas(newIdx, id))
            continue;

          int type = oldPack.getObjectType(ctx, ent.getOffset());
          pw.addObject(pool.lookupAny(id, type));
        }
        pm.endTask();
      }
      if (0 < pw.getObjectCount())
        writePack(UNREACHABLE_GARBAGE, pw, pm);
    } finally {
      pw.release();
    }
  }
View Full Code Here

    }
    return objectsBefore;
  }

  private PackWriter newPackWriter() {
    PackWriter pw = new PackWriter(packConfig, ctx);
    pw.setDeltaBaseAsOffset(true);
    pw.setReuseDeltaCommits(false);
    pw.setTagTargets(tagTargets);
    return pw;
  }
View Full Code Here

      pc.setIndexVersion(2);
      pc.setDeltaCompress(false);
      pc.setReuseDeltas(true);
      pc.setReuseObjects(true);

      PackWriter pw = new PackWriter(pc, ctx);
      try {
        pw.setDeltaBaseAsOffset(true);
        pw.setReuseDeltaCommits(false);

        addObjectsToPack(pw, ctx, pm);
        if (pw.getObjectCount() == 0)
          return;

        boolean rollback = true;
        DfsPackDescription pack = objdb.newPack(COMPACT);
        try {
          writePack(objdb, pack, pw, pm);
          writeIndex(objdb, pack, pw);

          PackWriter.Statistics stats = pw.getStatistics();
          pw.release();
          pw = null;

          pack.setPackStats(stats);
          objdb.commitPack(Collections.singletonList(pack), toPrune());
          newPacks.add(pack);
          newStats.add(stats);
          rollback = false;
        } finally {
          if (rollback)
            objdb.rollbackPack(Collections.singletonList(pack));
        }
      } finally {
        if (pw != null)
          pw.release();
      }
    } finally {
      ctx.release();
    }
  }
View Full Code Here

  private void packHeads(ProgressMonitor pm) throws IOException {
    if (allHeads.isEmpty())
      return;

    PackWriter pw = newPackWriter();
    try {
      pw.preparePack(pm, allHeads, Collections.<ObjectId> emptySet());
      if (0 < pw.getObjectCount())
        writePack(GC, pw, pm).setTips(allHeads);
    } finally {
      pw.release();
    }
  }
View Full Code Here

  private void packRest(ProgressMonitor pm) throws IOException {
    if (nonHeads.isEmpty() || objectsPacked == getObjectsBefore())
      return;

    PackWriter pw = newPackWriter();
    try {
      for (PackWriter.ObjectIdSet packedObjs : newPackObj)
        pw.excludeObjects(packedObjs);
      pw.preparePack(pm, nonHeads, allHeads);
      if (0 < pw.getObjectCount())
        writePack(GC, pw, pm);
    } finally {
      pw.release();
    }
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.storage.pack.PackWriter

Copyright © 2018 www.massapicom. 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.