Mercurial > hg4j
comparison src/org/tmatesoft/hg/repo/ext/Rebase.java @ 501:d2f6ab541330
Change the way extensions are accessed (with ExtensionsManager now), add preliminary Rebase extension support
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 29 Oct 2012 19:04:13 +0100 |
parents | |
children | 6526d8adbc0f |
comparison
equal
deleted
inserted
replaced
500:465316bf97e8 | 501:d2f6ab541330 |
---|---|
1 /* | |
2 * Copyright (c) 2012 TMate Software Ltd | |
3 * | |
4 * This program is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; version 2 of the License. | |
7 * | |
8 * This program is distributed in the hope that it will be useful, | |
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 * GNU General Public License for more details. | |
12 * | |
13 * For information on how to redistribute this software under | |
14 * the terms of a license other than GNU General Public License | |
15 * contact TMate Software at support@hg4j.com | |
16 */ | |
17 package org.tmatesoft.hg.repo.ext; | |
18 | |
19 import java.io.File; | |
20 import java.util.ArrayList; | |
21 import java.util.HashMap; | |
22 import java.util.Iterator; | |
23 import java.util.Map; | |
24 import java.util.NoSuchElementException; | |
25 | |
26 import org.tmatesoft.hg.core.HgBadNodeidFormatException; | |
27 import org.tmatesoft.hg.core.HgIOException; | |
28 import org.tmatesoft.hg.core.Nodeid; | |
29 import org.tmatesoft.hg.internal.Internals; | |
30 import org.tmatesoft.hg.internal.LineReader; | |
31 import org.tmatesoft.hg.repo.HgInvalidFileException; | |
32 import org.tmatesoft.hg.repo.HgInvalidStateException; | |
33 | |
34 /** | |
35 * Support for standard Rebase extension. | |
36 * | |
37 * @see http://mercurial.selenic.com/wiki/RebaseExtension | |
38 * @since 1.1 | |
39 * @author Artem Tikhomirov | |
40 * @author TMate Software Ltd. | |
41 */ | |
42 public class Rebase { | |
43 private Internals repo; | |
44 private Nodeid workingDirParent; | |
45 private Nodeid destRevision; | |
46 private Nodeid externalParent; | |
47 private Map<Nodeid, Nodeid> state; | |
48 private boolean collapse; | |
49 private boolean keepOriginalRevisions; | |
50 private boolean keepBranchNames; | |
51 | |
52 /*package-local*/ Rebase(Internals internalRepo) { | |
53 repo = internalRepo; | |
54 } | |
55 | |
56 public Rebase refresh() throws HgIOException { | |
57 workingDirParent = null; | |
58 destRevision = null; | |
59 externalParent = null; | |
60 state = null; | |
61 File f = repo.getFileFromRepoDir("rebasestate"); | |
62 if (!f.exists()) { | |
63 return this; | |
64 } | |
65 state = new HashMap<Nodeid, Nodeid>(); | |
66 try { | |
67 LineReader lr = new LineReader(f, repo.getSessionContext().getLog()); | |
68 ArrayList<String> contents = new ArrayList<String>(); | |
69 lr.read(new LineReader.SimpleLineCollector(), contents); | |
70 Iterator<String> it = contents.iterator(); | |
71 workingDirParent = Nodeid.fromAscii(it.next()); | |
72 destRevision = Nodeid.fromAscii(it.next()); | |
73 externalParent = Nodeid.fromAscii(it.next()); | |
74 collapse = "1".equals(it.next()); | |
75 keepOriginalRevisions = "1".equals(it.next()); | |
76 keepBranchNames = "1".equals(it.next()); | |
77 final String nullmerge = "-2"; | |
78 while (it.hasNext()) { | |
79 String line = it.next(); | |
80 int x = line.indexOf(':'); | |
81 if (x == -1) { | |
82 throw new HgInvalidStateException(line); | |
83 } | |
84 Nodeid oldRev = Nodeid.fromAscii(line.substring(0, x)); | |
85 Nodeid newRev; | |
86 if (line.regionMatches(x+1, nullmerge, 0, nullmerge.length())) { | |
87 newRev = null; | |
88 } else { | |
89 newRev = Nodeid.fromAscii(line.substring(x+1)); | |
90 } | |
91 state.put(oldRev, newRev); | |
92 } | |
93 } catch (NoSuchElementException ex) { | |
94 throw new HgIOException("Bad format of rebase state file", f); | |
95 } catch (HgBadNodeidFormatException ex) { | |
96 throw new HgIOException("Bad format of rebase state file", ex, f); | |
97 } catch (HgInvalidFileException ex) { | |
98 throw new HgIOException("Bad format of rebase state file", ex, f); | |
99 } | |
100 return this; | |
101 } | |
102 | |
103 /** | |
104 * Tells whether rebase process was interrupted to manually resolve a merge | |
105 * and can be resumed or aborted. | |
106 * | |
107 * @return <code>true</code> when rebase is in progress | |
108 */ | |
109 public boolean isRebaseInProgress() { | |
110 return state != null; | |
111 } | |
112 | |
113 public Nodeid getWorkingDirParent() { | |
114 assert isRebaseInProgress(); | |
115 return workingDirParent; | |
116 } | |
117 | |
118 public Nodeid getTarget() { | |
119 assert isRebaseInProgress(); | |
120 return destRevision; | |
121 } | |
122 | |
123 public Nodeid getExternalParent() { | |
124 assert isRebaseInProgress(); | |
125 assert collapse; | |
126 return externalParent; | |
127 } | |
128 | |
129 public boolean isCollapse() { | |
130 return collapse; | |
131 } | |
132 | |
133 public boolean isKeepOriginalRevisions() { | |
134 return keepOriginalRevisions; | |
135 } | |
136 | |
137 public boolean isKeepBranchNames() { | |
138 return keepBranchNames; | |
139 } | |
140 } |