Examples of DirCacheEntry


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

Examples of org.eclipse.jgit.dircache.DirCacheEntry

          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

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

Examples of org.eclipse.jgit.dircache.DirCacheEntry

   * @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

Examples of org.eclipse.jgit.dircache.DirCacheEntry

      // 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) {
View Full Code Here

Examples of org.eclipse.jgit.dircache.DirCacheEntry

      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

Examples of org.eclipse.jgit.dircache.DirCacheEntry

        String title = StringUtils.stripDotGit(StringUtils.getLastPathElement(repositoryModel.name));
        String description = repositoryModel.description == null ? "" : repositoryModel.description;
        String readme = String.format("## %s\n\n%s\n\n", title, description);
        byte [] bytes = readme.getBytes(Constants.ENCODING);

        DirCacheEntry entry = new DirCacheEntry("README.md");
        entry.setLength(bytes.length);
        entry.setLastModified(System.currentTimeMillis());
        entry.setFileMode(FileMode.REGULAR_FILE);
        entry.setObjectId(odi.insert(org.eclipse.jgit.lib.Constants.OBJ_BLOB, bytes));

        indexBuilder.add(entry);
      }

      if (!StringUtils.isEmpty(gitignore)) {
        // insert a .gitignore file
        File dir = app().runtime().getFileOrFolder(Keys.git.gitignoreFolder, "${baseFolder}/gitignore");
        File file = new File(dir, gitignore + ".gitignore");
        if (file.exists() && file.length() > 0) {
          byte [] bytes = FileUtils.readContent(file);
          if (!ArrayUtils.isEmpty(bytes)) {
            DirCacheEntry entry = new DirCacheEntry(".gitignore");
            entry.setLength(bytes.length);
            entry.setLastModified(System.currentTimeMillis());
            entry.setFileMode(FileMode.REGULAR_FILE);
            entry.setObjectId(odi.insert(org.eclipse.jgit.lib.Constants.OBJ_BLOB, bytes));

            indexBuilder.add(entry);
          }
        }
      }

      if (addGitFlow) {
        // insert a .gitflow file
        Config config = new Config();
        config.setString("gitflow", null, "masterBranch", Constants.MASTER);
        config.setString("gitflow", null, "developBranch", Constants.DEVELOP);
        config.setString("gitflow", null, "featureBranchPrefix", "feature/");
        config.setString("gitflow", null, "releaseBranchPrefix", "release/");
        config.setString("gitflow", null, "hotfixBranchPrefix", "hotfix/");
        config.setString("gitflow", null, "supportBranchPrefix", "support/");
        config.setString("gitflow", null, "versionTagPrefix", "");

        byte [] bytes = config.toText().getBytes(Constants.ENCODING);

        DirCacheEntry entry = new DirCacheEntry(".gitflow");
        entry.setLength(bytes.length);
        entry.setLastModified(System.currentTimeMillis());
        entry.setFileMode(FileMode.REGULAR_FILE);
        entry.setObjectId(odi.insert(org.eclipse.jgit.lib.Constants.OBJ_BLOB, bytes));

        indexBuilder.add(entry);
      }

      indexBuilder.finish();
View Full Code Here

Examples of org.eclipse.jgit.dircache.DirCacheEntry

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

Examples of org.eclipse.jgit.dircache.DirCacheEntry

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

Examples of org.eclipse.jgit.dircache.DirCacheEntry

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