Mercurial > jhg
annotate src/org/tmatesoft/hg/internal/MergeStateBuilder.java @ 707:42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 16 Aug 2013 19:22:59 +0200 |
parents | b4242b7e7dfe |
children |
rev | line source |
---|---|
705
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2013 TMate Software Ltd |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.internal; |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
707
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
19 import java.io.File; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
20 import java.io.FileOutputStream; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
21 import java.io.IOException; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
22 import java.io.OutputStream; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
23 import java.nio.ByteBuffer; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
24 import java.util.ArrayList; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
25 import java.util.List; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
26 |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
27 import org.tmatesoft.hg.core.HgFileRevision; |
705
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 import org.tmatesoft.hg.core.HgIOException; |
707
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
29 import org.tmatesoft.hg.core.Nodeid; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
30 import org.tmatesoft.hg.repo.HgManifest; |
705
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 import org.tmatesoft.hg.repo.HgMergeState; |
707
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
32 import org.tmatesoft.hg.repo.HgRepositoryFiles; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
33 import org.tmatesoft.hg.util.ByteChannel; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
34 import org.tmatesoft.hg.util.CancelledException; |
705
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 import org.tmatesoft.hg.util.Path; |
707
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
36 import org.tmatesoft.hg.util.LogFacility.Severity; |
705
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 /** |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 * Constructs merge/state file |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 * |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 * @see HgMergeState |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 * @author Artem Tikhomirov |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 * @author TMate Software Ltd. |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 */ |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 public class MergeStateBuilder { |
707
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
46 |
705
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 private final Internals repo; |
707
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
48 private final List<Record> unresolved = new ArrayList<Record>(); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
49 private Nodeid stateParent = Nodeid.NULL; |
705
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 public MergeStateBuilder(Internals implRepo) { |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 repo = implRepo; |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 } |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 |
707
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
55 public void prepare(Nodeid nodeid) { |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
56 assert nodeid != null; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
57 unresolved.clear(); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
58 stateParent = nodeid; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
59 abandon(); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
60 } |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
61 |
705
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 public void resolved() { |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 throw Internals.notImplemented(); |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 } |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 |
707
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
66 public void unresolved(Path file, HgFileRevision first, HgFileRevision second, HgFileRevision base, HgManifest.Flags flags) throws HgIOException { |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
67 Record r = new Record(file, first.getPath(), second.getPath(), base.getPath(), base.getRevision(), flags); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
68 final File d = mergeStateDir(); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
69 d.mkdirs(); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
70 File f = new File(d, r.hash()); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
71 try { |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
72 FileOutputStream fos = new FileOutputStream(f); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
73 first.putContentTo(new OutputStreamSink(fos)); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
74 fos.flush(); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
75 fos.close(); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
76 unresolved.add(r); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
77 } catch (IOException ex) { |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
78 throw new HgIOException(String.format("Failed to write content of unresolved file %s to merge state at %s", file, f), f); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
79 } catch (CancelledException ex) { |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
80 repo.getLog().dump(getClass(), Severity.Error, ex, "Our impl doesn't throw cancellation"); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
81 } |
705
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 } |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
83 |
707
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
84 // merge/state serialization is not a part of a transaction |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
85 public void serialize() throws HgIOException { |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
86 if (unresolved.isEmpty()) { |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
87 return; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
88 } |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
89 File mergeStateFile = repo.getRepositoryFile(HgRepositoryFiles.MergeState); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
90 try { |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
91 final byte NL = '\n'; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
92 FileOutputStream fos = new FileOutputStream(mergeStateFile); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
93 fos.write(stateParent.toString().getBytes()); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
94 fos.write(NL); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
95 for(Record r : unresolved) { |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
96 fos.write(r.key.toString().getBytes()); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
97 fos.write(0); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
98 fos.write('u'); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
99 fos.write(0); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
100 fos.write(r.hash().toString().getBytes()); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
101 fos.write(0); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
102 fos.write(r.fnameA.toString().getBytes()); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
103 fos.write(0); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
104 fos.write(r.fnameAncestor.toString().getBytes()); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
105 fos.write(0); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
106 fos.write(r.ancestorRev.toString().getBytes()); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
107 fos.write(0); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
108 fos.write(r.fnameB.toString().getBytes()); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
109 fos.write(0); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
110 fos.write(r.flags.mercurialString().getBytes()); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
111 fos.write(NL); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
112 } |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
113 fos.flush(); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
114 fos.close(); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
115 } catch (IOException ex) { |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
116 throw new HgIOException("Failed to serialize merge state", mergeStateFile); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
117 } |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
118 } |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
119 |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
120 public void abandon() { |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
121 File mergeStateDir = mergeStateDir(); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
122 try { |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
123 FileUtils.rmdir(mergeStateDir); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
124 } catch (IOException ex) { |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
125 // ignore almost silently |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
126 repo.getLog().dump(getClass(), Severity.Warn, ex, String.format("Failed to delete merge state in %s", mergeStateDir)); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
127 } |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
128 } |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
129 |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
130 private File mergeStateDir() { |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
131 return repo.getRepositoryFile(HgRepositoryFiles.MergeState).getParentFile(); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
132 } |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
133 |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
134 private static class Record { |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
135 public final Path key; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
136 public final Path fnameA, fnameB, fnameAncestor; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
137 public final Nodeid ancestorRev; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
138 public final HgManifest.Flags flags; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
139 private String hash; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
140 |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
141 public Record(Path fname, Path a, Path b, Path ancestor, Nodeid rev, HgManifest.Flags f) { |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
142 key = fname; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
143 fnameA = a; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
144 fnameB = b; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
145 fnameAncestor = ancestor; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
146 ancestorRev = rev; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
147 flags = f; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
148 } |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
149 |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
150 public String hash() { |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
151 if (hash == null) { |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
152 hash = new DigestHelper().sha1(key).asHexString(); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
153 } |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
154 return hash; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
155 } |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
156 } |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
157 |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
158 private static class OutputStreamSink implements ByteChannel { |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
159 private final OutputStream out; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
160 |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
161 public OutputStreamSink(OutputStream outputStream) { |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
162 out = outputStream; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
163 } |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
164 |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
165 public int write(ByteBuffer buffer) throws IOException { |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
166 final int toWrite = buffer.remaining(); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
167 if (toWrite <= 0) { |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
168 return 0; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
169 } |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
170 if (buffer.hasArray()) { |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
171 out.write(buffer.array(), buffer.arrayOffset(), toWrite); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
172 } else { |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
173 while (buffer.hasRemaining()) { |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
174 out.write(buffer.get()); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
175 } |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
176 } |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
177 buffer.position(buffer.limit()); |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
178 return toWrite; |
42b88709e41d
Merge: support 'unresolved' resolution with MergeStateBuilder
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
705
diff
changeset
|
179 } |
705
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
180 } |
b4242b7e7dfe
Merge command: implement conflict resolution alternatives
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
181 } |