コード例 #1
0
ファイル: Commit.java プロジェクト: miltonio/milton-cloud
 public static Commit find(Repository repo, long commitId, Session session) {
   Commit c = (Commit) session.get(Commit.class, commitId);
   if (c == null) {
     return null;
   }
   if (c.getBranch().getRepository() != repo) {
     return null;
   }
   return c;
 }
コード例 #2
0
  /**
   * Saves any changed items in the session by recalculating hashes and persisting new items to the
   * repository, and returns a list of root tree items which represent changed trees. That list will
   * contain the root of the tree which this session directly represents, but it will also contain
   * the roots of trees which have been affected through linked item updates
   *
   * @return
   */
  public String save(Profile currentUser) throws IOException {
    recalcHashes(rootDataNode);

    String newHash = rootDataNode.hash;

    Commit newCommit = new Commit();
    newCommit.setCreatedDate(currentDateService.getNow());
    newCommit.setEditor(currentUser);
    newCommit.setItemHash(newHash);
    session.save(newCommit);
    System.out.println("commit hash: " + newHash + " id " + newCommit.getId());
    branch.setHead(newCommit);
    session.save(branch);

    return rootDataNode.hash;
  }
コード例 #3
0
 public DataSession(
     Branch branch,
     Session session,
     HashStore hashStore,
     BlobStore blobStore,
     CurrentDateService currentDateService) {
   this.blobStore = blobStore;
   this.hashStore = hashStore;
   this.session = session;
   this.branch = branch;
   this.currentDateService = currentDateService;
   Commit c = branch.latestVersion(session);
   String hash = null;
   if (c != null) {
     hash = c.getItemHash();
   }
   rootDataNode = new DirectoryNode(null, null, hash);
 }
コード例 #4
0
  /**
   * Creates and saves a new branch, including setting up initial commit etc
   *
   * @param name
   * @param user
   * @param session
   * @return
   */
  public Branch createBranch(String name, Profile user, Session session) {
    Commit head = new Commit();
    head.setCreatedDate(new Date());
    head.setEditor(user);
    head.setItemHash(null);
    session.save(head);

    Branch b = new Branch();
    b.setName(Branch.TRUNK);
    b.setRepository(this);
    b.setHead(head);
    session.save(b);

    if (getBranches() == null) {
      setBranches(new ArrayList<Branch>());
    }
    getBranches().add(b);

    return b;
  }