Package org.eclipse.jgit.dircache

Examples of org.eclipse.jgit.dircache.DirCacheEntry


      // 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)
          return i.idBuffer();
      }
    }
View Full Code Here


        else if (!(path.equals(lastAddedFile))) {
          if (!(update && tw.getTree(0, DirCacheIterator.class) == null)) {
            c = tw.getTree(0, DirCacheIterator.class);
            if (f != null) { // the file exists
              long sz = f.getEntryLength();
              DirCacheEntry entry = new DirCacheEntry(path);
              if (c == null || c.getDirCacheEntry() == null
                  || !c.getDirCacheEntry().isAssumeValid()) {
                FileMode mode = f.getIndexFileMode(c);
                entry.setFileMode(mode);

                if (FileMode.GITLINK != mode) {
                  entry.setLength(sz);
                  entry.setLastModified(f
                      .getEntryLastModified());
                  InputStream in = f.openEntryStream();
                  try {
                    entry.setObjectId(inserter.insert(
                        Constants.OBJ_BLOB, sz, in));
                  } finally {
                    in.close();
                  }
                  builder.add(entry);
                  lastAddedFile = path;
                } else {
                  Repository subRepo = Git.open(
                      new File(repo.getWorkTree(), path))
                      .getRepository();
                  ObjectId subRepoHead = subRepo
                      .resolve(Constants.HEAD);
                  if (subRepoHead != null) {
                    entry.setObjectId(subRepoHead);
                    builder.add(entry);
                    lastAddedFile = path;
                  }
                }
              } else {
View Full Code Here

        if (!tracked)
          break;

        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();

              InputStream inputStream = fTree.openEntryStream();
              try {
                dcEntry.setObjectId(inserter.insert(
                    Constants.OBJ_BLOB, entryLength,
                    inputStream));
              } finally {
                inputStream.close();
              }
            }
          }

          // update index
          dcEditor.add(new PathEdit(path) {
            @Override
            public void apply(DirCacheEntry ent) {
              ent.copyMetaData(dcEntry);
            }
          });
          // add to temporary in-core index
          dcBuilder.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, remove entry from index and
          // don't add it to temporary in-core index
          dcEditor.add(new DeletePath(path));

          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
          dcBuilder.add(dcEntry);
        }
      }
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

          else {
            // the preferred version THEIRS has a different mode
            // than ours. Check it out!
            if (isWorktreeDirty())
              return false;
            DirCacheEntry e = add(tw.getRawPath(), theirs,
                DirCacheEntry.STAGE_0);
            toBeCheckedOut.put(tw.getPathString(), e);
          }
          return true;
        } else {
          // FileModes are not mergeable. We found a conflict on modes
          add(tw.getRawPath(), base, DirCacheEntry.STAGE_1);
          add(tw.getRawPath(), ours, DirCacheEntry.STAGE_2);
          add(tw.getRawPath(), theirs, DirCacheEntry.STAGE_3);
          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.
      add(tw.getRawPath(), ours, DirCacheEntry.STAGE_0);
      // 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())
        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;

      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);
        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

      add(tw.getRawPath(), theirs, DirCacheEntry.STAGE_3);
      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(oi.insert(Constants.OBJ_BLOB, of.length(), is));
      } finally {
        is.close();
        if (inCore)
          FileUtils.delete(of);
      }
View Full Code Here

        if (!tracked)
          break;

        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.getEntryFileMode());

          boolean objectExists = (dcTree != null && fTree
              .idEqual(dcTree))
              || (hTree != null && fTree.idEqual(hTree));
          if (objectExists) {
            dcEntry.setObjectId(fTree.getEntryObjectId());
          } else {
            // insert object
            if (inserter == null)
              inserter = repo.newObjectInserter();

            InputStream inputStream = fTree.openEntryStream();
            try {
              dcEntry.setObjectId(inserter.insert(
                  Constants.OBJ_BLOB, entryLength,
                  inputStream));
            } finally {
              inputStream.close();
            }
          }

          // update index
          dcEditor.add(new PathEdit(path) {
            @Override
            public void apply(DirCacheEntry ent) {
              ent.copyMetaData(dcEntry);
            }
          });
          // add to temporary in-core index
          dcBuilder.add(dcEntry);

          if (emptyCommit && (hTree == null || !hTree.idEqual(fTree)))
            // this is a change
            emptyCommit = false;
        } else {
          // if no file exists on disk, remove entry from index and
          // don't add it to temporary in-core index
          dcEditor.add(new DeletePath(path));

          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
          dcBuilder.add(dcEntry);
        }
      }
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)
          return i.idBuffer();
      }
    }
View Full Code Here

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

      if (dirCacheIterator != null) {
        final DirCacheEntry dirCacheEntry = dirCacheIterator
            .getDirCacheEntry();
        if (dirCacheEntry != null && dirCacheEntry.getStage() > 0) {
          conflicts.add(treeWalk.getPathString());
          continue;
        }
      }
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.