Package org.eclipse.jgit.dircache

Examples of org.eclipse.jgit.dircache.DirCacheEntry


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


   *            the entry which should be copied
   *
   * @return the entry which was added to the index
   */
  private DirCacheEntry keep(DirCacheEntry e) {
    DirCacheEntry newEntry = new DirCacheEntry(e.getPathString(),
        e.getStage());
    newEntry.setFileMode(e.getFileMode());
    newEntry.setObjectId(e.getObjectId());
    newEntry.setLastModified(e.getLastModified());
    newEntry.setLength(e.getLength());
    builder.add(newEntry);
    return newEntry;
  }
View Full Code Here

      return true;

    if (isIndexDirty())
      return false;

    DirCacheEntry ourDce = null;

    if (index == null || index.getDirCacheEntry() == null) {
      // create a fake DCE, but only if ours is valid. ours is kept only
      // in case it is valid, so a null ourDce is ok in all other cases.
      if (nonTree(modeO)) {
        ourDce = new DirCacheEntry(tw.getRawPath());
        ourDce.setObjectId(tw.getObjectId(T_OURS));
        ourDce.setFileMode(tw.getFileMode(T_OURS));
      }
    } else {
      ourDce = index.getDirCacheEntry();
    }

    if (nonTree(modeO) && nonTree(modeT) && tw.idEqual(T_OURS, T_THEIRS)) {
      // OURS and THEIRS have equal content. Check the file mode
      if (modeO == modeT) {
        // content and mode of OURS and THEIRS are equal: it doesn't
        // matter which one we choose. OURS is chosen. Since the index
        // is clean (the index matches already OURS) we can keep the existing one
        keep(ourDce);
        // no checkout needed!
        return true;
      } else {
        // same content but different mode on OURS and THEIRS.
        // Try to merge the mode and report an error if this is
        // not possible.
        int newMode = mergeFileModes(modeB, modeO, modeT);
        if (newMode != FileMode.MISSING.getBits()) {
          if (newMode == modeO)
            // ours version is preferred
            keep(ourDce);
          else {
            // the preferred version THEIRS has a different mode
            // than ours. Check it out!
            if (isWorktreeDirty(work))
              return false;
            // we know about length and lastMod only after we have written the new content.
            // This will happen later. Set these values to 0 for know.
            DirCacheEntry e = add(tw.getRawPath(), theirs,
                DirCacheEntry.STAGE_0, 0, 0);
            toBeCheckedOut.put(tw.getPathString(), e);
          }
          return true;
        } else {
          // FileModes are not mergeable. We found a conflict on modes.
          // For conflicting entries we don't know lastModified and length.
          add(tw.getRawPath(), base, DirCacheEntry.STAGE_1, 0, 0);
          add(tw.getRawPath(), ours, DirCacheEntry.STAGE_2, 0, 0);
          add(tw.getRawPath(), theirs, DirCacheEntry.STAGE_3, 0, 0);
          unmergedPaths.add(tw.getPathString());
          mergeResults.put(
              tw.getPathString(),
              new MergeResult<RawText>(Collections
                  .<RawText> emptyList()));
        }
        return true;
      }
    }

    if (nonTree(modeO) && modeB == modeT && tw.idEqual(T_BASE, T_THEIRS)) {
      // THEIRS was not changed compared to BASE. All changes must be in
      // OURS. OURS is chosen. We can keep the existing entry.
      keep(ourDce);
      // no checkout needed!
      return true;
    }

    if (modeB == modeO && tw.idEqual(T_BASE, T_OURS)) {
      // OURS was not changed compared to BASE. All changes must be in
      // THEIRS. THEIRS is chosen.

      // Check worktree before checking out THEIRS
      if (isWorktreeDirty(work))
        return false;
      if (nonTree(modeT)) {
        // we know about length and lastMod only after we have written
        // the new content.
        // This will happen later. Set these values to 0 for know.
        DirCacheEntry e = add(tw.getRawPath(), theirs,
            DirCacheEntry.STAGE_0, 0, 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
        toBeDeleted.add(tw.getPathString());
        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, 0, 0);
        add(tw.getRawPath(), ours, DirCacheEntry.STAGE_2, 0, 0);
        unmergedPaths.add(tw.getPathString());
        enterSubtree = false;
        return true;
      }
      if (nonTree(modeT) && !nonTree(modeO)) {
        if (nonTree(modeB))
          add(tw.getRawPath(), base, DirCacheEntry.STAGE_1, 0, 0);
        add(tw.getRawPath(), theirs, DirCacheEntry.STAGE_3, 0, 0);
        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(work))
        return false;

      // Don't attempt to resolve submodule link conflicts
      if (isGitLink(modeO) || isGitLink(modeT)) {
        add(tw.getRawPath(), base, DirCacheEntry.STAGE_1, 0, 0);
        add(tw.getRawPath(), ours, DirCacheEntry.STAGE_2, 0, 0);
        add(tw.getRawPath(), theirs, DirCacheEntry.STAGE_3, 0, 0);
        unmergedPaths.add(tw.getPathString());
        return true;
      }

      MergeResult<RawText> result = contentMerge(base, ours, theirs);
      File of = writeMergedFile(result);
      updateIndex(base, ours, theirs, result, of);
      if (result.containsConflicts())
        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, 0, 0);
        add(tw.getRawPath(), ours, DirCacheEntry.STAGE_2, 0, 0);
        DirCacheEntry e = add(tw.getRawPath(), theirs,
            DirCacheEntry.STAGE_3, 0, 0);

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

      add(tw.getRawPath(), theirs, DirCacheEntry.STAGE_3, 0, 0);
      mergeResults.put(tw.getPathString(), result);
    } 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());
      int newMode = mergeFileModes(tw.getRawMode(0), tw.getRawMode(1),
          tw.getRawMode(2));
      // set the mode for the new content. Fall back to REGULAR_FILE if
      // you can't merge modes of OURS and THEIRS
      dce.setFileMode((newMode == FileMode.MISSING.getBits()) ? FileMode.REGULAR_FILE
          : FileMode.fromBits(newMode));
      dce.setLastModified(of.lastModified());
      dce.setLength((int) of.length());
      InputStream is = new FileInputStream(of);
      try {
        dce.setObjectId(getObjectInserter().insert(
            Constants.OBJ_BLOB, of.length(), is));
      } finally {
        is.close();
        if (inCore)
          FileUtils.delete(of);
View Full Code Here

        final CanonicalTreeParser tree = tw.getTree(1,
            CanonicalTreeParser.class);
        // only keep file in index if it's in the commit
        if (tree != null) {
            // revert index to commit
          DirCacheEntry entry = new DirCacheEntry(tw.getRawPath());
          entry.setFileMode(tree.getEntryFileMode());
          entry.setObjectId(tree.getEntryObjectId());
          builder.add(entry);
        }
      }

      builder.commit();
View Full Code Here

        if (cIter == null) {
          // Not in commit, don't add to new index
          continue;
        }

        final DirCacheEntry entry = new DirCacheEntry(walk.getRawPath());
        entry.setFileMode(cIter.getEntryFileMode());
        entry.setObjectIdFromRaw(cIter.idBuffer(), cIter.idOffset());

        DirCacheIterator dcIter = walk.getTree(1,
            DirCacheIterator.class);
        if (dcIter != null && dcIter.idEqual(cIter)) {
          DirCacheEntry indexEntry = dcIter.getDirCacheEntry();
          entry.setLastModified(indexEntry.getLastModified());
          entry.setLength(indexEntry.getLength());
        }

        builder.add(entry);
      }
View Full Code Here

    treeWalk.addTree(dci);

    final ObjectReader r = treeWalk.getObjectReader();
    DirCacheEditor editor = dc.editor();
    while (treeWalk.next()) {
      DirCacheEntry entry = dci.getDirCacheEntry();
      // Only add one edit per path
      if (entry != null && entry.getStage() > DirCacheEntry.STAGE_1)
        continue;
      editor.add(new PathEdit(treeWalk.getPathString()) {
        public void apply(DirCacheEntry ent) {
          int stage = ent.getStage();
          if (stage > DirCacheEntry.STAGE_0) {
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

    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

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.