示例#1
0
 /**
  * Construct a tree from a specific listing of file entries.
  *
  * @param entries the files to include in the tree. The collection does not need to be sorted
  *     properly and may be empty.
  * @return reference to the tree specified by the entry list.
  * @throws Exception
  */
 public RevTree tree(final DirCacheEntry... entries) throws Exception {
   final DirCache dc = DirCache.newInCore();
   final DirCacheBuilder b = dc.builder();
   for (final DirCacheEntry e : entries) b.add(e);
   b.finish();
   ObjectId root;
   try {
     root = dc.writeTree(inserter);
     inserter.flush();
   } finally {
     inserter.release();
   }
   return pool.lookupTree(root);
 }
 /**
  * Reads a file from the tickets branch.
  *
  * @param db
  * @param file
  * @return the file content or null
  */
 private String readTicketsFile(Repository db, String file) {
   try {
     ObjectId treeId = db.resolve(BRANCH + "^{tree}");
     if (treeId == null) {
       return null;
     }
     try (RevWalk rw = new RevWalk(db)) {
       RevTree tree = rw.lookupTree(treeId);
       if (tree != null) {
         return JGitUtils.getStringContent(db, tree, file, Constants.ENCODING);
       }
     }
   } catch (IOException e) {
     log.error("failed to read " + file, e);
   }
   return null;
 }