Examples of DirCacheBuilder


Examples of org.eclipse.jgit.dircache.DirCacheBuilder

   */
  private static DirCache createIndex(Repository repo, ObjectId headId,
      Collection<ReceiveCommand> commands) throws IOException {

    DirCache inCoreIndex = DirCache.newInCore();
    DirCacheBuilder dcBuilder = inCoreIndex.builder();
    ObjectInserter inserter = repo.newObjectInserter();

    long now = System.currentTimeMillis();
    Set<String> ignorePaths = new TreeSet<String>();
    try {
      // add receive commands to the temporary index
      for (ReceiveCommand command : commands) {
        // use the ref names as the path names
        String path = command.getRefName();
        ignorePaths.add(path);

        StringBuilder change = new StringBuilder();
        change.append(command.getType().name()).append(' ');
        switch (command.getType()) {
        case CREATE:
          change.append(ObjectId.zeroId().getName());
          change.append(' ');
          change.append(command.getNewId().getName());
          break;
        case UPDATE:
        case UPDATE_NONFASTFORWARD:
          change.append(command.getOldId().getName());
          change.append(' ');
          change.append(command.getNewId().getName());
          break;
        case DELETE:
          change = null;
          break;
        }
        if (change == null) {
          // ref deleted
          continue;
        }
        String content = change.toString();

        // create an index entry for this attachment
        final DirCacheEntry dcEntry = new DirCacheEntry(path);
        dcEntry.setLength(content.length());
        dcEntry.setLastModified(now);
        dcEntry.setFileMode(FileMode.REGULAR_FILE);

        // insert object
        dcEntry.setObjectId(inserter.insert(org.eclipse.jgit.lib.Constants.OBJ_BLOB, content.getBytes("UTF-8")));

        // add to temporary in-core index
        dcBuilder.add(dcEntry);
      }

      // Traverse HEAD to add all other paths
      TreeWalk treeWalk = new TreeWalk(repo);
      int hIdx = -1;
      if (headId != null)
        hIdx = treeWalk.addTree(new RevWalk(repo).parseTree(headId));
      treeWalk.setRecursive(true);

      while (treeWalk.next()) {
        String path = treeWalk.getPathString();
        CanonicalTreeParser hTree = null;
        if (hIdx != -1)
          hTree = treeWalk.getTree(hIdx, CanonicalTreeParser.class);
        if (!ignorePaths.contains(path)) {
          // add entries from HEAD for all other paths
          if (hTree != null) {
            // create a new DirCacheEntry with data retrieved from
            // HEAD
            final DirCacheEntry dcEntry = new DirCacheEntry(path);
            dcEntry.setObjectId(hTree.getEntryObjectId());
            dcEntry.setFileMode(hTree.getEntryFileMode());

            // add to temporary in-core index
            dcBuilder.add(dcEntry);
          }
        }
      }

      // release the treewalk
      treeWalk.release();

      // finish temporary in-core index used for this commit
      dcBuilder.finish();
    } finally {
      inserter.release();
    }
    return inCoreIndex;
  }
View Full Code Here

Examples of org.eclipse.jgit.dircache.DirCacheBuilder

    if (getTicketsBranch(db) == null) {
      createTicketsBranch(db);
    }

    DirCache newIndex = DirCache.newInCore();
    DirCacheBuilder builder = newIndex.builder();
    ObjectInserter inserter = db.newObjectInserter();

    try {
      // create an index entry for the revised index
      final DirCacheEntry idIndexEntry = new DirCacheEntry(file);
      idIndexEntry.setLength(content.length());
      idIndexEntry.setLastModified(System.currentTimeMillis());
      idIndexEntry.setFileMode(FileMode.REGULAR_FILE);

      // insert new ticket index
      idIndexEntry.setObjectId(inserter.insert(org.eclipse.jgit.lib.Constants.OBJ_BLOB,
          content.getBytes(Constants.ENCODING)));

      // add to temporary in-core index
      builder.add(idIndexEntry);

      Set<String> ignorePaths = new HashSet<String>();
      ignorePaths.add(file);

      for (DirCacheEntry entry : getTreeEntries(db, ignorePaths)) {
        builder.add(entry);
      }

      // finish temporary in-core index used for this commit
      builder.finish();

      // commit the change
      commitIndex(db, newIndex, createdBy, msg);

    } catch (ConcurrentRefUpdateException e) {
View Full Code Here

Examples of org.eclipse.jgit.dircache.DirCacheBuilder

      try {
        ObjectId treeId = db.resolve(BRANCH + "^{tree}");

        // Create the in-memory index of the new/updated ticket
        DirCache index = DirCache.newInCore();
        DirCacheBuilder builder = index.builder();

        // Traverse HEAD to add all other paths
        treeWalk = new TreeWalk(db);
        int hIdx = -1;
        if (treeId != null) {
          hIdx = treeWalk.addTree(treeId);
        }
        treeWalk.setRecursive(true);
        while (treeWalk.next()) {
          String path = treeWalk.getPathString();
          CanonicalTreeParser hTree = null;
          if (hIdx != -1) {
            hTree = treeWalk.getTree(hIdx, CanonicalTreeParser.class);
          }
          if (!path.startsWith(ticketPath)) {
            // add entries from HEAD for all other paths
            if (hTree != null) {
              final DirCacheEntry entry = new DirCacheEntry(path);
              entry.setObjectId(hTree.getEntryObjectId());
              entry.setFileMode(hTree.getEntryFileMode());

              // add to temporary in-core index
              builder.add(entry);
            }
          }
        }

        // finish temporary in-core index used for this commit
        builder.finish();

        success = commitIndex(db, index, deletedBy, "- " + ticket.number);

      } catch (Throwable t) {
        log.error(MessageFormat.format("Failed to delete ticket {0,number,0} from {1}",
View Full Code Here

Examples of org.eclipse.jgit.dircache.DirCacheBuilder

  private DirCache createIndex(Repository db, long ticketId, Change change)
      throws IOException, ClassNotFoundException, NoSuchFieldException {

    String ticketPath = toTicketPath(ticketId);
    DirCache newIndex = DirCache.newInCore();
    DirCacheBuilder builder = newIndex.builder();
    ObjectInserter inserter = db.newObjectInserter();

    Set<String> ignorePaths = new TreeSet<String>();
    try {
      // create/update the journal
      // exclude the attachment content
      List<Change> changes = getJournal(db, ticketId);
      changes.add(change);
      String journal = TicketSerializer.serializeJournal(changes).trim();

      byte [] journalBytes = journal.getBytes(Constants.ENCODING);
      String journalPath = ticketPath + "/" + JOURNAL;
      final DirCacheEntry journalEntry = new DirCacheEntry(journalPath);
      journalEntry.setLength(journalBytes.length);
      journalEntry.setLastModified(change.date.getTime());
      journalEntry.setFileMode(FileMode.REGULAR_FILE);
      journalEntry.setObjectId(inserter.insert(org.eclipse.jgit.lib.Constants.OBJ_BLOB, journalBytes));

      // add journal to index
      builder.add(journalEntry);
      ignorePaths.add(journalEntry.getPathString());

      // Add any attachments to the index
      if (change.hasAttachments()) {
        for (Attachment attachment : change.attachments) {
          // build a path name for the attachment and mark as ignored
          String path = toAttachmentPath(ticketId, attachment.name);
          ignorePaths.add(path);

          // create an index entry for this attachment
          final DirCacheEntry entry = new DirCacheEntry(path);
          entry.setLength(attachment.content.length);
          entry.setLastModified(change.date.getTime());
          entry.setFileMode(FileMode.REGULAR_FILE);

          // insert object
          entry.setObjectId(inserter.insert(org.eclipse.jgit.lib.Constants.OBJ_BLOB, attachment.content));

          // add to temporary in-core index
          builder.add(entry);
        }
      }

      for (DirCacheEntry entry : getTreeEntries(db, ignorePaths)) {
        builder.add(entry);
      }

      // finish the index
      builder.finish();
    } finally {
      inserter.release();
    }
    return newIndex;
  }
View Full Code Here

Examples of org.eclipse.jgit.dircache.DirCacheBuilder

    }

    CommitBuilder(CommitBuilder prior) throws Exception {
      branch = prior.branch;

      DirCacheBuilder b = tree.builder();
      for (int i = 0; i < prior.tree.getEntryCount(); i++)
        b.add(prior.tree.getEntry(i));
      b.finish();

      parents.add(prior.create());
    }
View Full Code Here

Examples of org.eclipse.jgit.dircache.DirCacheBuilder

      parents.add(prior.create());
    }

    public CommitBuilder parent(RevCommit p) throws Exception {
      if (parents.isEmpty()) {
        DirCacheBuilder b = tree.builder();
        parseBody(p);
        b.addTree(new byte[0], DirCacheEntry.STAGE_0, pool
            .getObjectReader(), p.getTree());
        b.finish();
      }
      parents.add(p);
      return this;
    }
View Full Code Here

Examples of org.eclipse.jgit.dircache.DirCacheBuilder

   * @throws IOException
   */
  protected void resetIndex(FileTreeIterator treeItr)
      throws FileNotFoundException, IOException {
    ObjectInserter inserter = db.newObjectInserter();
    DirCacheBuilder builder = db.lockDirCache().builder();
    DirCacheEntry dce;

    while (!treeItr.eof()) {
      long len = treeItr.getEntryLength();

      dce = new DirCacheEntry(treeItr.getEntryPathString());
      dce.setFileMode(treeItr.getEntryFileMode());
      dce.setLastModified(treeItr.getEntryLastModified());
      dce.setLength((int) len);
      FileInputStream in = new FileInputStream(treeItr.getEntryFile());
      dce.setObjectId(inserter.insert(Constants.OBJ_BLOB, len, in));
      in.close();
      builder.add(dce);
      treeItr.next(1);
    }
    builder.commit();
    inserter.flush();
    inserter.release();
  }
View Full Code Here

Examples of org.eclipse.jgit.dircache.DirCacheBuilder

    checkCallable();
    DirCache dc = null;

    try {
      dc = repo.lockDirCache();
      DirCacheBuilder builder = dc.builder();
      final TreeWalk tw = new TreeWalk(repo);
      tw.reset(); // drop the first empty tree, which we do not need here
      tw.setRecursive(true);
      tw.setFilter(PathFilterGroup.createFromStrings(filepatterns));
      tw.addTree(new DirCacheBuildIterator(builder));

      while (tw.next()) {
        if (!cached) {
          final FileMode mode = tw.getFileMode(0);
          if (mode.getObjectType() == Constants.OBJ_BLOB) {
            final File path = new File(repo.getWorkTree(),
                tw.getPathString());
            // Deleting a blob is simply a matter of removing
            // the file or symlink named by the tree entry.
            delete(path);
          }
        }
      }
      builder.commit();
      setCallable(false);
    } catch (IOException e) {
      throw new JGitInternalException(
          JGitText.get().exceptionCaughtDuringExecutionOfRmCommand, e);
    } finally {
View Full Code Here

Examples of org.eclipse.jgit.dircache.DirCacheBuilder

  }

  private ObjectId createTree(String... paths) throws IOException {
    final ObjectInserter odi = db.newObjectInserter();
    final DirCache dc = db.readDirCache();
    final DirCacheBuilder builder = dc.builder();
    for (String path : paths) {
      DirCacheEntry entry = createEntry(path, FileMode.REGULAR_FILE);
      builder.add(entry);
    }
    builder.finish();
    final ObjectId treeId = dc.writeTree(odi);
    odi.flush();
    return treeId;
  }
View Full Code Here

Examples of org.eclipse.jgit.dircache.DirCacheBuilder

        // Commit untracked changes
        ObjectId untrackedCommit = null;
        if (!untracked.isEmpty()) {
          DirCache untrackedDirCache = DirCache.newInCore();
          DirCacheBuilder untrackedBuilder = untrackedDirCache
              .builder();
          for (DirCacheEntry entry : untracked)
            untrackedBuilder.add(entry);
          untrackedBuilder.finish();

          builder.setParentIds(new ObjectId[0]);
          builder.setTreeId(untrackedDirCache.writeTree(inserter));
          builder.setMessage(MessageFormat.format(MSG_UNTRACKED,
              branch, headCommit.abbreviate(7).name(),
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.