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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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 }