Package org.eclipse.jgit.dircache

Examples of org.eclipse.jgit.dircache.DirCacheEntry


      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);
        }
      }
View Full Code Here


          hTree = tw.getTree(hIdx, CanonicalTreeParser.class);
        }
        if (!ignorePaths.contains(path)) {
          // add all other tree entries
          if (hTree != null) {
            final DirCacheEntry entry = new DirCacheEntry(path);
            entry.setObjectId(hTree.getEntryObjectId());
            entry.setFileMode(hTree.getEntryFileMode());
            list.add(entry);
          }
        }
      }
    } finally {
View Full Code Here

      IOException {
    DirCache dc = git.getRepository().lockDirCache();
    ObjectReader r = git.getRepository().getObjectDatabase().newReader();
    try {
      for (int i = 0; i < dc.getEntryCount(); ++i) {
        DirCacheEntry entry = dc.getEntry(i);
        if (entry.getLength() > 0)
          assertEquals(entry.getLength(), r.getObjectSize(
              entry.getObjectId(), ObjectReader.OBJ_ANY));
      }
    } finally {
      dc.unlock();
      r.release();
    }
View Full Code Here

  }

  private void assertStageOneToThree(String name) throws Exception {
    DirCache cache = DirCache.read(db.getIndexFile(), db.getFS());
    int i = cache.findEntry(name);
    DirCacheEntry stage1 = cache.getEntry(i);
    DirCacheEntry stage2 = cache.getEntry(i + 1);
    DirCacheEntry stage3 = cache.getEntry(i + 2);

    assertEquals(DirCacheEntry.STAGE_1, stage1.getStage());
    assertEquals(DirCacheEntry.STAGE_2, stage2.getStage());
    assertEquals(DirCacheEntry.STAGE_3, stage3.getStage());
  }
View Full Code Here

      if (i != null) {
        if (FileMode.TREE.equals(tw.getRawMode(tree))) {
          builder.addTree(tw.getRawPath(), stage, reader, tw
              .getObjectId(tree));
        } else {
          final DirCacheEntry e;

          e = new DirCacheEntry(tw.getRawPath(), stage);
          e.setObjectIdFromRaw(i.idBuffer(), i.idOffset());
          e.setFileMode(tw.getFileMode(tree));
          builder.add(e);
        }
      }
    }
View Full Code Here

        timeStamps.add(Long.valueOf(dc.getEntry(i).getLastModified()));
    }

    // iterate again, now produce the result string
    for (int i=0; i<dc.getEntryCount(); ++i) {
      DirCacheEntry entry = dc.getEntry(i);
      sb.append("["+entry.getPathString()+", mode:" + entry.getFileMode());
      int stage = entry.getStage();
      if (stage != 0)
        sb.append(", stage:" + stage);
      if (0 != (includedOptions & MOD_TIME)) {
        sb.append(", time:t"+
          timeStamps.headSet(Long.valueOf(entry.getLastModified())).size());
      }
      if (0 != (includedOptions & SMUDGE))
        if (entry.isSmudged())
          sb.append(", smudged");
      if (0 != (includedOptions & LENGTH))
        sb.append(", length:"
            + Integer.toString(entry.getLength()));
      if (0 != (includedOptions & CONTENT_ID))
        sb.append(", sha1:" + ObjectId.toString(entry.getObjectId()));
      if (0 != (includedOptions & CONTENT)) {
        sb.append(", content:"
            + new String(db.open(entry.getObjectId(),
                Constants.OBJ_BLOB).getCachedBytes(), "UTF-8"));
      }
      if (0 != (includedOptions & ASSUME_UNCHANGED))
        sb.append(", assume-unchanged:"
            + Boolean.toString(entry.isAssumeValid()));
      sb.append("]");
    }
    return sb.toString();
  }
View Full Code Here

   */
  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();
View Full Code Here

    return createEntry(path, mode, DirCacheEntry.STAGE_0, content);
  }

  protected DirCacheEntry createEntry(final String path, final FileMode mode,
      final int stage, final String content) {
    final DirCacheEntry entry = new DirCacheEntry(path, stage);
    entry.setFileMode(mode);
    entry.setObjectId(new ObjectInserter.Formatter().idFor(
        Constants.OBJ_BLOB, Constants.encode(content)));
    return entry;
  }
View Full Code Here

          DirCacheIterator.class);
      WorkingTreeIterator workingTreeIterator = treeWalk.getTree(WORKDIR,
          WorkingTreeIterator.class);

      if (dirCacheIterator != null) {
        final DirCacheEntry dirCacheEntry = dirCacheIterator
            .getDirCacheEntry();
        if (dirCacheEntry != null) {
          int stage = dirCacheEntry.getStage();
          if (stage > 0) {
            String path = treeWalk.getPathString();
            addConflict(path, stage);
            continue;
          }
View Full Code Here

   *
   * @param path
   * @return file mode
   */
  public FileMode getIndexMode(final String path) {
    final DirCacheEntry entry = dirCache.getEntry(path);
    return entry != null ? entry.getFileMode() : FileMode.MISSING;
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.dircache.DirCacheEntry

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.