Examples of PackWriter


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

  /**
   * Test constructor for exceptions, default settings, initialization.
   */
  public void testContructor() {
    writer = new PackWriter(config, db.newObjectReader());
    assertEquals(false, writer.isDeltaBaseAsOffset());
    assertEquals(true, config.isReuseDeltas());
    assertEquals(true, config.isReuseObjects());
    assertEquals(0, writer.getObjectsNumber());
  }
View Full Code Here

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

    config.setDeltaBaseAsOffset(false);
    assertEquals(false, config.isReuseDeltas());
    assertEquals(false, config.isReuseObjects());
    assertEquals(false, config.isDeltaBaseAsOffset());

    writer = new PackWriter(config, db.newObjectReader());
    writer.setDeltaBaseAsOffset(true);
    assertEquals(true, writer.isDeltaBaseAsOffset());
    assertEquals(false, config.isDeltaBaseAsOffset());
  }
View Full Code Here

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

  private void createVerifyOpenPack(final Collection<ObjectId> interestings,
      final Collection<ObjectId> uninterestings, final boolean thin,
      final boolean ignoreMissingUninteresting)
      throws MissingObjectException, IOException {
    NullProgressMonitor m = NullProgressMonitor.INSTANCE;
    writer = new PackWriter(config, db.newObjectReader());
    writer.setThin(thin);
    writer.setIgnoreMissingUninteresting(ignoreMissingUninteresting);
    writer.preparePack(m, interestings, uninterestings);
    writer.writePack(m, m, os);
    writer.release();
View Full Code Here

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

  }

  private void createVerifyOpenPack(final Iterator<RevObject> objectSource)
      throws MissingObjectException, IOException {
    NullProgressMonitor m = NullProgressMonitor.INSTANCE;
    writer = new PackWriter(config, db.newObjectReader());
    writer.preparePack(objectSource);
    writer.writePack(m, m, os);
    writer.release();
    verifyOpenPack(false);
  }
View Full Code Here

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.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

    // different pack under the same file name is partially broken. We
    // should also have a different file name because the list of objects
    // within the pack has been modified.
    //
    final RevObject o2 = writeBlob(eden, "o2");
    final PackWriter pw = new PackWriter(eden);
    pw.addObject(o2);
    pw.addObject(o1);
    write(out1, pw);
    pw.release();

    // Try the old name, then the new name. The old name should cause the
    // pack to reload when it opens and the index and pack mismatch.
    //
    assertEquals(o1.name(), parse(o1).name());
View Full Code Here

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

    return new RevWalk(db).parseAny(id);
  }

  private File[] pack(final Repository src, final RevObject... list)
      throws IOException {
    final PackWriter pw = new PackWriter(src);
    for (final RevObject o : list) {
      pw.addObject(o);
    }

    final ObjectId name = pw.computeName();
    final File packFile = fullPackFileName(name, ".pack");
    final File idxFile = fullPackFileName(name, ".idx");
    final File[] files = new File[] { packFile, idxFile };
    write(files, pw);
    pw.release();
    return files;
  }
View Full Code Here

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

  private PackFile writePack(Set<? extends ObjectId> want,
      Set<? extends ObjectId> have, Set<ObjectId> tagTargets,
      List<PackIndex> excludeObjects) throws IOException {
    File tmpPack = null;
    File tmpIdx = null;
    PackWriter pw = new PackWriter(repo);
    try {
      // prepare the PackWriter
      pw.setDeltaBaseAsOffset(true);
      pw.setReuseDeltaCommits(false);
      if (tagTargets != null)
        pw.setTagTargets(tagTargets);
      if (excludeObjects != null)
        for (PackIndex idx : excludeObjects)
          pw.excludeObjects(idx);
      pw.preparePack(pm, want, have);
      if (pw.getObjectCount() == 0)
        return null;

      // create temporary files
      String id = pw.computeName().getName();
      File packdir = new File(repo.getObjectsDirectory(), "pack");
      tmpPack = File.createTempFile("gc_", ".pack_tmp", packdir);
      tmpIdx = new File(packdir, tmpPack.getName().substring(0,
          tmpPack.getName().lastIndexOf('.'))
          + ".idx_tmp");

      if (!tmpIdx.createNewFile())
        throw new IOException(MessageFormat.format(
            JGitText.get().cannotCreateIndexfile, tmpIdx.getPath()));

      // write the packfile
      FileChannel channel = new FileOutputStream(tmpPack).getChannel();
      OutputStream channelStream = Channels.newOutputStream(channel);
      try {
        pw.writePack(pm, pm, channelStream);
      } finally {
        channel.force(true);
        channelStream.close();
        channel.close();
      }

      // write the packindex
      FileChannel idxChannel = new FileOutputStream(tmpIdx).getChannel();
      OutputStream idxStream = Channels.newOutputStream(idxChannel);
      try {
        pw.writeIndex(idxStream);
      } finally {
        idxChannel.force(true);
        idxStream.close();
        idxChannel.close();
      }

      // rename the temporary files to real files
      File realPack = nameFor(id, ".pack");
      tmpPack.setReadOnly();
      File realIdx = nameFor(id, ".idx");
      realIdx.setReadOnly();
      boolean delete = true;
      try {
        if (!tmpPack.renameTo(realPack))
          return null;
        delete = false;
        if (!tmpIdx.renameTo(realIdx)) {
          File newIdx = new File(realIdx.getParentFile(),
              realIdx.getName() + ".new");
          if (!tmpIdx.renameTo(newIdx))
            newIdx = tmpIdx;
          throw new IOException(MessageFormat.format(
              JGitText.get().panicCantRenameIndexFile, newIdx,
              realIdx));
        }
      } finally {
        if (delete && tmpPack.exists())
          tmpPack.delete();
        if (delete && tmpIdx.exists())
          tmpIdx.delete();
      }
      return repo.getObjectDatabase().openPack(realPack, realIdx);
    } finally {
      pw.release();
      if (tmpPack != null && tmpPack.exists())
        tmpPack.delete();
      if (tmpIdx != null && tmpIdx.exists())
        tmpIdx.delete();
    }
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.setDeltaBaseAsOffset(true);
      packWriter.setThin(exc.size() > 0);
      packWriter.setReuseValidatingObjects(false);
      if (exc.size() == 0)
        packWriter.setTagTargets(tagTargets);
      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

  private void writePack(final Map<String, RemoteRefUpdate> refUpdates,
      final ProgressMonitor monitor) throws IOException {
    Set<ObjectId> remoteObjects = new HashSet<ObjectId>();
    Set<ObjectId> newObjects = new HashSet<ObjectId>();

    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.setReuseValidatingObjects(false);
      writer.setDeltaBaseAsOffset(capableOfsDelta);
      writer.preparePack(monitor, newObjects, remoteObjects);
      writer.writePack(monitor, monitor, out);
    } finally {
      writer.release();
    }
    packTransferTime = writer.getStatistics().getTimeWriting();
  }
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.