Coverage Report - com.aragost.javahg.merge.GraftContext
 
Classes in this File Line Coverage Branch Coverage Complexity
GraftContext
70%
14/20
50%
3/6
2
 
 1  
 package com.aragost.javahg.merge;
 2  
 
 3  
 import com.aragost.javahg.Changeset;
 4  
 import com.aragost.javahg.Repository;
 5  
 import com.aragost.javahg.commands.CommitCommand;
 6  
 import com.aragost.javahg.commands.GraftCommand;
 7  
 import com.aragost.javahg.commands.LogCommand;
 8  
 
 9  
 public class GraftContext extends ConflictResolvingContext {
 10  
 
 11  
     private final int sourceRev;
 12  
 
 13  
     private Changeset source;
 14  
 
 15  
     /**
 16  
      * The graft command might decide to rollback a changeset. In
 17  
      * which case the field is set.
 18  
      * <p>
 19  
      * If the changeset is rollback, a commit has to be done when
 20  
      * conflicts are resolved, otherwise a graft --continue
 21  
      */
 22  
     private Changeset rollbackChangeset;
 23  
 
 24  
     public GraftContext(GraftCommand command, int sourceRev) {
 25  3
         super(command);
 26  3
         this.sourceRev = sourceRev;
 27  3
     }
 28  
 
 29  
     public synchronized Changeset getSource() {
 30  1
         if (this.source == null) {
 31  1
             this.source = LogCommand.on(getRepository()).rev("" + this.sourceRev).single();
 32  
         }
 33  1
         return this.source;
 34  
     }
 35  
 
 36  
     public Changeset commit() {
 37  1
         Repository repo = getRepository();
 38  1
         if (this.rollbackChangeset == null) {
 39  1
             repo.lock();
 40  
             try {
 41  1
                 boolean createdNewChangeset = ((GraftCommand) getCommand()).executeContinue();
 42  1
                 return createdNewChangeset ? repo.tip() : null;
 43  
             } finally {
 44  1
                 repo.unlock();
 45  
             }
 46  
         } else {
 47  0
             CommitCommand cmd = CommitCommand.on(repo);
 48  0
             cmd.user(this.rollbackChangeset.getUser());
 49  0
             cmd.date(this.rollbackChangeset.getTimestamp());
 50  0
             cmd.message(this.rollbackChangeset.getMessage());
 51  0
             cmd.extra("source", getSource().getNode());
 52  0
             return cmd.execute();
 53  
         }
 54  
     }
 55  
 
 56  
     public void setRollbackChangeset(Changeset rollbackChangeset) {
 57  1
         this.rollbackChangeset = rollbackChangeset;
 58  1
     }
 59  
 
 60  
 }