private PrimaryVersionSpec isHeadOfBranch(
     ProjectHistory projectHistory, PrimaryVersionSpec versionSpec) {
   final BranchInfo branchInfo = getBranchInfo(projectHistory, versionSpec);
   if (branchInfo != null && branchInfo.getHead().equals(versionSpec)) {
     return branchInfo.getHead();
   }
   return null;
 }
 private BranchInfo getBranchInfo(ProjectHistory projectHistory, VersionSpec versionSpec) {
   for (final BranchInfo branchInfo : projectHistory.getBranches()) {
     if (branchInfo.getName().equals(versionSpec.getBranch())) {
       return branchInfo;
     }
   }
   return null;
 }
 private PrimaryVersionSpec resolveBranchVersionSpec(
     ProjectHistory projectHistory, BranchVersionSpec versionSpec)
     throws BranchInfoMissingException {
   final BranchInfo branchInfo = getBranchInfo(projectHistory, versionSpec);
   if (branchInfo == null) {
     throw new BranchInfoMissingException(Messages.VersionSubInterfaceImpl_NoBranchInfo);
   }
   return branchInfo.getHead();
 }
 private PrimaryVersionSpec resolveHeadVersionSpec(
     ProjectHistory projectHistory, HeadVersionSpec versionSpec)
     throws InvalidVersionSpecException {
   if (VersionSpec.GLOBAL.equals(versionSpec.getBranch())) {
     return projectHistory
         .getVersions()
         .get(projectHistory.getVersions().size() - 1)
         .getPrimarySpec();
   }
   final BranchInfo info = getBranchInfo(projectHistory, versionSpec);
   if (info != null) {
     return info.getHead();
   }
   throw new InvalidVersionSpecException(Messages.VersionSubInterfaceImpl_HeadVersionNotFound);
 }
  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 Version performRegularCommit(
     PrimaryVersionSpec baseVersionSpec,
     LogMessage logMessage,
     final ACUser user,
     final ProjectHistory projectHistory,
     final BranchInfo baseBranch,
     final Version baseVersion,
     final Project newProjectState)
     throws ESUpdateRequiredException, ESException {
   Version newVersion;
   // If branch is null or branch equals base branch, create new
   // version for specific branch
   if (!baseVersionSpec.equals(isHeadOfBranch(projectHistory, baseVersion.getPrimarySpec()))) {
     throw new ESUpdateRequiredException();
   }
   newVersion = createVersion(projectHistory, newProjectState, logMessage, user, baseVersion);
   newVersion.setPreviousVersion(baseVersion);
   baseBranch.setHead(ModelUtil.clone(newVersion.getPrimarySpec()));
   return newVersion;
 }
  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);
  }