View Javadoc

1   package com.aragost.javahg.merge;
2   
3   import java.io.IOException;
4   
5   import com.aragost.javahg.internals.AbstractCommand;
6   import com.aragost.javahg.internals.HgInputStream;
7   import com.aragost.javahg.internals.UnexpectedCommandOutputException;
8   
9   public class BackoutConflictResolvingContext extends ConflictResolvingContext {
10  
11      private static final byte[] MERGING_WITH_CHANGESET = "merging with changeset ".getBytes();
12      private static final byte[] BACKS_OUT_CHANGESET = " backs out changeset ".getBytes();
13      private static final byte[] CHANGESET = "changeset".getBytes();
14      private static final byte[] REVERTING = "reverting".getBytes();
15      private static final byte[] CREATED_NEW_HEAD = "created new head".getBytes();
16  
17      private final boolean merge;
18  
19      public BackoutConflictResolvingContext(AbstractCommand command, boolean merge) {
20          super(command);
21          
22          this.merge = merge;
23      }
24  
25      /**
26       * Example:
27       * <pre>
28       * $ hg backout --merge 7:7
29       * reverting foo.txt
30       * created new head
31       * changeset 9:664c3e4cbb2b backs out changeset 7:3f5bacea93aa
32       * merging with changeset 9:664c3e4cbb2b
33       * merging foo.txt
34       * warning: conflicts during merge.
35       * merging foo.txt incomplete! (edit conflicts, then use 'hg resolve --mark')
36       * 0 files updated, 0 files merged, 0 files removed, 1 files unresolved
37       * use 'hg resolve' to retry unresolved file merges or 'hg update -C .' to abandon
38       * </pre>
39       * 
40       * @see com.aragost.javahg.merge.ConflictResolvingContext#processStream(com.aragost.javahg.internals.HgInputStream,
41       *      boolean)
42       */
43      @Override
44      public void processStream(HgInputStream in, boolean whenUnknowReturn)
45              throws IOException {
46          String createdChangeset = null;
47          
48          while (!in.isEof()) {
49              if (in.match(REVERTING)) {
50                  in.upTo('\n');
51              } else if (in.match(CREATED_NEW_HEAD)) {
52                  in.upTo('\n');
53              } else if (in.match(CHANGESET)) {
54                  createdChangeset = in.textUpTo(BACKS_OUT_CHANGESET);
55                  in.upTo('\n');
56              } else if (in.match(MERGING_WITH_CHANGESET)) {
57                  in.upTo('\n');
58              } else {
59                  break;
60              }
61          }
62  
63          if (createdChangeset == null && merge) {
64              if (whenUnknowReturn) {
65                  return;
66              }
67              throw new UnexpectedCommandOutputException(this.getCommand(), null);
68          }
69  
70          super.processStream(in, whenUnknowReturn);
71      }
72  
73  }