private BranchInfo getBranchInfo(ProjectHistory projectHistory, VersionSpec versionSpec) {
   for (final BranchInfo branchInfo : projectHistory.getBranches()) {
     if (branchInfo.getName().equals(versionSpec.getBranch())) {
       return branchInfo;
     }
   }
   return null;
 }
 /**
  * Returns all branches for the project with the given ID.
  *
  * @param projectId the ID of a project
  * @return a list containing information about each branch
  * @throws ESException in case of failure
  */
 @ESMethod(MethodId.GETBRANCHES)
 public List<BranchInfo> getBranches(ProjectId projectId) throws ESException {
   synchronized (getMonitor()) {
     final ProjectHistory projectHistory =
         getSubInterface(ProjectSubInterfaceImpl.class).getProject(projectId);
     final ArrayList<BranchInfo> result = new ArrayList<BranchInfo>();
     for (final BranchInfo branch : projectHistory.getBranches()) {
       result.add(ModelUtil.clone(branch));
     }
     return result;
   }
 }
  private BranchInfo createNewBranch(
      ProjectHistory projectHistory,
      PrimaryVersionSpec baseSpec,
      PrimaryVersionSpec primarySpec,
      BranchVersionSpec branch) {
    primarySpec.setBranch(branch.getBranch());

    final BranchInfo branchInfo = VersioningFactory.eINSTANCE.createBranchInfo();
    branchInfo.setName(branch.getBranch());
    branchInfo.setSource(ModelUtil.clone(baseSpec));
    branchInfo.setHead(ModelUtil.clone(primarySpec));

    projectHistory.getBranches().add(branchInfo);

    return branchInfo;
  }
  private void rollback(
      final ProjectHistory projectHistory,
      final BranchInfo baseBranch,
      final Version baseVersion,
      Version newVersion,
      BranchInfo newBranch,
      final FatalESException e)
      throws StorageException {
    projectHistory.getVersions().remove(newVersion);

    if (newBranch == null) {
      // normal commit
      baseVersion.setNextVersion(null);
      baseBranch.setHead(ModelUtil.clone(baseVersion.getPrimarySpec()));
    } else {
      // branch commit
      baseVersion.getBranchedVersions().remove(newVersion);
      projectHistory.getBranches().remove(newBranch);
    }
    // TODO: delete obsolete project, change package and version files
    throw new StorageException(StorageException.NOSAVE, e);
  }