Package org.eclipse.jgit.dircache

Examples of org.eclipse.jgit.dircache.DirCacheEntry


    DirCache dc = db.readDirCache();
    ObjectReader or = db.getObjectDatabase().newReader();
    Iterator<String> mpathsIt=modifiedFiles.iterator();
    while(mpathsIt.hasNext()) {
      String mpath=mpathsIt.next();
      DirCacheEntry entry = dc.getEntry(mpath);
      FileOutputStream fos = new FileOutputStream(new File(db.getWorkTree(), mpath));
      try {
        or.open(entry.getObjectId()).copyTo(fos);
      } finally {
        fos.close();
      }
      mpathsIt.remove();
    }
View Full Code Here


   * @param stage
   * @return the entry which was added to the index
   */
  private DirCacheEntry add(byte[] path, CanonicalTreeParser p, int stage) {
    if (p != null && !p.getEntryFileMode().equals(FileMode.TREE)) {
      DirCacheEntry e = new DirCacheEntry(path, stage);
      e.setFileMode(p.getEntryFileMode());
      e.setObjectId(p.getEntryObjectId());
      builder.add(e);
      return e;
    }
    return null;
  }
View Full Code Here

      // Check worktree before checking out THEIRS
      if (isWorktreeDirty())
        return false;
      if (nonTree(modeT)) {
        DirCacheEntry e = add(tw.getRawPath(), theirs,
            DirCacheEntry.STAGE_0);
        if (e != null)
          toBeCheckedOut.put(tw.getPathString(), e);
        return true;
      } else if (modeT == 0 && modeB != 0) {
        // we want THEIRS ... but THEIRS contains the deletion of the
        // file
        toBeCheckedOut.put(tw.getPathString(), null);
        return true;
      }
    }

    if (tw.isSubtree()) {
      // file/folder conflicts: here I want to detect only file/folder
      // conflict between ours and theirs. file/folder conflicts between
      // base/index/workingTree and something else are not relevant or
      // detected later
      if (nonTree(modeO) && !nonTree(modeT)) {
        if (nonTree(modeB))
          add(tw.getRawPath(), base, DirCacheEntry.STAGE_1);
        add(tw.getRawPath(), ours, DirCacheEntry.STAGE_2);
        unmergedPaths.add(tw.getPathString());
        enterSubtree = false;
        return true;
      }
      if (nonTree(modeT) && !nonTree(modeO)) {
        if (nonTree(modeB))
          add(tw.getRawPath(), base, DirCacheEntry.STAGE_1);
        add(tw.getRawPath(), theirs, DirCacheEntry.STAGE_3);
        unmergedPaths.add(tw.getPathString());
        enterSubtree = false;
        return true;
      }

      // ours and theirs are both folders or both files (and treewalk
      // tells us we are in a subtree because of index or working-dir).
      // If they are both folders no content-merge is required - we can
      // return here.
      if (!nonTree(modeO))
        return true;

      // ours and theirs are both files, just fall out of the if block
      // and do the content merge
    }

    if (nonTree(modeO) && nonTree(modeT)) {
      // Check worktree before modifying files
      if (isWorktreeDirty())
        return false;
      if (!contentMerge(base, ours, theirs)) {
        unmergedPaths.add(tw.getPathString());
      }
      modifiedFiles.add(tw.getPathString());
    } else if (modeO != modeT) {
      // OURS or THEIRS has been deleted
      if (((modeO != 0 && !tw.idEqual(T_BASE, T_OURS)) || (modeT != 0 && !tw
          .idEqual(T_BASE, T_THEIRS)))) {

        add(tw.getRawPath(), base, DirCacheEntry.STAGE_1);
        add(tw.getRawPath(), ours, DirCacheEntry.STAGE_2);
        DirCacheEntry e = add(tw.getRawPath(), theirs,
            DirCacheEntry.STAGE_3);

        // OURS was deleted checkout THEIRS
        if (modeO == 0) {
          // Check worktree before checking out THEIRS
View Full Code Here

      mergeResults.put(tw.getPathString(), result);
      return false;
    } else {
      // no conflict occurred, the file will contain fully merged content.
      // the index will be populated with the new merged version
      DirCacheEntry dce = new DirCacheEntry(tw.getPathString());
      dce.setFileMode(tw.getFileMode(0));
      dce.setLastModified(of.lastModified());
      dce.setLength((int) of.length());
      InputStream is = new FileInputStream(of);
      try {
        dce.setObjectId(oi.insert(Constants.OBJ_BLOB, of.length(),
            is));
      } finally {
        is.close();
        if (inCore)
          FileUtils.delete(of);
View Full Code Here

      // the cached index information for the path.
      //
      DirCacheIterator i = state.walk.getTree(state.dirCacheTree,
          DirCacheIterator.class);
      if (i != null) {
        DirCacheEntry ent = i.getDirCacheEntry();
        if (ent != null && compareMetadata(ent) == MetadataDiff.EQUAL) {
          contentIdOffset = i.idOffset();
          contentIdFromPtr = ptr;
          return contentId = i.idBuffer();
        }
View Full Code Here

        lastAddedFile = path;

        if (fTree != null) {
          // create a new DirCacheEntry with data retrieved from disk
          final DirCacheEntry dcEntry = new DirCacheEntry(path);
          long entryLength = fTree.getEntryLength();
          dcEntry.setLength(entryLength);
          dcEntry.setLastModified(fTree.getEntryLastModified());
          dcEntry.setFileMode(fTree.getIndexFileMode(dcTree));

          boolean objectExists = (dcTree != null && fTree
              .idEqual(dcTree))
              || (hTree != null && fTree.idEqual(hTree));
          if (objectExists) {
            dcEntry.setObjectId(fTree.getEntryObjectId());
          } else {
            if (FileMode.GITLINK.equals(dcEntry.getFileMode()))
              dcEntry.setObjectId(fTree.getEntryObjectId());
            else {
              // insert object
              if (inserter == null)
                inserter = repo.newObjectInserter();
              long contentLength = fTree.getEntryContentLength();
              InputStream inputStream = fTree.openEntryStream();
              try {
                dcEntry.setObjectId(inserter.insert(
                    Constants.OBJ_BLOB, contentLength,
                    inputStream));
              } finally {
                inputStream.close();
              }
            }
          }

          // add to existing index
          existingBuilder.add(dcEntry);
          // add to temporary in-core index
          tempBuilder.add(dcEntry);

          if (emptyCommit
              && (hTree == null || !hTree.idEqual(fTree) || hTree
                  .getEntryRawMode() != fTree
                  .getEntryRawMode()))
            // this is a change
            emptyCommit = false;
        } else {
          // if no file exists on disk, neither add it to
          // index nor to temporary in-core index

          if (emptyCommit && hTree != null)
            // this is a change
            emptyCommit = false;
        }

        // keep track of processed path
        onlyProcessed[pos] = true;
      } else {
        // 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
          tempBuilder.add(dcEntry);
        }
View Full Code Here

  }

  private DirCacheEntry file(final String name) throws IOException {
    final ObjectInserter oi = repository.newObjectInserter();
    try {
      final DirCacheEntry e = new DirCacheEntry(name);
      e.setFileMode(FileMode.REGULAR_FILE);
      e.setObjectId(oi.insert(Constants.OBJ_BLOB, Constants.encode(name)));
      oi.flush();
      return e;
    } finally {
      oi.release();
    }
View Full Code Here

        }

        DirCacheBuilder builder = dc.builder();
        int cnt = dc.getEntryCount();
        for (int i = 0; i < cnt;) {
          DirCacheEntry entry = dc.getEntry(i);
          if (entry.getStage() == 0) {
            builder.add(entry);
            i++;
            continue;
          }

          int next = dc.nextEntry(i);
          String path = entry.getPathString();
          DirCacheEntry res = new DirCacheEntry(path);
          if (resolved.containsKey(path)) {
            // For a file with content merge conflict that we produced a result
            // above on, collapse the file down to a single stage 0 with just
            // the blob content, and a randomly selected mode (the lowest stage,
            // which should be the merge base, or ours).
            res.setFileMode(entry.getFileMode());
            res.setObjectId(resolved.get(path));

          } else if (next == i + 1) {
            // If there is exactly one stage present, shouldn't be a conflict...
            res.setFileMode(entry.getFileMode());
            res.setObjectId(entry.getObjectId());

          } else if (next == i + 2) {
            // Two stages suggests a delete/modify conflict. Pick the higher
            // stage as the automatic result.
            entry = dc.getEntry(i + 1);
            res.setFileMode(entry.getFileMode());
            res.setObjectId(entry.getObjectId());

          } else { // 3 stage conflict, no resolve above
            // Punt on the 3-stage conflict and show the base, for now.
            res.setFileMode(entry.getFileMode());
            res.setObjectId(entry.getObjectId());
          }
          builder.add(res);
          i = next;
        }
        builder.finish();
View Full Code Here

    final SimpleDateFormat fmt;
    fmt = new SimpleDateFormat("yyyy-MM-dd,HH:mm:ss.SSS");

    final DirCache cache = db.readDirCache();
    for (int i = 0; i < cache.getEntryCount(); i++) {
      final DirCacheEntry ent = cache.getEntry(i);
      final FileMode mode = FileMode.fromBits(ent.getRawMode());
      final int len = ent.getLength();
      final Date mtime = new Date(ent.getLastModified());
      final int stage = ent.getStage();

      outw.print(mode);
      outw.format(" %6d", valueOf(len)); //$NON-NLS-1$
      outw.print(' ');
      outw.print(fmt.format(mtime));
      outw.print(' ');
      outw.print(ent.getObjectId().name());
      outw.print(' ');
      outw.print(stage);
      outw.print('\t');
      outw.print(ent.getPathString());
      outw.println();
    }
  }
View Full Code Here

    DirCache dc = db.readDirCache();
    ObjectReader or = db.getObjectDatabase().newReader();
    Iterator<String> mpathsIt=modifiedFiles.iterator();
    while(mpathsIt.hasNext()) {
      String mpath=mpathsIt.next();
      DirCacheEntry entry = dc.getEntry(mpath);
      FileOutputStream fos = new FileOutputStream(new File(db.getWorkTree(), mpath));
      try {
        or.open(entry.getObjectId()).copyTo(fos);
      } finally {
        fos.close();
      }
      mpathsIt.remove();
    }
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.