Show More
@@ -1,2311 +1,2314 b'' | |||||
1 | # localrepo.py - read/write repository class for mercurial |
|
1 | # localrepo.py - read/write repository class for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | from node import bin, hex, nullid, nullrev, short |
|
8 | from node import bin, hex, nullid, nullrev, short | |
9 | from i18n import _ |
|
9 | from i18n import _ | |
10 | import repo, changegroup, subrepo, discovery, pushkey |
|
10 | import repo, changegroup, subrepo, discovery, pushkey | |
11 | import changelog, dirstate, filelog, manifest, context, bookmarks, phases |
|
11 | import changelog, dirstate, filelog, manifest, context, bookmarks, phases | |
12 | import lock, transaction, store, encoding |
|
12 | import lock, transaction, store, encoding | |
13 | import scmutil, util, extensions, hook, error, revset |
|
13 | import scmutil, util, extensions, hook, error, revset | |
14 | import match as matchmod |
|
14 | import match as matchmod | |
15 | import merge as mergemod |
|
15 | import merge as mergemod | |
16 | import tags as tagsmod |
|
16 | import tags as tagsmod | |
17 | from lock import release |
|
17 | from lock import release | |
18 | import weakref, errno, os, time, inspect |
|
18 | import weakref, errno, os, time, inspect | |
19 | propertycache = util.propertycache |
|
19 | propertycache = util.propertycache | |
20 | filecache = scmutil.filecache |
|
20 | filecache = scmutil.filecache | |
21 |
|
21 | |||
22 | class localrepository(repo.repository): |
|
22 | class localrepository(repo.repository): | |
23 | capabilities = set(('lookup', 'changegroupsubset', 'branchmap', 'pushkey', |
|
23 | capabilities = set(('lookup', 'changegroupsubset', 'branchmap', 'pushkey', | |
24 | 'known', 'getbundle')) |
|
24 | 'known', 'getbundle')) | |
25 | supportedformats = set(('revlogv1', 'generaldelta')) |
|
25 | supportedformats = set(('revlogv1', 'generaldelta')) | |
26 | supported = supportedformats | set(('store', 'fncache', 'shared', |
|
26 | supported = supportedformats | set(('store', 'fncache', 'shared', | |
27 | 'dotencode')) |
|
27 | 'dotencode')) | |
28 |
|
28 | |||
29 | def __init__(self, baseui, path=None, create=False): |
|
29 | def __init__(self, baseui, path=None, create=False): | |
30 | repo.repository.__init__(self) |
|
30 | repo.repository.__init__(self) | |
31 | self.root = os.path.realpath(util.expandpath(path)) |
|
31 | self.root = os.path.realpath(util.expandpath(path)) | |
32 | self.path = os.path.join(self.root, ".hg") |
|
32 | self.path = os.path.join(self.root, ".hg") | |
33 | self.origroot = path |
|
33 | self.origroot = path | |
34 | self.auditor = scmutil.pathauditor(self.root, self._checknested) |
|
34 | self.auditor = scmutil.pathauditor(self.root, self._checknested) | |
35 | self.opener = scmutil.opener(self.path) |
|
35 | self.opener = scmutil.opener(self.path) | |
36 | self.wopener = scmutil.opener(self.root) |
|
36 | self.wopener = scmutil.opener(self.root) | |
37 | self.baseui = baseui |
|
37 | self.baseui = baseui | |
38 | self.ui = baseui.copy() |
|
38 | self.ui = baseui.copy() | |
39 | self._dirtyphases = False |
|
39 | self._dirtyphases = False | |
40 | # A list of callback to shape the phase if no data were found. |
|
40 | # A list of callback to shape the phase if no data were found. | |
41 | # Callback are in the form: func(repo, roots) --> processed root. |
|
41 | # Callback are in the form: func(repo, roots) --> processed root. | |
42 | # This list it to be filled by extension during repo setup |
|
42 | # This list it to be filled by extension during repo setup | |
43 | self._phasedefaults = [] |
|
43 | self._phasedefaults = [] | |
44 |
|
44 | |||
45 | try: |
|
45 | try: | |
46 | self.ui.readconfig(self.join("hgrc"), self.root) |
|
46 | self.ui.readconfig(self.join("hgrc"), self.root) | |
47 | extensions.loadall(self.ui) |
|
47 | extensions.loadall(self.ui) | |
48 | except IOError: |
|
48 | except IOError: | |
49 | pass |
|
49 | pass | |
50 |
|
50 | |||
51 | if not os.path.isdir(self.path): |
|
51 | if not os.path.isdir(self.path): | |
52 | if create: |
|
52 | if create: | |
53 | if not os.path.exists(path): |
|
53 | if not os.path.exists(path): | |
54 | util.makedirs(path) |
|
54 | util.makedirs(path) | |
55 | util.makedir(self.path, notindexed=True) |
|
55 | util.makedir(self.path, notindexed=True) | |
56 | requirements = ["revlogv1"] |
|
56 | requirements = ["revlogv1"] | |
57 | if self.ui.configbool('format', 'usestore', True): |
|
57 | if self.ui.configbool('format', 'usestore', True): | |
58 | os.mkdir(os.path.join(self.path, "store")) |
|
58 | os.mkdir(os.path.join(self.path, "store")) | |
59 | requirements.append("store") |
|
59 | requirements.append("store") | |
60 | if self.ui.configbool('format', 'usefncache', True): |
|
60 | if self.ui.configbool('format', 'usefncache', True): | |
61 | requirements.append("fncache") |
|
61 | requirements.append("fncache") | |
62 | if self.ui.configbool('format', 'dotencode', True): |
|
62 | if self.ui.configbool('format', 'dotencode', True): | |
63 | requirements.append('dotencode') |
|
63 | requirements.append('dotencode') | |
64 | # create an invalid changelog |
|
64 | # create an invalid changelog | |
65 | self.opener.append( |
|
65 | self.opener.append( | |
66 | "00changelog.i", |
|
66 | "00changelog.i", | |
67 | '\0\0\0\2' # represents revlogv2 |
|
67 | '\0\0\0\2' # represents revlogv2 | |
68 | ' dummy changelog to prevent using the old repo layout' |
|
68 | ' dummy changelog to prevent using the old repo layout' | |
69 | ) |
|
69 | ) | |
70 | if self.ui.configbool('format', 'generaldelta', False): |
|
70 | if self.ui.configbool('format', 'generaldelta', False): | |
71 | requirements.append("generaldelta") |
|
71 | requirements.append("generaldelta") | |
72 | requirements = set(requirements) |
|
72 | requirements = set(requirements) | |
73 | else: |
|
73 | else: | |
74 | raise error.RepoError(_("repository %s not found") % path) |
|
74 | raise error.RepoError(_("repository %s not found") % path) | |
75 | elif create: |
|
75 | elif create: | |
76 | raise error.RepoError(_("repository %s already exists") % path) |
|
76 | raise error.RepoError(_("repository %s already exists") % path) | |
77 | else: |
|
77 | else: | |
78 | try: |
|
78 | try: | |
79 | requirements = scmutil.readrequires(self.opener, self.supported) |
|
79 | requirements = scmutil.readrequires(self.opener, self.supported) | |
80 | except IOError, inst: |
|
80 | except IOError, inst: | |
81 | if inst.errno != errno.ENOENT: |
|
81 | if inst.errno != errno.ENOENT: | |
82 | raise |
|
82 | raise | |
83 | requirements = set() |
|
83 | requirements = set() | |
84 |
|
84 | |||
85 | self.sharedpath = self.path |
|
85 | self.sharedpath = self.path | |
86 | try: |
|
86 | try: | |
87 | s = os.path.realpath(self.opener.read("sharedpath").rstrip('\n')) |
|
87 | s = os.path.realpath(self.opener.read("sharedpath").rstrip('\n')) | |
88 | if not os.path.exists(s): |
|
88 | if not os.path.exists(s): | |
89 | raise error.RepoError( |
|
89 | raise error.RepoError( | |
90 | _('.hg/sharedpath points to nonexistent directory %s') % s) |
|
90 | _('.hg/sharedpath points to nonexistent directory %s') % s) | |
91 | self.sharedpath = s |
|
91 | self.sharedpath = s | |
92 | except IOError, inst: |
|
92 | except IOError, inst: | |
93 | if inst.errno != errno.ENOENT: |
|
93 | if inst.errno != errno.ENOENT: | |
94 | raise |
|
94 | raise | |
95 |
|
95 | |||
96 | self.store = store.store(requirements, self.sharedpath, scmutil.opener) |
|
96 | self.store = store.store(requirements, self.sharedpath, scmutil.opener) | |
97 | self.spath = self.store.path |
|
97 | self.spath = self.store.path | |
98 | self.sopener = self.store.opener |
|
98 | self.sopener = self.store.opener | |
99 | self.sjoin = self.store.join |
|
99 | self.sjoin = self.store.join | |
100 | self.opener.createmode = self.store.createmode |
|
100 | self.opener.createmode = self.store.createmode | |
101 | self._applyrequirements(requirements) |
|
101 | self._applyrequirements(requirements) | |
102 | if create: |
|
102 | if create: | |
103 | self._writerequirements() |
|
103 | self._writerequirements() | |
104 |
|
104 | |||
105 |
|
105 | |||
106 | self._branchcache = None |
|
106 | self._branchcache = None | |
107 | self._branchcachetip = None |
|
107 | self._branchcachetip = None | |
108 | self.filterpats = {} |
|
108 | self.filterpats = {} | |
109 | self._datafilters = {} |
|
109 | self._datafilters = {} | |
110 | self._transref = self._lockref = self._wlockref = None |
|
110 | self._transref = self._lockref = self._wlockref = None | |
111 |
|
111 | |||
112 | # A cache for various files under .hg/ that tracks file changes, |
|
112 | # A cache for various files under .hg/ that tracks file changes, | |
113 | # (used by the filecache decorator) |
|
113 | # (used by the filecache decorator) | |
114 | # |
|
114 | # | |
115 | # Maps a property name to its util.filecacheentry |
|
115 | # Maps a property name to its util.filecacheentry | |
116 | self._filecache = {} |
|
116 | self._filecache = {} | |
117 |
|
117 | |||
118 | def _applyrequirements(self, requirements): |
|
118 | def _applyrequirements(self, requirements): | |
119 | self.requirements = requirements |
|
119 | self.requirements = requirements | |
120 | openerreqs = set(('revlogv1', 'generaldelta')) |
|
120 | openerreqs = set(('revlogv1', 'generaldelta')) | |
121 | self.sopener.options = dict((r, 1) for r in requirements |
|
121 | self.sopener.options = dict((r, 1) for r in requirements | |
122 | if r in openerreqs) |
|
122 | if r in openerreqs) | |
123 |
|
123 | |||
124 | def _writerequirements(self): |
|
124 | def _writerequirements(self): | |
125 | reqfile = self.opener("requires", "w") |
|
125 | reqfile = self.opener("requires", "w") | |
126 | for r in self.requirements: |
|
126 | for r in self.requirements: | |
127 | reqfile.write("%s\n" % r) |
|
127 | reqfile.write("%s\n" % r) | |
128 | reqfile.close() |
|
128 | reqfile.close() | |
129 |
|
129 | |||
130 | def _checknested(self, path): |
|
130 | def _checknested(self, path): | |
131 | """Determine if path is a legal nested repository.""" |
|
131 | """Determine if path is a legal nested repository.""" | |
132 | if not path.startswith(self.root): |
|
132 | if not path.startswith(self.root): | |
133 | return False |
|
133 | return False | |
134 | subpath = path[len(self.root) + 1:] |
|
134 | subpath = path[len(self.root) + 1:] | |
135 | normsubpath = util.pconvert(subpath) |
|
135 | normsubpath = util.pconvert(subpath) | |
136 |
|
136 | |||
137 | # XXX: Checking against the current working copy is wrong in |
|
137 | # XXX: Checking against the current working copy is wrong in | |
138 | # the sense that it can reject things like |
|
138 | # the sense that it can reject things like | |
139 | # |
|
139 | # | |
140 | # $ hg cat -r 10 sub/x.txt |
|
140 | # $ hg cat -r 10 sub/x.txt | |
141 | # |
|
141 | # | |
142 | # if sub/ is no longer a subrepository in the working copy |
|
142 | # if sub/ is no longer a subrepository in the working copy | |
143 | # parent revision. |
|
143 | # parent revision. | |
144 | # |
|
144 | # | |
145 | # However, it can of course also allow things that would have |
|
145 | # However, it can of course also allow things that would have | |
146 | # been rejected before, such as the above cat command if sub/ |
|
146 | # been rejected before, such as the above cat command if sub/ | |
147 | # is a subrepository now, but was a normal directory before. |
|
147 | # is a subrepository now, but was a normal directory before. | |
148 | # The old path auditor would have rejected by mistake since it |
|
148 | # The old path auditor would have rejected by mistake since it | |
149 | # panics when it sees sub/.hg/. |
|
149 | # panics when it sees sub/.hg/. | |
150 | # |
|
150 | # | |
151 | # All in all, checking against the working copy seems sensible |
|
151 | # All in all, checking against the working copy seems sensible | |
152 | # since we want to prevent access to nested repositories on |
|
152 | # since we want to prevent access to nested repositories on | |
153 | # the filesystem *now*. |
|
153 | # the filesystem *now*. | |
154 | ctx = self[None] |
|
154 | ctx = self[None] | |
155 | parts = util.splitpath(subpath) |
|
155 | parts = util.splitpath(subpath) | |
156 | while parts: |
|
156 | while parts: | |
157 | prefix = '/'.join(parts) |
|
157 | prefix = '/'.join(parts) | |
158 | if prefix in ctx.substate: |
|
158 | if prefix in ctx.substate: | |
159 | if prefix == normsubpath: |
|
159 | if prefix == normsubpath: | |
160 | return True |
|
160 | return True | |
161 | else: |
|
161 | else: | |
162 | sub = ctx.sub(prefix) |
|
162 | sub = ctx.sub(prefix) | |
163 | return sub.checknested(subpath[len(prefix) + 1:]) |
|
163 | return sub.checknested(subpath[len(prefix) + 1:]) | |
164 | else: |
|
164 | else: | |
165 | parts.pop() |
|
165 | parts.pop() | |
166 | return False |
|
166 | return False | |
167 |
|
167 | |||
168 | @filecache('bookmarks') |
|
168 | @filecache('bookmarks') | |
169 | def _bookmarks(self): |
|
169 | def _bookmarks(self): | |
170 | return bookmarks.read(self) |
|
170 | return bookmarks.read(self) | |
171 |
|
171 | |||
172 | @filecache('bookmarks.current') |
|
172 | @filecache('bookmarks.current') | |
173 | def _bookmarkcurrent(self): |
|
173 | def _bookmarkcurrent(self): | |
174 | return bookmarks.readcurrent(self) |
|
174 | return bookmarks.readcurrent(self) | |
175 |
|
175 | |||
176 | def _writebookmarks(self, marks): |
|
176 | def _writebookmarks(self, marks): | |
177 | bookmarks.write(self) |
|
177 | bookmarks.write(self) | |
178 |
|
178 | |||
179 | @filecache('phaseroots', True) |
|
179 | @filecache('phaseroots', True) | |
180 | def _phaseroots(self): |
|
180 | def _phaseroots(self): | |
181 | self._dirtyphases = False |
|
181 | self._dirtyphases = False | |
182 | phaseroots = phases.readroots(self) |
|
182 | phaseroots = phases.readroots(self) | |
183 | phases.filterunknown(self, phaseroots) |
|
183 | phases.filterunknown(self, phaseroots) | |
184 | return phaseroots |
|
184 | return phaseroots | |
185 |
|
185 | |||
186 | @propertycache |
|
186 | @propertycache | |
187 | def _phaserev(self): |
|
187 | def _phaserev(self): | |
188 | cache = [phases.public] * len(self) |
|
188 | cache = [phases.public] * len(self) | |
189 | for phase in phases.trackedphases: |
|
189 | for phase in phases.trackedphases: | |
190 | roots = map(self.changelog.rev, self._phaseroots[phase]) |
|
190 | roots = map(self.changelog.rev, self._phaseroots[phase]) | |
191 | if roots: |
|
191 | if roots: | |
192 | for rev in roots: |
|
192 | for rev in roots: | |
193 | cache[rev] = phase |
|
193 | cache[rev] = phase | |
194 | for rev in self.changelog.descendants(*roots): |
|
194 | for rev in self.changelog.descendants(*roots): | |
195 | cache[rev] = phase |
|
195 | cache[rev] = phase | |
196 | return cache |
|
196 | return cache | |
197 |
|
197 | |||
198 | @filecache('00changelog.i', True) |
|
198 | @filecache('00changelog.i', True) | |
199 | def changelog(self): |
|
199 | def changelog(self): | |
200 | c = changelog.changelog(self.sopener) |
|
200 | c = changelog.changelog(self.sopener) | |
201 | if 'HG_PENDING' in os.environ: |
|
201 | if 'HG_PENDING' in os.environ: | |
202 | p = os.environ['HG_PENDING'] |
|
202 | p = os.environ['HG_PENDING'] | |
203 | if p.startswith(self.root): |
|
203 | if p.startswith(self.root): | |
204 | c.readpending('00changelog.i.a') |
|
204 | c.readpending('00changelog.i.a') | |
205 | return c |
|
205 | return c | |
206 |
|
206 | |||
207 | @filecache('00manifest.i', True) |
|
207 | @filecache('00manifest.i', True) | |
208 | def manifest(self): |
|
208 | def manifest(self): | |
209 | return manifest.manifest(self.sopener) |
|
209 | return manifest.manifest(self.sopener) | |
210 |
|
210 | |||
211 | @filecache('dirstate') |
|
211 | @filecache('dirstate') | |
212 | def dirstate(self): |
|
212 | def dirstate(self): | |
213 | warned = [0] |
|
213 | warned = [0] | |
214 | def validate(node): |
|
214 | def validate(node): | |
215 | try: |
|
215 | try: | |
216 | self.changelog.rev(node) |
|
216 | self.changelog.rev(node) | |
217 | return node |
|
217 | return node | |
218 | except error.LookupError: |
|
218 | except error.LookupError: | |
219 | if not warned[0]: |
|
219 | if not warned[0]: | |
220 | warned[0] = True |
|
220 | warned[0] = True | |
221 | self.ui.warn(_("warning: ignoring unknown" |
|
221 | self.ui.warn(_("warning: ignoring unknown" | |
222 | " working parent %s!\n") % short(node)) |
|
222 | " working parent %s!\n") % short(node)) | |
223 | return nullid |
|
223 | return nullid | |
224 |
|
224 | |||
225 | return dirstate.dirstate(self.opener, self.ui, self.root, validate) |
|
225 | return dirstate.dirstate(self.opener, self.ui, self.root, validate) | |
226 |
|
226 | |||
227 | def __getitem__(self, changeid): |
|
227 | def __getitem__(self, changeid): | |
228 | if changeid is None: |
|
228 | if changeid is None: | |
229 | return context.workingctx(self) |
|
229 | return context.workingctx(self) | |
230 | return context.changectx(self, changeid) |
|
230 | return context.changectx(self, changeid) | |
231 |
|
231 | |||
232 | def __contains__(self, changeid): |
|
232 | def __contains__(self, changeid): | |
233 | try: |
|
233 | try: | |
234 | return bool(self.lookup(changeid)) |
|
234 | return bool(self.lookup(changeid)) | |
235 | except error.RepoLookupError: |
|
235 | except error.RepoLookupError: | |
236 | return False |
|
236 | return False | |
237 |
|
237 | |||
238 | def __nonzero__(self): |
|
238 | def __nonzero__(self): | |
239 | return True |
|
239 | return True | |
240 |
|
240 | |||
241 | def __len__(self): |
|
241 | def __len__(self): | |
242 | return len(self.changelog) |
|
242 | return len(self.changelog) | |
243 |
|
243 | |||
244 | def __iter__(self): |
|
244 | def __iter__(self): | |
245 | for i in xrange(len(self)): |
|
245 | for i in xrange(len(self)): | |
246 | yield i |
|
246 | yield i | |
247 |
|
247 | |||
248 | def revs(self, expr, *args): |
|
248 | def revs(self, expr, *args): | |
249 | '''Return a list of revisions matching the given revset''' |
|
249 | '''Return a list of revisions matching the given revset''' | |
250 | expr = revset.formatspec(expr, *args) |
|
250 | expr = revset.formatspec(expr, *args) | |
251 | m = revset.match(None, expr) |
|
251 | m = revset.match(None, expr) | |
252 | return [r for r in m(self, range(len(self)))] |
|
252 | return [r for r in m(self, range(len(self)))] | |
253 |
|
253 | |||
254 | def set(self, expr, *args): |
|
254 | def set(self, expr, *args): | |
255 | ''' |
|
255 | ''' | |
256 | Yield a context for each matching revision, after doing arg |
|
256 | Yield a context for each matching revision, after doing arg | |
257 | replacement via revset.formatspec |
|
257 | replacement via revset.formatspec | |
258 | ''' |
|
258 | ''' | |
259 | for r in self.revs(expr, *args): |
|
259 | for r in self.revs(expr, *args): | |
260 | yield self[r] |
|
260 | yield self[r] | |
261 |
|
261 | |||
262 | def url(self): |
|
262 | def url(self): | |
263 | return 'file:' + self.root |
|
263 | return 'file:' + self.root | |
264 |
|
264 | |||
265 | def hook(self, name, throw=False, **args): |
|
265 | def hook(self, name, throw=False, **args): | |
266 | return hook.hook(self.ui, self, name, throw, **args) |
|
266 | return hook.hook(self.ui, self, name, throw, **args) | |
267 |
|
267 | |||
268 | tag_disallowed = ':\r\n' |
|
268 | tag_disallowed = ':\r\n' | |
269 |
|
269 | |||
270 | def _tag(self, names, node, message, local, user, date, extra={}): |
|
270 | def _tag(self, names, node, message, local, user, date, extra={}): | |
271 | if isinstance(names, str): |
|
271 | if isinstance(names, str): | |
272 | allchars = names |
|
272 | allchars = names | |
273 | names = (names,) |
|
273 | names = (names,) | |
274 | else: |
|
274 | else: | |
275 | allchars = ''.join(names) |
|
275 | allchars = ''.join(names) | |
276 | for c in self.tag_disallowed: |
|
276 | for c in self.tag_disallowed: | |
277 | if c in allchars: |
|
277 | if c in allchars: | |
278 | raise util.Abort(_('%r cannot be used in a tag name') % c) |
|
278 | raise util.Abort(_('%r cannot be used in a tag name') % c) | |
279 |
|
279 | |||
280 | branches = self.branchmap() |
|
280 | branches = self.branchmap() | |
281 | for name in names: |
|
281 | for name in names: | |
282 | self.hook('pretag', throw=True, node=hex(node), tag=name, |
|
282 | self.hook('pretag', throw=True, node=hex(node), tag=name, | |
283 | local=local) |
|
283 | local=local) | |
284 | if name in branches: |
|
284 | if name in branches: | |
285 | self.ui.warn(_("warning: tag %s conflicts with existing" |
|
285 | self.ui.warn(_("warning: tag %s conflicts with existing" | |
286 | " branch name\n") % name) |
|
286 | " branch name\n") % name) | |
287 |
|
287 | |||
288 | def writetags(fp, names, munge, prevtags): |
|
288 | def writetags(fp, names, munge, prevtags): | |
289 | fp.seek(0, 2) |
|
289 | fp.seek(0, 2) | |
290 | if prevtags and prevtags[-1] != '\n': |
|
290 | if prevtags and prevtags[-1] != '\n': | |
291 | fp.write('\n') |
|
291 | fp.write('\n') | |
292 | for name in names: |
|
292 | for name in names: | |
293 | m = munge and munge(name) or name |
|
293 | m = munge and munge(name) or name | |
294 | if self._tagscache.tagtypes and name in self._tagscache.tagtypes: |
|
294 | if self._tagscache.tagtypes and name in self._tagscache.tagtypes: | |
295 | old = self.tags().get(name, nullid) |
|
295 | old = self.tags().get(name, nullid) | |
296 | fp.write('%s %s\n' % (hex(old), m)) |
|
296 | fp.write('%s %s\n' % (hex(old), m)) | |
297 | fp.write('%s %s\n' % (hex(node), m)) |
|
297 | fp.write('%s %s\n' % (hex(node), m)) | |
298 | fp.close() |
|
298 | fp.close() | |
299 |
|
299 | |||
300 | prevtags = '' |
|
300 | prevtags = '' | |
301 | if local: |
|
301 | if local: | |
302 | try: |
|
302 | try: | |
303 | fp = self.opener('localtags', 'r+') |
|
303 | fp = self.opener('localtags', 'r+') | |
304 | except IOError: |
|
304 | except IOError: | |
305 | fp = self.opener('localtags', 'a') |
|
305 | fp = self.opener('localtags', 'a') | |
306 | else: |
|
306 | else: | |
307 | prevtags = fp.read() |
|
307 | prevtags = fp.read() | |
308 |
|
308 | |||
309 | # local tags are stored in the current charset |
|
309 | # local tags are stored in the current charset | |
310 | writetags(fp, names, None, prevtags) |
|
310 | writetags(fp, names, None, prevtags) | |
311 | for name in names: |
|
311 | for name in names: | |
312 | self.hook('tag', node=hex(node), tag=name, local=local) |
|
312 | self.hook('tag', node=hex(node), tag=name, local=local) | |
313 | return |
|
313 | return | |
314 |
|
314 | |||
315 | try: |
|
315 | try: | |
316 | fp = self.wfile('.hgtags', 'rb+') |
|
316 | fp = self.wfile('.hgtags', 'rb+') | |
317 | except IOError, e: |
|
317 | except IOError, e: | |
318 | if e.errno != errno.ENOENT: |
|
318 | if e.errno != errno.ENOENT: | |
319 | raise |
|
319 | raise | |
320 | fp = self.wfile('.hgtags', 'ab') |
|
320 | fp = self.wfile('.hgtags', 'ab') | |
321 | else: |
|
321 | else: | |
322 | prevtags = fp.read() |
|
322 | prevtags = fp.read() | |
323 |
|
323 | |||
324 | # committed tags are stored in UTF-8 |
|
324 | # committed tags are stored in UTF-8 | |
325 | writetags(fp, names, encoding.fromlocal, prevtags) |
|
325 | writetags(fp, names, encoding.fromlocal, prevtags) | |
326 |
|
326 | |||
327 | fp.close() |
|
327 | fp.close() | |
328 |
|
328 | |||
329 | self.invalidatecaches() |
|
329 | self.invalidatecaches() | |
330 |
|
330 | |||
331 | if '.hgtags' not in self.dirstate: |
|
331 | if '.hgtags' not in self.dirstate: | |
332 | self[None].add(['.hgtags']) |
|
332 | self[None].add(['.hgtags']) | |
333 |
|
333 | |||
334 | m = matchmod.exact(self.root, '', ['.hgtags']) |
|
334 | m = matchmod.exact(self.root, '', ['.hgtags']) | |
335 | tagnode = self.commit(message, user, date, extra=extra, match=m) |
|
335 | tagnode = self.commit(message, user, date, extra=extra, match=m) | |
336 |
|
336 | |||
337 | for name in names: |
|
337 | for name in names: | |
338 | self.hook('tag', node=hex(node), tag=name, local=local) |
|
338 | self.hook('tag', node=hex(node), tag=name, local=local) | |
339 |
|
339 | |||
340 | return tagnode |
|
340 | return tagnode | |
341 |
|
341 | |||
342 | def tag(self, names, node, message, local, user, date): |
|
342 | def tag(self, names, node, message, local, user, date): | |
343 | '''tag a revision with one or more symbolic names. |
|
343 | '''tag a revision with one or more symbolic names. | |
344 |
|
344 | |||
345 | names is a list of strings or, when adding a single tag, names may be a |
|
345 | names is a list of strings or, when adding a single tag, names may be a | |
346 | string. |
|
346 | string. | |
347 |
|
347 | |||
348 | if local is True, the tags are stored in a per-repository file. |
|
348 | if local is True, the tags are stored in a per-repository file. | |
349 | otherwise, they are stored in the .hgtags file, and a new |
|
349 | otherwise, they are stored in the .hgtags file, and a new | |
350 | changeset is committed with the change. |
|
350 | changeset is committed with the change. | |
351 |
|
351 | |||
352 | keyword arguments: |
|
352 | keyword arguments: | |
353 |
|
353 | |||
354 | local: whether to store tags in non-version-controlled file |
|
354 | local: whether to store tags in non-version-controlled file | |
355 | (default False) |
|
355 | (default False) | |
356 |
|
356 | |||
357 | message: commit message to use if committing |
|
357 | message: commit message to use if committing | |
358 |
|
358 | |||
359 | user: name of user to use if committing |
|
359 | user: name of user to use if committing | |
360 |
|
360 | |||
361 | date: date tuple to use if committing''' |
|
361 | date: date tuple to use if committing''' | |
362 |
|
362 | |||
363 | if not local: |
|
363 | if not local: | |
364 | for x in self.status()[:5]: |
|
364 | for x in self.status()[:5]: | |
365 | if '.hgtags' in x: |
|
365 | if '.hgtags' in x: | |
366 | raise util.Abort(_('working copy of .hgtags is changed ' |
|
366 | raise util.Abort(_('working copy of .hgtags is changed ' | |
367 | '(please commit .hgtags manually)')) |
|
367 | '(please commit .hgtags manually)')) | |
368 |
|
368 | |||
369 | self.tags() # instantiate the cache |
|
369 | self.tags() # instantiate the cache | |
370 | self._tag(names, node, message, local, user, date) |
|
370 | self._tag(names, node, message, local, user, date) | |
371 |
|
371 | |||
372 | @propertycache |
|
372 | @propertycache | |
373 | def _tagscache(self): |
|
373 | def _tagscache(self): | |
374 | '''Returns a tagscache object that contains various tags related caches.''' |
|
374 | '''Returns a tagscache object that contains various tags related caches.''' | |
375 |
|
375 | |||
376 | # This simplifies its cache management by having one decorated |
|
376 | # This simplifies its cache management by having one decorated | |
377 | # function (this one) and the rest simply fetch things from it. |
|
377 | # function (this one) and the rest simply fetch things from it. | |
378 | class tagscache(object): |
|
378 | class tagscache(object): | |
379 | def __init__(self): |
|
379 | def __init__(self): | |
380 | # These two define the set of tags for this repository. tags |
|
380 | # These two define the set of tags for this repository. tags | |
381 | # maps tag name to node; tagtypes maps tag name to 'global' or |
|
381 | # maps tag name to node; tagtypes maps tag name to 'global' or | |
382 | # 'local'. (Global tags are defined by .hgtags across all |
|
382 | # 'local'. (Global tags are defined by .hgtags across all | |
383 | # heads, and local tags are defined in .hg/localtags.) |
|
383 | # heads, and local tags are defined in .hg/localtags.) | |
384 | # They constitute the in-memory cache of tags. |
|
384 | # They constitute the in-memory cache of tags. | |
385 | self.tags = self.tagtypes = None |
|
385 | self.tags = self.tagtypes = None | |
386 |
|
386 | |||
387 | self.nodetagscache = self.tagslist = None |
|
387 | self.nodetagscache = self.tagslist = None | |
388 |
|
388 | |||
389 | cache = tagscache() |
|
389 | cache = tagscache() | |
390 | cache.tags, cache.tagtypes = self._findtags() |
|
390 | cache.tags, cache.tagtypes = self._findtags() | |
391 |
|
391 | |||
392 | return cache |
|
392 | return cache | |
393 |
|
393 | |||
394 | def tags(self): |
|
394 | def tags(self): | |
395 | '''return a mapping of tag to node''' |
|
395 | '''return a mapping of tag to node''' | |
396 | return self._tagscache.tags |
|
396 | return self._tagscache.tags | |
397 |
|
397 | |||
398 | def _findtags(self): |
|
398 | def _findtags(self): | |
399 | '''Do the hard work of finding tags. Return a pair of dicts |
|
399 | '''Do the hard work of finding tags. Return a pair of dicts | |
400 | (tags, tagtypes) where tags maps tag name to node, and tagtypes |
|
400 | (tags, tagtypes) where tags maps tag name to node, and tagtypes | |
401 | maps tag name to a string like \'global\' or \'local\'. |
|
401 | maps tag name to a string like \'global\' or \'local\'. | |
402 | Subclasses or extensions are free to add their own tags, but |
|
402 | Subclasses or extensions are free to add their own tags, but | |
403 | should be aware that the returned dicts will be retained for the |
|
403 | should be aware that the returned dicts will be retained for the | |
404 | duration of the localrepo object.''' |
|
404 | duration of the localrepo object.''' | |
405 |
|
405 | |||
406 | # XXX what tagtype should subclasses/extensions use? Currently |
|
406 | # XXX what tagtype should subclasses/extensions use? Currently | |
407 | # mq and bookmarks add tags, but do not set the tagtype at all. |
|
407 | # mq and bookmarks add tags, but do not set the tagtype at all. | |
408 | # Should each extension invent its own tag type? Should there |
|
408 | # Should each extension invent its own tag type? Should there | |
409 | # be one tagtype for all such "virtual" tags? Or is the status |
|
409 | # be one tagtype for all such "virtual" tags? Or is the status | |
410 | # quo fine? |
|
410 | # quo fine? | |
411 |
|
411 | |||
412 | alltags = {} # map tag name to (node, hist) |
|
412 | alltags = {} # map tag name to (node, hist) | |
413 | tagtypes = {} |
|
413 | tagtypes = {} | |
414 |
|
414 | |||
415 | tagsmod.findglobaltags(self.ui, self, alltags, tagtypes) |
|
415 | tagsmod.findglobaltags(self.ui, self, alltags, tagtypes) | |
416 | tagsmod.readlocaltags(self.ui, self, alltags, tagtypes) |
|
416 | tagsmod.readlocaltags(self.ui, self, alltags, tagtypes) | |
417 |
|
417 | |||
418 | # Build the return dicts. Have to re-encode tag names because |
|
418 | # Build the return dicts. Have to re-encode tag names because | |
419 | # the tags module always uses UTF-8 (in order not to lose info |
|
419 | # the tags module always uses UTF-8 (in order not to lose info | |
420 | # writing to the cache), but the rest of Mercurial wants them in |
|
420 | # writing to the cache), but the rest of Mercurial wants them in | |
421 | # local encoding. |
|
421 | # local encoding. | |
422 | tags = {} |
|
422 | tags = {} | |
423 | for (name, (node, hist)) in alltags.iteritems(): |
|
423 | for (name, (node, hist)) in alltags.iteritems(): | |
424 | if node != nullid: |
|
424 | if node != nullid: | |
425 | try: |
|
425 | try: | |
426 | # ignore tags to unknown nodes |
|
426 | # ignore tags to unknown nodes | |
427 | self.changelog.lookup(node) |
|
427 | self.changelog.lookup(node) | |
428 | tags[encoding.tolocal(name)] = node |
|
428 | tags[encoding.tolocal(name)] = node | |
429 | except error.LookupError: |
|
429 | except error.LookupError: | |
430 | pass |
|
430 | pass | |
431 | tags['tip'] = self.changelog.tip() |
|
431 | tags['tip'] = self.changelog.tip() | |
432 | tagtypes = dict([(encoding.tolocal(name), value) |
|
432 | tagtypes = dict([(encoding.tolocal(name), value) | |
433 | for (name, value) in tagtypes.iteritems()]) |
|
433 | for (name, value) in tagtypes.iteritems()]) | |
434 | return (tags, tagtypes) |
|
434 | return (tags, tagtypes) | |
435 |
|
435 | |||
436 | def tagtype(self, tagname): |
|
436 | def tagtype(self, tagname): | |
437 | ''' |
|
437 | ''' | |
438 | return the type of the given tag. result can be: |
|
438 | return the type of the given tag. result can be: | |
439 |
|
439 | |||
440 | 'local' : a local tag |
|
440 | 'local' : a local tag | |
441 | 'global' : a global tag |
|
441 | 'global' : a global tag | |
442 | None : tag does not exist |
|
442 | None : tag does not exist | |
443 | ''' |
|
443 | ''' | |
444 |
|
444 | |||
445 | return self._tagscache.tagtypes.get(tagname) |
|
445 | return self._tagscache.tagtypes.get(tagname) | |
446 |
|
446 | |||
447 | def tagslist(self): |
|
447 | def tagslist(self): | |
448 | '''return a list of tags ordered by revision''' |
|
448 | '''return a list of tags ordered by revision''' | |
449 | if not self._tagscache.tagslist: |
|
449 | if not self._tagscache.tagslist: | |
450 | l = [] |
|
450 | l = [] | |
451 | for t, n in self.tags().iteritems(): |
|
451 | for t, n in self.tags().iteritems(): | |
452 | r = self.changelog.rev(n) |
|
452 | r = self.changelog.rev(n) | |
453 | l.append((r, t, n)) |
|
453 | l.append((r, t, n)) | |
454 | self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)] |
|
454 | self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)] | |
455 |
|
455 | |||
456 | return self._tagscache.tagslist |
|
456 | return self._tagscache.tagslist | |
457 |
|
457 | |||
458 | def nodetags(self, node): |
|
458 | def nodetags(self, node): | |
459 | '''return the tags associated with a node''' |
|
459 | '''return the tags associated with a node''' | |
460 | if not self._tagscache.nodetagscache: |
|
460 | if not self._tagscache.nodetagscache: | |
461 | nodetagscache = {} |
|
461 | nodetagscache = {} | |
462 | for t, n in self.tags().iteritems(): |
|
462 | for t, n in self.tags().iteritems(): | |
463 | nodetagscache.setdefault(n, []).append(t) |
|
463 | nodetagscache.setdefault(n, []).append(t) | |
464 | for tags in nodetagscache.itervalues(): |
|
464 | for tags in nodetagscache.itervalues(): | |
465 | tags.sort() |
|
465 | tags.sort() | |
466 | self._tagscache.nodetagscache = nodetagscache |
|
466 | self._tagscache.nodetagscache = nodetagscache | |
467 | return self._tagscache.nodetagscache.get(node, []) |
|
467 | return self._tagscache.nodetagscache.get(node, []) | |
468 |
|
468 | |||
469 | def nodebookmarks(self, node): |
|
469 | def nodebookmarks(self, node): | |
470 | marks = [] |
|
470 | marks = [] | |
471 | for bookmark, n in self._bookmarks.iteritems(): |
|
471 | for bookmark, n in self._bookmarks.iteritems(): | |
472 | if n == node: |
|
472 | if n == node: | |
473 | marks.append(bookmark) |
|
473 | marks.append(bookmark) | |
474 | return sorted(marks) |
|
474 | return sorted(marks) | |
475 |
|
475 | |||
476 | def _branchtags(self, partial, lrev): |
|
476 | def _branchtags(self, partial, lrev): | |
477 | # TODO: rename this function? |
|
477 | # TODO: rename this function? | |
478 | tiprev = len(self) - 1 |
|
478 | tiprev = len(self) - 1 | |
479 | if lrev != tiprev: |
|
479 | if lrev != tiprev: | |
480 | ctxgen = (self[r] for r in xrange(lrev + 1, tiprev + 1)) |
|
480 | ctxgen = (self[r] for r in xrange(lrev + 1, tiprev + 1)) | |
481 | self._updatebranchcache(partial, ctxgen) |
|
481 | self._updatebranchcache(partial, ctxgen) | |
482 | self._writebranchcache(partial, self.changelog.tip(), tiprev) |
|
482 | self._writebranchcache(partial, self.changelog.tip(), tiprev) | |
483 |
|
483 | |||
484 | return partial |
|
484 | return partial | |
485 |
|
485 | |||
486 | def updatebranchcache(self): |
|
486 | def updatebranchcache(self): | |
487 | tip = self.changelog.tip() |
|
487 | tip = self.changelog.tip() | |
488 | if self._branchcache is not None and self._branchcachetip == tip: |
|
488 | if self._branchcache is not None and self._branchcachetip == tip: | |
489 | return |
|
489 | return | |
490 |
|
490 | |||
491 | oldtip = self._branchcachetip |
|
491 | oldtip = self._branchcachetip | |
492 | self._branchcachetip = tip |
|
492 | self._branchcachetip = tip | |
493 | if oldtip is None or oldtip not in self.changelog.nodemap: |
|
493 | if oldtip is None or oldtip not in self.changelog.nodemap: | |
494 | partial, last, lrev = self._readbranchcache() |
|
494 | partial, last, lrev = self._readbranchcache() | |
495 | else: |
|
495 | else: | |
496 | lrev = self.changelog.rev(oldtip) |
|
496 | lrev = self.changelog.rev(oldtip) | |
497 | partial = self._branchcache |
|
497 | partial = self._branchcache | |
498 |
|
498 | |||
499 | self._branchtags(partial, lrev) |
|
499 | self._branchtags(partial, lrev) | |
500 | # this private cache holds all heads (not just tips) |
|
500 | # this private cache holds all heads (not just tips) | |
501 | self._branchcache = partial |
|
501 | self._branchcache = partial | |
502 |
|
502 | |||
503 | def branchmap(self): |
|
503 | def branchmap(self): | |
504 | '''returns a dictionary {branch: [branchheads]}''' |
|
504 | '''returns a dictionary {branch: [branchheads]}''' | |
505 | self.updatebranchcache() |
|
505 | self.updatebranchcache() | |
506 | return self._branchcache |
|
506 | return self._branchcache | |
507 |
|
507 | |||
508 | def branchtags(self): |
|
508 | def branchtags(self): | |
509 | '''return a dict where branch names map to the tipmost head of |
|
509 | '''return a dict where branch names map to the tipmost head of | |
510 | the branch, open heads come before closed''' |
|
510 | the branch, open heads come before closed''' | |
511 | bt = {} |
|
511 | bt = {} | |
512 | for bn, heads in self.branchmap().iteritems(): |
|
512 | for bn, heads in self.branchmap().iteritems(): | |
513 | tip = heads[-1] |
|
513 | tip = heads[-1] | |
514 | for h in reversed(heads): |
|
514 | for h in reversed(heads): | |
515 | if 'close' not in self.changelog.read(h)[5]: |
|
515 | if 'close' not in self.changelog.read(h)[5]: | |
516 | tip = h |
|
516 | tip = h | |
517 | break |
|
517 | break | |
518 | bt[bn] = tip |
|
518 | bt[bn] = tip | |
519 | return bt |
|
519 | return bt | |
520 |
|
520 | |||
521 | def _readbranchcache(self): |
|
521 | def _readbranchcache(self): | |
522 | partial = {} |
|
522 | partial = {} | |
523 | try: |
|
523 | try: | |
524 | f = self.opener("cache/branchheads") |
|
524 | f = self.opener("cache/branchheads") | |
525 | lines = f.read().split('\n') |
|
525 | lines = f.read().split('\n') | |
526 | f.close() |
|
526 | f.close() | |
527 | except (IOError, OSError): |
|
527 | except (IOError, OSError): | |
528 | return {}, nullid, nullrev |
|
528 | return {}, nullid, nullrev | |
529 |
|
529 | |||
530 | try: |
|
530 | try: | |
531 | last, lrev = lines.pop(0).split(" ", 1) |
|
531 | last, lrev = lines.pop(0).split(" ", 1) | |
532 | last, lrev = bin(last), int(lrev) |
|
532 | last, lrev = bin(last), int(lrev) | |
533 | if lrev >= len(self) or self[lrev].node() != last: |
|
533 | if lrev >= len(self) or self[lrev].node() != last: | |
534 | # invalidate the cache |
|
534 | # invalidate the cache | |
535 | raise ValueError('invalidating branch cache (tip differs)') |
|
535 | raise ValueError('invalidating branch cache (tip differs)') | |
536 | for l in lines: |
|
536 | for l in lines: | |
537 | if not l: |
|
537 | if not l: | |
538 | continue |
|
538 | continue | |
539 | node, label = l.split(" ", 1) |
|
539 | node, label = l.split(" ", 1) | |
540 | label = encoding.tolocal(label.strip()) |
|
540 | label = encoding.tolocal(label.strip()) | |
541 | partial.setdefault(label, []).append(bin(node)) |
|
541 | partial.setdefault(label, []).append(bin(node)) | |
542 | except KeyboardInterrupt: |
|
542 | except KeyboardInterrupt: | |
543 | raise |
|
543 | raise | |
544 | except Exception, inst: |
|
544 | except Exception, inst: | |
545 | if self.ui.debugflag: |
|
545 | if self.ui.debugflag: | |
546 | self.ui.warn(str(inst), '\n') |
|
546 | self.ui.warn(str(inst), '\n') | |
547 | partial, last, lrev = {}, nullid, nullrev |
|
547 | partial, last, lrev = {}, nullid, nullrev | |
548 | return partial, last, lrev |
|
548 | return partial, last, lrev | |
549 |
|
549 | |||
550 | def _writebranchcache(self, branches, tip, tiprev): |
|
550 | def _writebranchcache(self, branches, tip, tiprev): | |
551 | try: |
|
551 | try: | |
552 | f = self.opener("cache/branchheads", "w", atomictemp=True) |
|
552 | f = self.opener("cache/branchheads", "w", atomictemp=True) | |
553 | f.write("%s %s\n" % (hex(tip), tiprev)) |
|
553 | f.write("%s %s\n" % (hex(tip), tiprev)) | |
554 | for label, nodes in branches.iteritems(): |
|
554 | for label, nodes in branches.iteritems(): | |
555 | for node in nodes: |
|
555 | for node in nodes: | |
556 | f.write("%s %s\n" % (hex(node), encoding.fromlocal(label))) |
|
556 | f.write("%s %s\n" % (hex(node), encoding.fromlocal(label))) | |
557 | f.close() |
|
557 | f.close() | |
558 | except (IOError, OSError): |
|
558 | except (IOError, OSError): | |
559 | pass |
|
559 | pass | |
560 |
|
560 | |||
561 | def _updatebranchcache(self, partial, ctxgen): |
|
561 | def _updatebranchcache(self, partial, ctxgen): | |
562 | # collect new branch entries |
|
562 | # collect new branch entries | |
563 | newbranches = {} |
|
563 | newbranches = {} | |
564 | for c in ctxgen: |
|
564 | for c in ctxgen: | |
565 | newbranches.setdefault(c.branch(), []).append(c.node()) |
|
565 | newbranches.setdefault(c.branch(), []).append(c.node()) | |
566 | # if older branchheads are reachable from new ones, they aren't |
|
566 | # if older branchheads are reachable from new ones, they aren't | |
567 | # really branchheads. Note checking parents is insufficient: |
|
567 | # really branchheads. Note checking parents is insufficient: | |
568 | # 1 (branch a) -> 2 (branch b) -> 3 (branch a) |
|
568 | # 1 (branch a) -> 2 (branch b) -> 3 (branch a) | |
569 | for branch, newnodes in newbranches.iteritems(): |
|
569 | for branch, newnodes in newbranches.iteritems(): | |
570 | bheads = partial.setdefault(branch, []) |
|
570 | bheads = partial.setdefault(branch, []) | |
571 | bheads.extend(newnodes) |
|
571 | bheads.extend(newnodes) | |
572 | if len(bheads) <= 1: |
|
572 | if len(bheads) <= 1: | |
573 | continue |
|
573 | continue | |
574 | bheads = sorted(bheads, key=lambda x: self[x].rev()) |
|
574 | bheads = sorted(bheads, key=lambda x: self[x].rev()) | |
575 | # starting from tip means fewer passes over reachable |
|
575 | # starting from tip means fewer passes over reachable | |
576 | while newnodes: |
|
576 | while newnodes: | |
577 | latest = newnodes.pop() |
|
577 | latest = newnodes.pop() | |
578 | if latest not in bheads: |
|
578 | if latest not in bheads: | |
579 | continue |
|
579 | continue | |
580 | minbhrev = self[bheads[0]].node() |
|
580 | minbhrev = self[bheads[0]].node() | |
581 | reachable = self.changelog.reachable(latest, minbhrev) |
|
581 | reachable = self.changelog.reachable(latest, minbhrev) | |
582 | reachable.remove(latest) |
|
582 | reachable.remove(latest) | |
583 | if reachable: |
|
583 | if reachable: | |
584 | bheads = [b for b in bheads if b not in reachable] |
|
584 | bheads = [b for b in bheads if b not in reachable] | |
585 | partial[branch] = bheads |
|
585 | partial[branch] = bheads | |
586 |
|
586 | |||
587 | def lookup(self, key): |
|
587 | def lookup(self, key): | |
588 | if isinstance(key, int): |
|
588 | if isinstance(key, int): | |
589 | return self.changelog.node(key) |
|
589 | return self.changelog.node(key) | |
590 | elif key == '.': |
|
590 | elif key == '.': | |
591 | return self.dirstate.p1() |
|
591 | return self.dirstate.p1() | |
592 | elif key == 'null': |
|
592 | elif key == 'null': | |
593 | return nullid |
|
593 | return nullid | |
594 | elif key == 'tip': |
|
594 | elif key == 'tip': | |
595 | return self.changelog.tip() |
|
595 | return self.changelog.tip() | |
596 | n = self.changelog._match(key) |
|
596 | n = self.changelog._match(key) | |
597 | if n: |
|
597 | if n: | |
598 | return n |
|
598 | return n | |
599 | if key in self._bookmarks: |
|
599 | if key in self._bookmarks: | |
600 | return self._bookmarks[key] |
|
600 | return self._bookmarks[key] | |
601 | if key in self.tags(): |
|
601 | if key in self.tags(): | |
602 | return self.tags()[key] |
|
602 | return self.tags()[key] | |
603 | if key in self.branchtags(): |
|
603 | if key in self.branchtags(): | |
604 | return self.branchtags()[key] |
|
604 | return self.branchtags()[key] | |
605 | n = self.changelog._partialmatch(key) |
|
605 | n = self.changelog._partialmatch(key) | |
606 | if n: |
|
606 | if n: | |
607 | return n |
|
607 | return n | |
608 |
|
608 | |||
609 | # can't find key, check if it might have come from damaged dirstate |
|
609 | # can't find key, check if it might have come from damaged dirstate | |
610 | if key in self.dirstate.parents(): |
|
610 | if key in self.dirstate.parents(): | |
611 | raise error.Abort(_("working directory has unknown parent '%s'!") |
|
611 | raise error.Abort(_("working directory has unknown parent '%s'!") | |
612 | % short(key)) |
|
612 | % short(key)) | |
613 | try: |
|
613 | try: | |
614 | if len(key) == 20: |
|
614 | if len(key) == 20: | |
615 | key = hex(key) |
|
615 | key = hex(key) | |
616 | except TypeError: |
|
616 | except TypeError: | |
617 | pass |
|
617 | pass | |
618 | raise error.RepoLookupError(_("unknown revision '%s'") % key) |
|
618 | raise error.RepoLookupError(_("unknown revision '%s'") % key) | |
619 |
|
619 | |||
620 | def lookupbranch(self, key, remote=None): |
|
620 | def lookupbranch(self, key, remote=None): | |
621 | repo = remote or self |
|
621 | repo = remote or self | |
622 | if key in repo.branchmap(): |
|
622 | if key in repo.branchmap(): | |
623 | return key |
|
623 | return key | |
624 |
|
624 | |||
625 | repo = (remote and remote.local()) and remote or self |
|
625 | repo = (remote and remote.local()) and remote or self | |
626 | return repo[key].branch() |
|
626 | return repo[key].branch() | |
627 |
|
627 | |||
628 | def known(self, nodes): |
|
628 | def known(self, nodes): | |
629 | nm = self.changelog.nodemap |
|
629 | nm = self.changelog.nodemap | |
630 | result = [] |
|
630 | result = [] | |
631 | for n in nodes: |
|
631 | for n in nodes: | |
632 | r = nm.get(n) |
|
632 | r = nm.get(n) | |
633 | resp = not (r is None or self._phaserev[r] >= phases.secret) |
|
633 | resp = not (r is None or self._phaserev[r] >= phases.secret) | |
634 | result.append(resp) |
|
634 | result.append(resp) | |
635 | return result |
|
635 | return result | |
636 |
|
636 | |||
637 | def local(self): |
|
637 | def local(self): | |
638 | return self |
|
638 | return self | |
639 |
|
639 | |||
640 | def join(self, f): |
|
640 | def join(self, f): | |
641 | return os.path.join(self.path, f) |
|
641 | return os.path.join(self.path, f) | |
642 |
|
642 | |||
643 | def wjoin(self, f): |
|
643 | def wjoin(self, f): | |
644 | return os.path.join(self.root, f) |
|
644 | return os.path.join(self.root, f) | |
645 |
|
645 | |||
646 | def file(self, f): |
|
646 | def file(self, f): | |
647 | if f[0] == '/': |
|
647 | if f[0] == '/': | |
648 | f = f[1:] |
|
648 | f = f[1:] | |
649 | return filelog.filelog(self.sopener, f) |
|
649 | return filelog.filelog(self.sopener, f) | |
650 |
|
650 | |||
651 | def changectx(self, changeid): |
|
651 | def changectx(self, changeid): | |
652 | return self[changeid] |
|
652 | return self[changeid] | |
653 |
|
653 | |||
654 | def parents(self, changeid=None): |
|
654 | def parents(self, changeid=None): | |
655 | '''get list of changectxs for parents of changeid''' |
|
655 | '''get list of changectxs for parents of changeid''' | |
656 | return self[changeid].parents() |
|
656 | return self[changeid].parents() | |
657 |
|
657 | |||
658 | def filectx(self, path, changeid=None, fileid=None): |
|
658 | def filectx(self, path, changeid=None, fileid=None): | |
659 | """changeid can be a changeset revision, node, or tag. |
|
659 | """changeid can be a changeset revision, node, or tag. | |
660 | fileid can be a file revision or node.""" |
|
660 | fileid can be a file revision or node.""" | |
661 | return context.filectx(self, path, changeid, fileid) |
|
661 | return context.filectx(self, path, changeid, fileid) | |
662 |
|
662 | |||
663 | def getcwd(self): |
|
663 | def getcwd(self): | |
664 | return self.dirstate.getcwd() |
|
664 | return self.dirstate.getcwd() | |
665 |
|
665 | |||
666 | def pathto(self, f, cwd=None): |
|
666 | def pathto(self, f, cwd=None): | |
667 | return self.dirstate.pathto(f, cwd) |
|
667 | return self.dirstate.pathto(f, cwd) | |
668 |
|
668 | |||
669 | def wfile(self, f, mode='r'): |
|
669 | def wfile(self, f, mode='r'): | |
670 | return self.wopener(f, mode) |
|
670 | return self.wopener(f, mode) | |
671 |
|
671 | |||
672 | def _link(self, f): |
|
672 | def _link(self, f): | |
673 | return os.path.islink(self.wjoin(f)) |
|
673 | return os.path.islink(self.wjoin(f)) | |
674 |
|
674 | |||
675 | def _loadfilter(self, filter): |
|
675 | def _loadfilter(self, filter): | |
676 | if filter not in self.filterpats: |
|
676 | if filter not in self.filterpats: | |
677 | l = [] |
|
677 | l = [] | |
678 | for pat, cmd in self.ui.configitems(filter): |
|
678 | for pat, cmd in self.ui.configitems(filter): | |
679 | if cmd == '!': |
|
679 | if cmd == '!': | |
680 | continue |
|
680 | continue | |
681 | mf = matchmod.match(self.root, '', [pat]) |
|
681 | mf = matchmod.match(self.root, '', [pat]) | |
682 | fn = None |
|
682 | fn = None | |
683 | params = cmd |
|
683 | params = cmd | |
684 | for name, filterfn in self._datafilters.iteritems(): |
|
684 | for name, filterfn in self._datafilters.iteritems(): | |
685 | if cmd.startswith(name): |
|
685 | if cmd.startswith(name): | |
686 | fn = filterfn |
|
686 | fn = filterfn | |
687 | params = cmd[len(name):].lstrip() |
|
687 | params = cmd[len(name):].lstrip() | |
688 | break |
|
688 | break | |
689 | if not fn: |
|
689 | if not fn: | |
690 | fn = lambda s, c, **kwargs: util.filter(s, c) |
|
690 | fn = lambda s, c, **kwargs: util.filter(s, c) | |
691 | # Wrap old filters not supporting keyword arguments |
|
691 | # Wrap old filters not supporting keyword arguments | |
692 | if not inspect.getargspec(fn)[2]: |
|
692 | if not inspect.getargspec(fn)[2]: | |
693 | oldfn = fn |
|
693 | oldfn = fn | |
694 | fn = lambda s, c, **kwargs: oldfn(s, c) |
|
694 | fn = lambda s, c, **kwargs: oldfn(s, c) | |
695 | l.append((mf, fn, params)) |
|
695 | l.append((mf, fn, params)) | |
696 | self.filterpats[filter] = l |
|
696 | self.filterpats[filter] = l | |
697 | return self.filterpats[filter] |
|
697 | return self.filterpats[filter] | |
698 |
|
698 | |||
699 | def _filter(self, filterpats, filename, data): |
|
699 | def _filter(self, filterpats, filename, data): | |
700 | for mf, fn, cmd in filterpats: |
|
700 | for mf, fn, cmd in filterpats: | |
701 | if mf(filename): |
|
701 | if mf(filename): | |
702 | self.ui.debug("filtering %s through %s\n" % (filename, cmd)) |
|
702 | self.ui.debug("filtering %s through %s\n" % (filename, cmd)) | |
703 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) |
|
703 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) | |
704 | break |
|
704 | break | |
705 |
|
705 | |||
706 | return data |
|
706 | return data | |
707 |
|
707 | |||
708 | @propertycache |
|
708 | @propertycache | |
709 | def _encodefilterpats(self): |
|
709 | def _encodefilterpats(self): | |
710 | return self._loadfilter('encode') |
|
710 | return self._loadfilter('encode') | |
711 |
|
711 | |||
712 | @propertycache |
|
712 | @propertycache | |
713 | def _decodefilterpats(self): |
|
713 | def _decodefilterpats(self): | |
714 | return self._loadfilter('decode') |
|
714 | return self._loadfilter('decode') | |
715 |
|
715 | |||
716 | def adddatafilter(self, name, filter): |
|
716 | def adddatafilter(self, name, filter): | |
717 | self._datafilters[name] = filter |
|
717 | self._datafilters[name] = filter | |
718 |
|
718 | |||
719 | def wread(self, filename): |
|
719 | def wread(self, filename): | |
720 | if self._link(filename): |
|
720 | if self._link(filename): | |
721 | data = os.readlink(self.wjoin(filename)) |
|
721 | data = os.readlink(self.wjoin(filename)) | |
722 | else: |
|
722 | else: | |
723 | data = self.wopener.read(filename) |
|
723 | data = self.wopener.read(filename) | |
724 | return self._filter(self._encodefilterpats, filename, data) |
|
724 | return self._filter(self._encodefilterpats, filename, data) | |
725 |
|
725 | |||
726 | def wwrite(self, filename, data, flags): |
|
726 | def wwrite(self, filename, data, flags): | |
727 | data = self._filter(self._decodefilterpats, filename, data) |
|
727 | data = self._filter(self._decodefilterpats, filename, data) | |
728 | if 'l' in flags: |
|
728 | if 'l' in flags: | |
729 | self.wopener.symlink(data, filename) |
|
729 | self.wopener.symlink(data, filename) | |
730 | else: |
|
730 | else: | |
731 | self.wopener.write(filename, data) |
|
731 | self.wopener.write(filename, data) | |
732 | if 'x' in flags: |
|
732 | if 'x' in flags: | |
733 | util.setflags(self.wjoin(filename), False, True) |
|
733 | util.setflags(self.wjoin(filename), False, True) | |
734 |
|
734 | |||
735 | def wwritedata(self, filename, data): |
|
735 | def wwritedata(self, filename, data): | |
736 | return self._filter(self._decodefilterpats, filename, data) |
|
736 | return self._filter(self._decodefilterpats, filename, data) | |
737 |
|
737 | |||
738 | def transaction(self, desc): |
|
738 | def transaction(self, desc): | |
739 | tr = self._transref and self._transref() or None |
|
739 | tr = self._transref and self._transref() or None | |
740 | if tr and tr.running(): |
|
740 | if tr and tr.running(): | |
741 | return tr.nest() |
|
741 | return tr.nest() | |
742 |
|
742 | |||
743 | # abort here if the journal already exists |
|
743 | # abort here if the journal already exists | |
744 | if os.path.exists(self.sjoin("journal")): |
|
744 | if os.path.exists(self.sjoin("journal")): | |
745 | raise error.RepoError( |
|
745 | raise error.RepoError( | |
746 | _("abandoned transaction found - run hg recover")) |
|
746 | _("abandoned transaction found - run hg recover")) | |
747 |
|
747 | |||
748 | journalfiles = self._writejournal(desc) |
|
748 | journalfiles = self._writejournal(desc) | |
749 | renames = [(x, undoname(x)) for x in journalfiles] |
|
749 | renames = [(x, undoname(x)) for x in journalfiles] | |
750 |
|
750 | |||
751 | tr = transaction.transaction(self.ui.warn, self.sopener, |
|
751 | tr = transaction.transaction(self.ui.warn, self.sopener, | |
752 | self.sjoin("journal"), |
|
752 | self.sjoin("journal"), | |
753 | aftertrans(renames), |
|
753 | aftertrans(renames), | |
754 | self.store.createmode) |
|
754 | self.store.createmode) | |
755 | self._transref = weakref.ref(tr) |
|
755 | self._transref = weakref.ref(tr) | |
756 | return tr |
|
756 | return tr | |
757 |
|
757 | |||
758 | def _writejournal(self, desc): |
|
758 | def _writejournal(self, desc): | |
759 | # save dirstate for rollback |
|
759 | # save dirstate for rollback | |
760 | try: |
|
760 | try: | |
761 | ds = self.opener.read("dirstate") |
|
761 | ds = self.opener.read("dirstate") | |
762 | except IOError: |
|
762 | except IOError: | |
763 | ds = "" |
|
763 | ds = "" | |
764 | self.opener.write("journal.dirstate", ds) |
|
764 | self.opener.write("journal.dirstate", ds) | |
765 | self.opener.write("journal.branch", |
|
765 | self.opener.write("journal.branch", | |
766 | encoding.fromlocal(self.dirstate.branch())) |
|
766 | encoding.fromlocal(self.dirstate.branch())) | |
767 | self.opener.write("journal.desc", |
|
767 | self.opener.write("journal.desc", | |
768 | "%d\n%s\n" % (len(self), desc)) |
|
768 | "%d\n%s\n" % (len(self), desc)) | |
769 |
|
769 | |||
770 | bkname = self.join('bookmarks') |
|
770 | bkname = self.join('bookmarks') | |
771 | if os.path.exists(bkname): |
|
771 | if os.path.exists(bkname): | |
772 | util.copyfile(bkname, self.join('journal.bookmarks')) |
|
772 | util.copyfile(bkname, self.join('journal.bookmarks')) | |
773 | else: |
|
773 | else: | |
774 | self.opener.write('journal.bookmarks', '') |
|
774 | self.opener.write('journal.bookmarks', '') | |
775 | phasesname = self.sjoin('phaseroots') |
|
775 | phasesname = self.sjoin('phaseroots') | |
776 | if os.path.exists(phasesname): |
|
776 | if os.path.exists(phasesname): | |
777 | util.copyfile(phasesname, self.sjoin('journal.phaseroots')) |
|
777 | util.copyfile(phasesname, self.sjoin('journal.phaseroots')) | |
778 | else: |
|
778 | else: | |
779 | self.sopener.write('journal.phaseroots', '') |
|
779 | self.sopener.write('journal.phaseroots', '') | |
780 |
|
780 | |||
781 | return (self.sjoin('journal'), self.join('journal.dirstate'), |
|
781 | return (self.sjoin('journal'), self.join('journal.dirstate'), | |
782 | self.join('journal.branch'), self.join('journal.desc'), |
|
782 | self.join('journal.branch'), self.join('journal.desc'), | |
783 | self.join('journal.bookmarks'), |
|
783 | self.join('journal.bookmarks'), | |
784 | self.sjoin('journal.phaseroots')) |
|
784 | self.sjoin('journal.phaseroots')) | |
785 |
|
785 | |||
786 | def recover(self): |
|
786 | def recover(self): | |
787 | lock = self.lock() |
|
787 | lock = self.lock() | |
788 | try: |
|
788 | try: | |
789 | if os.path.exists(self.sjoin("journal")): |
|
789 | if os.path.exists(self.sjoin("journal")): | |
790 | self.ui.status(_("rolling back interrupted transaction\n")) |
|
790 | self.ui.status(_("rolling back interrupted transaction\n")) | |
791 | transaction.rollback(self.sopener, self.sjoin("journal"), |
|
791 | transaction.rollback(self.sopener, self.sjoin("journal"), | |
792 | self.ui.warn) |
|
792 | self.ui.warn) | |
793 | self.invalidate() |
|
793 | self.invalidate() | |
794 | return True |
|
794 | return True | |
795 | else: |
|
795 | else: | |
796 | self.ui.warn(_("no interrupted transaction available\n")) |
|
796 | self.ui.warn(_("no interrupted transaction available\n")) | |
797 | return False |
|
797 | return False | |
798 | finally: |
|
798 | finally: | |
799 | lock.release() |
|
799 | lock.release() | |
800 |
|
800 | |||
801 | def rollback(self, dryrun=False, force=False): |
|
801 | def rollback(self, dryrun=False, force=False): | |
802 | wlock = lock = None |
|
802 | wlock = lock = None | |
803 | try: |
|
803 | try: | |
804 | wlock = self.wlock() |
|
804 | wlock = self.wlock() | |
805 | lock = self.lock() |
|
805 | lock = self.lock() | |
806 | if os.path.exists(self.sjoin("undo")): |
|
806 | if os.path.exists(self.sjoin("undo")): | |
807 | return self._rollback(dryrun, force) |
|
807 | return self._rollback(dryrun, force) | |
808 | else: |
|
808 | else: | |
809 | self.ui.warn(_("no rollback information available\n")) |
|
809 | self.ui.warn(_("no rollback information available\n")) | |
810 | return 1 |
|
810 | return 1 | |
811 | finally: |
|
811 | finally: | |
812 | release(lock, wlock) |
|
812 | release(lock, wlock) | |
813 |
|
813 | |||
814 | def _rollback(self, dryrun, force): |
|
814 | def _rollback(self, dryrun, force): | |
815 | ui = self.ui |
|
815 | ui = self.ui | |
816 | try: |
|
816 | try: | |
817 | args = self.opener.read('undo.desc').splitlines() |
|
817 | args = self.opener.read('undo.desc').splitlines() | |
818 | (oldlen, desc, detail) = (int(args[0]), args[1], None) |
|
818 | (oldlen, desc, detail) = (int(args[0]), args[1], None) | |
819 | if len(args) >= 3: |
|
819 | if len(args) >= 3: | |
820 | detail = args[2] |
|
820 | detail = args[2] | |
821 | oldtip = oldlen - 1 |
|
821 | oldtip = oldlen - 1 | |
822 |
|
822 | |||
823 | if detail and ui.verbose: |
|
823 | if detail and ui.verbose: | |
824 | msg = (_('repository tip rolled back to revision %s' |
|
824 | msg = (_('repository tip rolled back to revision %s' | |
825 | ' (undo %s: %s)\n') |
|
825 | ' (undo %s: %s)\n') | |
826 | % (oldtip, desc, detail)) |
|
826 | % (oldtip, desc, detail)) | |
827 | else: |
|
827 | else: | |
828 | msg = (_('repository tip rolled back to revision %s' |
|
828 | msg = (_('repository tip rolled back to revision %s' | |
829 | ' (undo %s)\n') |
|
829 | ' (undo %s)\n') | |
830 | % (oldtip, desc)) |
|
830 | % (oldtip, desc)) | |
831 | except IOError: |
|
831 | except IOError: | |
832 | msg = _('rolling back unknown transaction\n') |
|
832 | msg = _('rolling back unknown transaction\n') | |
833 | desc = None |
|
833 | desc = None | |
834 |
|
834 | |||
835 | if not force and self['.'] != self['tip'] and desc == 'commit': |
|
835 | if not force and self['.'] != self['tip'] and desc == 'commit': | |
836 | raise util.Abort( |
|
836 | raise util.Abort( | |
837 | _('rollback of last commit while not checked out ' |
|
837 | _('rollback of last commit while not checked out ' | |
838 | 'may lose data'), hint=_('use -f to force')) |
|
838 | 'may lose data'), hint=_('use -f to force')) | |
839 |
|
839 | |||
840 | ui.status(msg) |
|
840 | ui.status(msg) | |
841 | if dryrun: |
|
841 | if dryrun: | |
842 | return 0 |
|
842 | return 0 | |
843 |
|
843 | |||
844 | parents = self.dirstate.parents() |
|
844 | parents = self.dirstate.parents() | |
845 | transaction.rollback(self.sopener, self.sjoin('undo'), ui.warn) |
|
845 | transaction.rollback(self.sopener, self.sjoin('undo'), ui.warn) | |
846 | if os.path.exists(self.join('undo.bookmarks')): |
|
846 | if os.path.exists(self.join('undo.bookmarks')): | |
847 | util.rename(self.join('undo.bookmarks'), |
|
847 | util.rename(self.join('undo.bookmarks'), | |
848 | self.join('bookmarks')) |
|
848 | self.join('bookmarks')) | |
849 | if os.path.exists(self.sjoin('undo.phaseroots')): |
|
849 | if os.path.exists(self.sjoin('undo.phaseroots')): | |
850 | util.rename(self.sjoin('undo.phaseroots'), |
|
850 | util.rename(self.sjoin('undo.phaseroots'), | |
851 | self.sjoin('phaseroots')) |
|
851 | self.sjoin('phaseroots')) | |
852 | self.invalidate() |
|
852 | self.invalidate() | |
853 |
|
853 | |||
854 | parentgone = (parents[0] not in self.changelog.nodemap or |
|
854 | parentgone = (parents[0] not in self.changelog.nodemap or | |
855 | parents[1] not in self.changelog.nodemap) |
|
855 | parents[1] not in self.changelog.nodemap) | |
856 | if parentgone: |
|
856 | if parentgone: | |
857 | util.rename(self.join('undo.dirstate'), self.join('dirstate')) |
|
857 | util.rename(self.join('undo.dirstate'), self.join('dirstate')) | |
858 | try: |
|
858 | try: | |
859 | branch = self.opener.read('undo.branch') |
|
859 | branch = self.opener.read('undo.branch') | |
860 | self.dirstate.setbranch(branch) |
|
860 | self.dirstate.setbranch(branch) | |
861 | except IOError: |
|
861 | except IOError: | |
862 | ui.warn(_('named branch could not be reset: ' |
|
862 | ui.warn(_('named branch could not be reset: ' | |
863 | 'current branch is still \'%s\'\n') |
|
863 | 'current branch is still \'%s\'\n') | |
864 | % self.dirstate.branch()) |
|
864 | % self.dirstate.branch()) | |
865 |
|
865 | |||
866 | self.dirstate.invalidate() |
|
866 | self.dirstate.invalidate() | |
867 | parents = tuple([p.rev() for p in self.parents()]) |
|
867 | parents = tuple([p.rev() for p in self.parents()]) | |
868 | if len(parents) > 1: |
|
868 | if len(parents) > 1: | |
869 | ui.status(_('working directory now based on ' |
|
869 | ui.status(_('working directory now based on ' | |
870 | 'revisions %d and %d\n') % parents) |
|
870 | 'revisions %d and %d\n') % parents) | |
871 | else: |
|
871 | else: | |
872 | ui.status(_('working directory now based on ' |
|
872 | ui.status(_('working directory now based on ' | |
873 | 'revision %d\n') % parents) |
|
873 | 'revision %d\n') % parents) | |
874 | self.destroyed() |
|
874 | self.destroyed() | |
875 | return 0 |
|
875 | return 0 | |
876 |
|
876 | |||
877 | def invalidatecaches(self): |
|
877 | def invalidatecaches(self): | |
878 | def delcache(name): |
|
878 | def delcache(name): | |
879 | try: |
|
879 | try: | |
880 | delattr(self, name) |
|
880 | delattr(self, name) | |
881 | except AttributeError: |
|
881 | except AttributeError: | |
882 | pass |
|
882 | pass | |
883 |
|
883 | |||
884 | delcache('_tagscache') |
|
884 | delcache('_tagscache') | |
885 | delcache('_phaserev') |
|
885 | delcache('_phaserev') | |
886 |
|
886 | |||
887 | self._branchcache = None # in UTF-8 |
|
887 | self._branchcache = None # in UTF-8 | |
888 | self._branchcachetip = None |
|
888 | self._branchcachetip = None | |
889 |
|
889 | |||
890 | def invalidatedirstate(self): |
|
890 | def invalidatedirstate(self): | |
891 | '''Invalidates the dirstate, causing the next call to dirstate |
|
891 | '''Invalidates the dirstate, causing the next call to dirstate | |
892 | to check if it was modified since the last time it was read, |
|
892 | to check if it was modified since the last time it was read, | |
893 | rereading it if it has. |
|
893 | rereading it if it has. | |
894 |
|
894 | |||
895 | This is different to dirstate.invalidate() that it doesn't always |
|
895 | This is different to dirstate.invalidate() that it doesn't always | |
896 | rereads the dirstate. Use dirstate.invalidate() if you want to |
|
896 | rereads the dirstate. Use dirstate.invalidate() if you want to | |
897 | explicitly read the dirstate again (i.e. restoring it to a previous |
|
897 | explicitly read the dirstate again (i.e. restoring it to a previous | |
898 | known good state).''' |
|
898 | known good state).''' | |
899 | try: |
|
899 | try: | |
900 | delattr(self, 'dirstate') |
|
900 | delattr(self, 'dirstate') | |
901 | except AttributeError: |
|
901 | except AttributeError: | |
902 | pass |
|
902 | pass | |
903 |
|
903 | |||
904 | def invalidate(self): |
|
904 | def invalidate(self): | |
905 | for k in self._filecache: |
|
905 | for k in self._filecache: | |
906 | # dirstate is invalidated separately in invalidatedirstate() |
|
906 | # dirstate is invalidated separately in invalidatedirstate() | |
907 | if k == 'dirstate': |
|
907 | if k == 'dirstate': | |
908 | continue |
|
908 | continue | |
909 |
|
909 | |||
910 | try: |
|
910 | try: | |
911 | delattr(self, k) |
|
911 | delattr(self, k) | |
912 | except AttributeError: |
|
912 | except AttributeError: | |
913 | pass |
|
913 | pass | |
914 | self.invalidatecaches() |
|
914 | self.invalidatecaches() | |
915 |
|
915 | |||
916 | def _lock(self, lockname, wait, releasefn, acquirefn, desc): |
|
916 | def _lock(self, lockname, wait, releasefn, acquirefn, desc): | |
917 | try: |
|
917 | try: | |
918 | l = lock.lock(lockname, 0, releasefn, desc=desc) |
|
918 | l = lock.lock(lockname, 0, releasefn, desc=desc) | |
919 | except error.LockHeld, inst: |
|
919 | except error.LockHeld, inst: | |
920 | if not wait: |
|
920 | if not wait: | |
921 | raise |
|
921 | raise | |
922 | self.ui.warn(_("waiting for lock on %s held by %r\n") % |
|
922 | self.ui.warn(_("waiting for lock on %s held by %r\n") % | |
923 | (desc, inst.locker)) |
|
923 | (desc, inst.locker)) | |
924 | # default to 600 seconds timeout |
|
924 | # default to 600 seconds timeout | |
925 | l = lock.lock(lockname, int(self.ui.config("ui", "timeout", "600")), |
|
925 | l = lock.lock(lockname, int(self.ui.config("ui", "timeout", "600")), | |
926 | releasefn, desc=desc) |
|
926 | releasefn, desc=desc) | |
927 | if acquirefn: |
|
927 | if acquirefn: | |
928 | acquirefn() |
|
928 | acquirefn() | |
929 | return l |
|
929 | return l | |
930 |
|
930 | |||
931 | def _afterlock(self, callback): |
|
931 | def _afterlock(self, callback): | |
932 | """add a callback to the current repository lock. |
|
932 | """add a callback to the current repository lock. | |
933 |
|
933 | |||
934 | The callback will be executed on lock release.""" |
|
934 | The callback will be executed on lock release.""" | |
935 | l = self._lockref and self._lockref() |
|
935 | l = self._lockref and self._lockref() | |
936 | if l: |
|
936 | if l: | |
937 | l.postrelease.append(callback) |
|
937 | l.postrelease.append(callback) | |
938 |
|
938 | |||
939 | def lock(self, wait=True): |
|
939 | def lock(self, wait=True): | |
940 | '''Lock the repository store (.hg/store) and return a weak reference |
|
940 | '''Lock the repository store (.hg/store) and return a weak reference | |
941 | to the lock. Use this before modifying the store (e.g. committing or |
|
941 | to the lock. Use this before modifying the store (e.g. committing or | |
942 | stripping). If you are opening a transaction, get a lock as well.)''' |
|
942 | stripping). If you are opening a transaction, get a lock as well.)''' | |
943 | l = self._lockref and self._lockref() |
|
943 | l = self._lockref and self._lockref() | |
944 | if l is not None and l.held: |
|
944 | if l is not None and l.held: | |
945 | l.lock() |
|
945 | l.lock() | |
946 | return l |
|
946 | return l | |
947 |
|
947 | |||
948 | def unlock(): |
|
948 | def unlock(): | |
949 | self.store.write() |
|
949 | self.store.write() | |
950 | if self._dirtyphases: |
|
950 | if self._dirtyphases: | |
951 | phases.writeroots(self) |
|
951 | phases.writeroots(self) | |
952 | self._dirtyphases = False |
|
952 | self._dirtyphases = False | |
953 | for k, ce in self._filecache.items(): |
|
953 | for k, ce in self._filecache.items(): | |
954 | if k == 'dirstate': |
|
954 | if k == 'dirstate': | |
955 | continue |
|
955 | continue | |
956 | ce.refresh() |
|
956 | ce.refresh() | |
957 |
|
957 | |||
958 | l = self._lock(self.sjoin("lock"), wait, unlock, |
|
958 | l = self._lock(self.sjoin("lock"), wait, unlock, | |
959 | self.invalidate, _('repository %s') % self.origroot) |
|
959 | self.invalidate, _('repository %s') % self.origroot) | |
960 | self._lockref = weakref.ref(l) |
|
960 | self._lockref = weakref.ref(l) | |
961 | return l |
|
961 | return l | |
962 |
|
962 | |||
963 | def wlock(self, wait=True): |
|
963 | def wlock(self, wait=True): | |
964 | '''Lock the non-store parts of the repository (everything under |
|
964 | '''Lock the non-store parts of the repository (everything under | |
965 | .hg except .hg/store) and return a weak reference to the lock. |
|
965 | .hg except .hg/store) and return a weak reference to the lock. | |
966 | Use this before modifying files in .hg.''' |
|
966 | Use this before modifying files in .hg.''' | |
967 | l = self._wlockref and self._wlockref() |
|
967 | l = self._wlockref and self._wlockref() | |
968 | if l is not None and l.held: |
|
968 | if l is not None and l.held: | |
969 | l.lock() |
|
969 | l.lock() | |
970 | return l |
|
970 | return l | |
971 |
|
971 | |||
972 | def unlock(): |
|
972 | def unlock(): | |
973 | self.dirstate.write() |
|
973 | self.dirstate.write() | |
974 | ce = self._filecache.get('dirstate') |
|
974 | ce = self._filecache.get('dirstate') | |
975 | if ce: |
|
975 | if ce: | |
976 | ce.refresh() |
|
976 | ce.refresh() | |
977 |
|
977 | |||
978 | l = self._lock(self.join("wlock"), wait, unlock, |
|
978 | l = self._lock(self.join("wlock"), wait, unlock, | |
979 | self.invalidatedirstate, _('working directory of %s') % |
|
979 | self.invalidatedirstate, _('working directory of %s') % | |
980 | self.origroot) |
|
980 | self.origroot) | |
981 | self._wlockref = weakref.ref(l) |
|
981 | self._wlockref = weakref.ref(l) | |
982 | return l |
|
982 | return l | |
983 |
|
983 | |||
984 | def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist): |
|
984 | def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist): | |
985 | """ |
|
985 | """ | |
986 | commit an individual file as part of a larger transaction |
|
986 | commit an individual file as part of a larger transaction | |
987 | """ |
|
987 | """ | |
988 |
|
988 | |||
989 | fname = fctx.path() |
|
989 | fname = fctx.path() | |
990 | text = fctx.data() |
|
990 | text = fctx.data() | |
991 | flog = self.file(fname) |
|
991 | flog = self.file(fname) | |
992 | fparent1 = manifest1.get(fname, nullid) |
|
992 | fparent1 = manifest1.get(fname, nullid) | |
993 | fparent2 = fparent2o = manifest2.get(fname, nullid) |
|
993 | fparent2 = fparent2o = manifest2.get(fname, nullid) | |
994 |
|
994 | |||
995 | meta = {} |
|
995 | meta = {} | |
996 | copy = fctx.renamed() |
|
996 | copy = fctx.renamed() | |
997 | if copy and copy[0] != fname: |
|
997 | if copy and copy[0] != fname: | |
998 | # Mark the new revision of this file as a copy of another |
|
998 | # Mark the new revision of this file as a copy of another | |
999 | # file. This copy data will effectively act as a parent |
|
999 | # file. This copy data will effectively act as a parent | |
1000 | # of this new revision. If this is a merge, the first |
|
1000 | # of this new revision. If this is a merge, the first | |
1001 | # parent will be the nullid (meaning "look up the copy data") |
|
1001 | # parent will be the nullid (meaning "look up the copy data") | |
1002 | # and the second one will be the other parent. For example: |
|
1002 | # and the second one will be the other parent. For example: | |
1003 | # |
|
1003 | # | |
1004 | # 0 --- 1 --- 3 rev1 changes file foo |
|
1004 | # 0 --- 1 --- 3 rev1 changes file foo | |
1005 | # \ / rev2 renames foo to bar and changes it |
|
1005 | # \ / rev2 renames foo to bar and changes it | |
1006 | # \- 2 -/ rev3 should have bar with all changes and |
|
1006 | # \- 2 -/ rev3 should have bar with all changes and | |
1007 | # should record that bar descends from |
|
1007 | # should record that bar descends from | |
1008 | # bar in rev2 and foo in rev1 |
|
1008 | # bar in rev2 and foo in rev1 | |
1009 | # |
|
1009 | # | |
1010 | # this allows this merge to succeed: |
|
1010 | # this allows this merge to succeed: | |
1011 | # |
|
1011 | # | |
1012 | # 0 --- 1 --- 3 rev4 reverts the content change from rev2 |
|
1012 | # 0 --- 1 --- 3 rev4 reverts the content change from rev2 | |
1013 | # \ / merging rev3 and rev4 should use bar@rev2 |
|
1013 | # \ / merging rev3 and rev4 should use bar@rev2 | |
1014 | # \- 2 --- 4 as the merge base |
|
1014 | # \- 2 --- 4 as the merge base | |
1015 | # |
|
1015 | # | |
1016 |
|
1016 | |||
1017 | cfname = copy[0] |
|
1017 | cfname = copy[0] | |
1018 | crev = manifest1.get(cfname) |
|
1018 | crev = manifest1.get(cfname) | |
1019 | newfparent = fparent2 |
|
1019 | newfparent = fparent2 | |
1020 |
|
1020 | |||
1021 | if manifest2: # branch merge |
|
1021 | if manifest2: # branch merge | |
1022 | if fparent2 == nullid or crev is None: # copied on remote side |
|
1022 | if fparent2 == nullid or crev is None: # copied on remote side | |
1023 | if cfname in manifest2: |
|
1023 | if cfname in manifest2: | |
1024 | crev = manifest2[cfname] |
|
1024 | crev = manifest2[cfname] | |
1025 | newfparent = fparent1 |
|
1025 | newfparent = fparent1 | |
1026 |
|
1026 | |||
1027 | # find source in nearest ancestor if we've lost track |
|
1027 | # find source in nearest ancestor if we've lost track | |
1028 | if not crev: |
|
1028 | if not crev: | |
1029 | self.ui.debug(" %s: searching for copy revision for %s\n" % |
|
1029 | self.ui.debug(" %s: searching for copy revision for %s\n" % | |
1030 | (fname, cfname)) |
|
1030 | (fname, cfname)) | |
1031 | for ancestor in self[None].ancestors(): |
|
1031 | for ancestor in self[None].ancestors(): | |
1032 | if cfname in ancestor: |
|
1032 | if cfname in ancestor: | |
1033 | crev = ancestor[cfname].filenode() |
|
1033 | crev = ancestor[cfname].filenode() | |
1034 | break |
|
1034 | break | |
1035 |
|
1035 | |||
1036 | if crev: |
|
1036 | if crev: | |
1037 | self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(crev))) |
|
1037 | self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(crev))) | |
1038 | meta["copy"] = cfname |
|
1038 | meta["copy"] = cfname | |
1039 | meta["copyrev"] = hex(crev) |
|
1039 | meta["copyrev"] = hex(crev) | |
1040 | fparent1, fparent2 = nullid, newfparent |
|
1040 | fparent1, fparent2 = nullid, newfparent | |
1041 | else: |
|
1041 | else: | |
1042 | self.ui.warn(_("warning: can't find ancestor for '%s' " |
|
1042 | self.ui.warn(_("warning: can't find ancestor for '%s' " | |
1043 | "copied from '%s'!\n") % (fname, cfname)) |
|
1043 | "copied from '%s'!\n") % (fname, cfname)) | |
1044 |
|
1044 | |||
1045 | elif fparent2 != nullid: |
|
1045 | elif fparent2 != nullid: | |
1046 | # is one parent an ancestor of the other? |
|
1046 | # is one parent an ancestor of the other? | |
1047 | fparentancestor = flog.ancestor(fparent1, fparent2) |
|
1047 | fparentancestor = flog.ancestor(fparent1, fparent2) | |
1048 | if fparentancestor == fparent1: |
|
1048 | if fparentancestor == fparent1: | |
1049 | fparent1, fparent2 = fparent2, nullid |
|
1049 | fparent1, fparent2 = fparent2, nullid | |
1050 | elif fparentancestor == fparent2: |
|
1050 | elif fparentancestor == fparent2: | |
1051 | fparent2 = nullid |
|
1051 | fparent2 = nullid | |
1052 |
|
1052 | |||
1053 | # is the file changed? |
|
1053 | # is the file changed? | |
1054 | if fparent2 != nullid or flog.cmp(fparent1, text) or meta: |
|
1054 | if fparent2 != nullid or flog.cmp(fparent1, text) or meta: | |
1055 | changelist.append(fname) |
|
1055 | changelist.append(fname) | |
1056 | return flog.add(text, meta, tr, linkrev, fparent1, fparent2) |
|
1056 | return flog.add(text, meta, tr, linkrev, fparent1, fparent2) | |
1057 |
|
1057 | |||
1058 | # are just the flags changed during merge? |
|
1058 | # are just the flags changed during merge? | |
1059 | if fparent1 != fparent2o and manifest1.flags(fname) != fctx.flags(): |
|
1059 | if fparent1 != fparent2o and manifest1.flags(fname) != fctx.flags(): | |
1060 | changelist.append(fname) |
|
1060 | changelist.append(fname) | |
1061 |
|
1061 | |||
1062 | return fparent1 |
|
1062 | return fparent1 | |
1063 |
|
1063 | |||
1064 | def commit(self, text="", user=None, date=None, match=None, force=False, |
|
1064 | def commit(self, text="", user=None, date=None, match=None, force=False, | |
1065 | editor=False, extra={}): |
|
1065 | editor=False, extra={}): | |
1066 | """Add a new revision to current repository. |
|
1066 | """Add a new revision to current repository. | |
1067 |
|
1067 | |||
1068 | Revision information is gathered from the working directory, |
|
1068 | Revision information is gathered from the working directory, | |
1069 | match can be used to filter the committed files. If editor is |
|
1069 | match can be used to filter the committed files. If editor is | |
1070 | supplied, it is called to get a commit message. |
|
1070 | supplied, it is called to get a commit message. | |
1071 | """ |
|
1071 | """ | |
1072 |
|
1072 | |||
1073 | def fail(f, msg): |
|
1073 | def fail(f, msg): | |
1074 | raise util.Abort('%s: %s' % (f, msg)) |
|
1074 | raise util.Abort('%s: %s' % (f, msg)) | |
1075 |
|
1075 | |||
1076 | if not match: |
|
1076 | if not match: | |
1077 | match = matchmod.always(self.root, '') |
|
1077 | match = matchmod.always(self.root, '') | |
1078 |
|
1078 | |||
1079 | if not force: |
|
1079 | if not force: | |
1080 | vdirs = [] |
|
1080 | vdirs = [] | |
1081 | match.dir = vdirs.append |
|
1081 | match.dir = vdirs.append | |
1082 | match.bad = fail |
|
1082 | match.bad = fail | |
1083 |
|
1083 | |||
1084 | wlock = self.wlock() |
|
1084 | wlock = self.wlock() | |
1085 | try: |
|
1085 | try: | |
1086 | wctx = self[None] |
|
1086 | wctx = self[None] | |
1087 | merge = len(wctx.parents()) > 1 |
|
1087 | merge = len(wctx.parents()) > 1 | |
1088 |
|
1088 | |||
1089 | if (not force and merge and match and |
|
1089 | if (not force and merge and match and | |
1090 | (match.files() or match.anypats())): |
|
1090 | (match.files() or match.anypats())): | |
1091 | raise util.Abort(_('cannot partially commit a merge ' |
|
1091 | raise util.Abort(_('cannot partially commit a merge ' | |
1092 | '(do not specify files or patterns)')) |
|
1092 | '(do not specify files or patterns)')) | |
1093 |
|
1093 | |||
1094 | changes = self.status(match=match, clean=force) |
|
1094 | changes = self.status(match=match, clean=force) | |
1095 | if force: |
|
1095 | if force: | |
1096 | changes[0].extend(changes[6]) # mq may commit unchanged files |
|
1096 | changes[0].extend(changes[6]) # mq may commit unchanged files | |
1097 |
|
1097 | |||
1098 | # check subrepos |
|
1098 | # check subrepos | |
1099 | subs = [] |
|
1099 | subs = [] | |
1100 | removedsubs = set() |
|
1100 | removedsubs = set() | |
1101 | if '.hgsub' in wctx: |
|
1101 | if '.hgsub' in wctx: | |
1102 | # only manage subrepos and .hgsubstate if .hgsub is present |
|
1102 | # only manage subrepos and .hgsubstate if .hgsub is present | |
1103 | for p in wctx.parents(): |
|
1103 | for p in wctx.parents(): | |
1104 | removedsubs.update(s for s in p.substate if match(s)) |
|
1104 | removedsubs.update(s for s in p.substate if match(s)) | |
1105 | for s in wctx.substate: |
|
1105 | for s in wctx.substate: | |
1106 | removedsubs.discard(s) |
|
1106 | removedsubs.discard(s) | |
1107 | if match(s) and wctx.sub(s).dirty(): |
|
1107 | if match(s) and wctx.sub(s).dirty(): | |
1108 | subs.append(s) |
|
1108 | subs.append(s) | |
1109 | if (subs or removedsubs): |
|
1109 | if (subs or removedsubs): | |
1110 | if (not match('.hgsub') and |
|
1110 | if (not match('.hgsub') and | |
1111 | '.hgsub' in (wctx.modified() + wctx.added())): |
|
1111 | '.hgsub' in (wctx.modified() + wctx.added())): | |
1112 | raise util.Abort( |
|
1112 | raise util.Abort( | |
1113 | _("can't commit subrepos without .hgsub")) |
|
1113 | _("can't commit subrepos without .hgsub")) | |
1114 | if '.hgsubstate' not in changes[0]: |
|
1114 | if '.hgsubstate' not in changes[0]: | |
1115 | changes[0].insert(0, '.hgsubstate') |
|
1115 | changes[0].insert(0, '.hgsubstate') | |
1116 | if '.hgsubstate' in changes[2]: |
|
1116 | if '.hgsubstate' in changes[2]: | |
1117 | changes[2].remove('.hgsubstate') |
|
1117 | changes[2].remove('.hgsubstate') | |
1118 | elif '.hgsub' in changes[2]: |
|
1118 | elif '.hgsub' in changes[2]: | |
1119 | # clean up .hgsubstate when .hgsub is removed |
|
1119 | # clean up .hgsubstate when .hgsub is removed | |
1120 | if ('.hgsubstate' in wctx and |
|
1120 | if ('.hgsubstate' in wctx and | |
1121 | '.hgsubstate' not in changes[0] + changes[1] + changes[2]): |
|
1121 | '.hgsubstate' not in changes[0] + changes[1] + changes[2]): | |
1122 | changes[2].insert(0, '.hgsubstate') |
|
1122 | changes[2].insert(0, '.hgsubstate') | |
1123 |
|
1123 | |||
1124 | if subs and not self.ui.configbool('ui', 'commitsubrepos', False): |
|
1124 | if subs and not self.ui.configbool('ui', 'commitsubrepos', False): | |
1125 | changedsubs = [s for s in subs if wctx.sub(s).dirty(True)] |
|
1125 | changedsubs = [s for s in subs if wctx.sub(s).dirty(True)] | |
1126 | if changedsubs: |
|
1126 | if changedsubs: | |
1127 | raise util.Abort(_("uncommitted changes in subrepo %s") |
|
1127 | raise util.Abort(_("uncommitted changes in subrepo %s") | |
1128 | % changedsubs[0], |
|
1128 | % changedsubs[0], | |
1129 | hint=_("use --subrepos for recursive commit")) |
|
1129 | hint=_("use --subrepos for recursive commit")) | |
1130 |
|
1130 | |||
1131 | # make sure all explicit patterns are matched |
|
1131 | # make sure all explicit patterns are matched | |
1132 | if not force and match.files(): |
|
1132 | if not force and match.files(): | |
1133 | matched = set(changes[0] + changes[1] + changes[2]) |
|
1133 | matched = set(changes[0] + changes[1] + changes[2]) | |
1134 |
|
1134 | |||
1135 | for f in match.files(): |
|
1135 | for f in match.files(): | |
1136 | if f == '.' or f in matched or f in wctx.substate: |
|
1136 | if f == '.' or f in matched or f in wctx.substate: | |
1137 | continue |
|
1137 | continue | |
1138 | if f in changes[3]: # missing |
|
1138 | if f in changes[3]: # missing | |
1139 | fail(f, _('file not found!')) |
|
1139 | fail(f, _('file not found!')) | |
1140 | if f in vdirs: # visited directory |
|
1140 | if f in vdirs: # visited directory | |
1141 | d = f + '/' |
|
1141 | d = f + '/' | |
1142 | for mf in matched: |
|
1142 | for mf in matched: | |
1143 | if mf.startswith(d): |
|
1143 | if mf.startswith(d): | |
1144 | break |
|
1144 | break | |
1145 | else: |
|
1145 | else: | |
1146 | fail(f, _("no match under directory!")) |
|
1146 | fail(f, _("no match under directory!")) | |
1147 | elif f not in self.dirstate: |
|
1147 | elif f not in self.dirstate: | |
1148 | fail(f, _("file not tracked!")) |
|
1148 | fail(f, _("file not tracked!")) | |
1149 |
|
1149 | |||
1150 | if (not force and not extra.get("close") and not merge |
|
1150 | if (not force and not extra.get("close") and not merge | |
1151 | and not (changes[0] or changes[1] or changes[2]) |
|
1151 | and not (changes[0] or changes[1] or changes[2]) | |
1152 | and wctx.branch() == wctx.p1().branch()): |
|
1152 | and wctx.branch() == wctx.p1().branch()): | |
1153 | return None |
|
1153 | return None | |
1154 |
|
1154 | |||
1155 | ms = mergemod.mergestate(self) |
|
1155 | ms = mergemod.mergestate(self) | |
1156 | for f in changes[0]: |
|
1156 | for f in changes[0]: | |
1157 | if f in ms and ms[f] == 'u': |
|
1157 | if f in ms and ms[f] == 'u': | |
1158 | raise util.Abort(_("unresolved merge conflicts " |
|
1158 | raise util.Abort(_("unresolved merge conflicts " | |
1159 | "(see hg help resolve)")) |
|
1159 | "(see hg help resolve)")) | |
1160 |
|
1160 | |||
1161 | cctx = context.workingctx(self, text, user, date, extra, changes) |
|
1161 | cctx = context.workingctx(self, text, user, date, extra, changes) | |
1162 | if editor: |
|
1162 | if editor: | |
1163 | cctx._text = editor(self, cctx, subs) |
|
1163 | cctx._text = editor(self, cctx, subs) | |
1164 | edited = (text != cctx._text) |
|
1164 | edited = (text != cctx._text) | |
1165 |
|
1165 | |||
1166 | # commit subs |
|
1166 | # commit subs | |
1167 | if subs or removedsubs: |
|
1167 | if subs or removedsubs: | |
1168 | state = wctx.substate.copy() |
|
1168 | state = wctx.substate.copy() | |
1169 | for s in sorted(subs): |
|
1169 | for s in sorted(subs): | |
1170 | sub = wctx.sub(s) |
|
1170 | sub = wctx.sub(s) | |
1171 | self.ui.status(_('committing subrepository %s\n') % |
|
1171 | self.ui.status(_('committing subrepository %s\n') % | |
1172 | subrepo.subrelpath(sub)) |
|
1172 | subrepo.subrelpath(sub)) | |
1173 | sr = sub.commit(cctx._text, user, date) |
|
1173 | sr = sub.commit(cctx._text, user, date) | |
1174 | state[s] = (state[s][0], sr) |
|
1174 | state[s] = (state[s][0], sr) | |
1175 | subrepo.writestate(self, state) |
|
1175 | subrepo.writestate(self, state) | |
1176 |
|
1176 | |||
1177 | # Save commit message in case this transaction gets rolled back |
|
1177 | # Save commit message in case this transaction gets rolled back | |
1178 | # (e.g. by a pretxncommit hook). Leave the content alone on |
|
1178 | # (e.g. by a pretxncommit hook). Leave the content alone on | |
1179 | # the assumption that the user will use the same editor again. |
|
1179 | # the assumption that the user will use the same editor again. | |
1180 | msgfn = self.savecommitmessage(cctx._text) |
|
1180 | msgfn = self.savecommitmessage(cctx._text) | |
1181 |
|
1181 | |||
1182 | p1, p2 = self.dirstate.parents() |
|
1182 | p1, p2 = self.dirstate.parents() | |
1183 | hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '') |
|
1183 | hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '') | |
1184 | try: |
|
1184 | try: | |
1185 | self.hook("precommit", throw=True, parent1=hookp1, parent2=hookp2) |
|
1185 | self.hook("precommit", throw=True, parent1=hookp1, parent2=hookp2) | |
1186 | ret = self.commitctx(cctx, True) |
|
1186 | ret = self.commitctx(cctx, True) | |
1187 | except: |
|
1187 | except: | |
1188 | if edited: |
|
1188 | if edited: | |
1189 | self.ui.write( |
|
1189 | self.ui.write( | |
1190 | _('note: commit message saved in %s\n') % msgfn) |
|
1190 | _('note: commit message saved in %s\n') % msgfn) | |
1191 | raise |
|
1191 | raise | |
1192 |
|
1192 | |||
1193 | # update bookmarks, dirstate and mergestate |
|
1193 | # update bookmarks, dirstate and mergestate | |
1194 | bookmarks.update(self, p1, ret) |
|
1194 | bookmarks.update(self, p1, ret) | |
1195 | for f in changes[0] + changes[1]: |
|
1195 | for f in changes[0] + changes[1]: | |
1196 | self.dirstate.normal(f) |
|
1196 | self.dirstate.normal(f) | |
1197 | for f in changes[2]: |
|
1197 | for f in changes[2]: | |
1198 | self.dirstate.drop(f) |
|
1198 | self.dirstate.drop(f) | |
1199 | self.dirstate.setparents(ret) |
|
1199 | self.dirstate.setparents(ret) | |
1200 | ms.reset() |
|
1200 | ms.reset() | |
1201 | finally: |
|
1201 | finally: | |
1202 | wlock.release() |
|
1202 | wlock.release() | |
1203 |
|
1203 | |||
1204 | self.hook("commit", node=hex(ret), parent1=hookp1, parent2=hookp2) |
|
1204 | self.hook("commit", node=hex(ret), parent1=hookp1, parent2=hookp2) | |
1205 | return ret |
|
1205 | return ret | |
1206 |
|
1206 | |||
1207 | def commitctx(self, ctx, error=False): |
|
1207 | def commitctx(self, ctx, error=False): | |
1208 | """Add a new revision to current repository. |
|
1208 | """Add a new revision to current repository. | |
1209 | Revision information is passed via the context argument. |
|
1209 | Revision information is passed via the context argument. | |
1210 | """ |
|
1210 | """ | |
1211 |
|
1211 | |||
1212 | tr = lock = None |
|
1212 | tr = lock = None | |
1213 | removed = list(ctx.removed()) |
|
1213 | removed = list(ctx.removed()) | |
1214 | p1, p2 = ctx.p1(), ctx.p2() |
|
1214 | p1, p2 = ctx.p1(), ctx.p2() | |
1215 | user = ctx.user() |
|
1215 | user = ctx.user() | |
1216 |
|
1216 | |||
1217 | lock = self.lock() |
|
1217 | lock = self.lock() | |
1218 | try: |
|
1218 | try: | |
1219 | tr = self.transaction("commit") |
|
1219 | tr = self.transaction("commit") | |
1220 | trp = weakref.proxy(tr) |
|
1220 | trp = weakref.proxy(tr) | |
1221 |
|
1221 | |||
1222 | if ctx.files(): |
|
1222 | if ctx.files(): | |
1223 | m1 = p1.manifest().copy() |
|
1223 | m1 = p1.manifest().copy() | |
1224 | m2 = p2.manifest() |
|
1224 | m2 = p2.manifest() | |
1225 |
|
1225 | |||
1226 | # check in files |
|
1226 | # check in files | |
1227 | new = {} |
|
1227 | new = {} | |
1228 | changed = [] |
|
1228 | changed = [] | |
1229 | linkrev = len(self) |
|
1229 | linkrev = len(self) | |
1230 | for f in sorted(ctx.modified() + ctx.added()): |
|
1230 | for f in sorted(ctx.modified() + ctx.added()): | |
1231 | self.ui.note(f + "\n") |
|
1231 | self.ui.note(f + "\n") | |
1232 | try: |
|
1232 | try: | |
1233 | fctx = ctx[f] |
|
1233 | fctx = ctx[f] | |
1234 | new[f] = self._filecommit(fctx, m1, m2, linkrev, trp, |
|
1234 | new[f] = self._filecommit(fctx, m1, m2, linkrev, trp, | |
1235 | changed) |
|
1235 | changed) | |
1236 | m1.set(f, fctx.flags()) |
|
1236 | m1.set(f, fctx.flags()) | |
1237 | except OSError, inst: |
|
1237 | except OSError, inst: | |
1238 | self.ui.warn(_("trouble committing %s!\n") % f) |
|
1238 | self.ui.warn(_("trouble committing %s!\n") % f) | |
1239 | raise |
|
1239 | raise | |
1240 | except IOError, inst: |
|
1240 | except IOError, inst: | |
1241 | errcode = getattr(inst, 'errno', errno.ENOENT) |
|
1241 | errcode = getattr(inst, 'errno', errno.ENOENT) | |
1242 | if error or errcode and errcode != errno.ENOENT: |
|
1242 | if error or errcode and errcode != errno.ENOENT: | |
1243 | self.ui.warn(_("trouble committing %s!\n") % f) |
|
1243 | self.ui.warn(_("trouble committing %s!\n") % f) | |
1244 | raise |
|
1244 | raise | |
1245 | else: |
|
1245 | else: | |
1246 | removed.append(f) |
|
1246 | removed.append(f) | |
1247 |
|
1247 | |||
1248 | # update manifest |
|
1248 | # update manifest | |
1249 | m1.update(new) |
|
1249 | m1.update(new) | |
1250 | removed = [f for f in sorted(removed) if f in m1 or f in m2] |
|
1250 | removed = [f for f in sorted(removed) if f in m1 or f in m2] | |
1251 | drop = [f for f in removed if f in m1] |
|
1251 | drop = [f for f in removed if f in m1] | |
1252 | for f in drop: |
|
1252 | for f in drop: | |
1253 | del m1[f] |
|
1253 | del m1[f] | |
1254 | mn = self.manifest.add(m1, trp, linkrev, p1.manifestnode(), |
|
1254 | mn = self.manifest.add(m1, trp, linkrev, p1.manifestnode(), | |
1255 | p2.manifestnode(), (new, drop)) |
|
1255 | p2.manifestnode(), (new, drop)) | |
1256 | files = changed + removed |
|
1256 | files = changed + removed | |
1257 | else: |
|
1257 | else: | |
1258 | mn = p1.manifestnode() |
|
1258 | mn = p1.manifestnode() | |
1259 | files = [] |
|
1259 | files = [] | |
1260 |
|
1260 | |||
1261 | # update changelog |
|
1261 | # update changelog | |
1262 | self.changelog.delayupdate() |
|
1262 | self.changelog.delayupdate() | |
1263 | n = self.changelog.add(mn, files, ctx.description(), |
|
1263 | n = self.changelog.add(mn, files, ctx.description(), | |
1264 | trp, p1.node(), p2.node(), |
|
1264 | trp, p1.node(), p2.node(), | |
1265 | user, ctx.date(), ctx.extra().copy()) |
|
1265 | user, ctx.date(), ctx.extra().copy()) | |
1266 | p = lambda: self.changelog.writepending() and self.root or "" |
|
1266 | p = lambda: self.changelog.writepending() and self.root or "" | |
1267 | xp1, xp2 = p1.hex(), p2 and p2.hex() or '' |
|
1267 | xp1, xp2 = p1.hex(), p2 and p2.hex() or '' | |
1268 | self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, |
|
1268 | self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, | |
1269 | parent2=xp2, pending=p) |
|
1269 | parent2=xp2, pending=p) | |
1270 | self.changelog.finalize(trp) |
|
1270 | self.changelog.finalize(trp) | |
1271 | # set the new commit is proper phase |
|
1271 | # set the new commit is proper phase | |
1272 | targetphase = phases.newcommitphase(self.ui) |
|
1272 | targetphase = phases.newcommitphase(self.ui) | |
1273 | if targetphase: |
|
1273 | if targetphase: | |
1274 | # retract boundary do not alter parent changeset. |
|
1274 | # retract boundary do not alter parent changeset. | |
1275 | # if a parent have higher the resulting phase will |
|
1275 | # if a parent have higher the resulting phase will | |
1276 | # be compliant anyway |
|
1276 | # be compliant anyway | |
1277 | # |
|
1277 | # | |
1278 | # if minimal phase was 0 we don't need to retract anything |
|
1278 | # if minimal phase was 0 we don't need to retract anything | |
1279 | phases.retractboundary(self, targetphase, [n]) |
|
1279 | phases.retractboundary(self, targetphase, [n]) | |
1280 | tr.close() |
|
1280 | tr.close() | |
1281 | self.updatebranchcache() |
|
1281 | self.updatebranchcache() | |
1282 | return n |
|
1282 | return n | |
1283 | finally: |
|
1283 | finally: | |
1284 | if tr: |
|
1284 | if tr: | |
1285 | tr.release() |
|
1285 | tr.release() | |
1286 | lock.release() |
|
1286 | lock.release() | |
1287 |
|
1287 | |||
1288 | def destroyed(self): |
|
1288 | def destroyed(self): | |
1289 | '''Inform the repository that nodes have been destroyed. |
|
1289 | '''Inform the repository that nodes have been destroyed. | |
1290 | Intended for use by strip and rollback, so there's a common |
|
1290 | Intended for use by strip and rollback, so there's a common | |
1291 | place for anything that has to be done after destroying history.''' |
|
1291 | place for anything that has to be done after destroying history.''' | |
1292 | # XXX it might be nice if we could take the list of destroyed |
|
1292 | # XXX it might be nice if we could take the list of destroyed | |
1293 | # nodes, but I don't see an easy way for rollback() to do that |
|
1293 | # nodes, but I don't see an easy way for rollback() to do that | |
1294 |
|
1294 | |||
1295 | # Ensure the persistent tag cache is updated. Doing it now |
|
1295 | # Ensure the persistent tag cache is updated. Doing it now | |
1296 | # means that the tag cache only has to worry about destroyed |
|
1296 | # means that the tag cache only has to worry about destroyed | |
1297 | # heads immediately after a strip/rollback. That in turn |
|
1297 | # heads immediately after a strip/rollback. That in turn | |
1298 | # guarantees that "cachetip == currenttip" (comparing both rev |
|
1298 | # guarantees that "cachetip == currenttip" (comparing both rev | |
1299 | # and node) always means no nodes have been added or destroyed. |
|
1299 | # and node) always means no nodes have been added or destroyed. | |
1300 |
|
1300 | |||
1301 | # XXX this is suboptimal when qrefresh'ing: we strip the current |
|
1301 | # XXX this is suboptimal when qrefresh'ing: we strip the current | |
1302 | # head, refresh the tag cache, then immediately add a new head. |
|
1302 | # head, refresh the tag cache, then immediately add a new head. | |
1303 | # But I think doing it this way is necessary for the "instant |
|
1303 | # But I think doing it this way is necessary for the "instant | |
1304 | # tag cache retrieval" case to work. |
|
1304 | # tag cache retrieval" case to work. | |
1305 | self.invalidatecaches() |
|
1305 | self.invalidatecaches() | |
1306 |
|
1306 | |||
|
1307 | # Discard all cache entries to force reloading everything. | |||
|
1308 | self._filecache.clear() | |||
|
1309 | ||||
1307 | def walk(self, match, node=None): |
|
1310 | def walk(self, match, node=None): | |
1308 | ''' |
|
1311 | ''' | |
1309 | walk recursively through the directory tree or a given |
|
1312 | walk recursively through the directory tree or a given | |
1310 | changeset, finding all files matched by the match |
|
1313 | changeset, finding all files matched by the match | |
1311 | function |
|
1314 | function | |
1312 | ''' |
|
1315 | ''' | |
1313 | return self[node].walk(match) |
|
1316 | return self[node].walk(match) | |
1314 |
|
1317 | |||
1315 | def status(self, node1='.', node2=None, match=None, |
|
1318 | def status(self, node1='.', node2=None, match=None, | |
1316 | ignored=False, clean=False, unknown=False, |
|
1319 | ignored=False, clean=False, unknown=False, | |
1317 | listsubrepos=False): |
|
1320 | listsubrepos=False): | |
1318 | """return status of files between two nodes or node and working directory |
|
1321 | """return status of files between two nodes or node and working directory | |
1319 |
|
1322 | |||
1320 | If node1 is None, use the first dirstate parent instead. |
|
1323 | If node1 is None, use the first dirstate parent instead. | |
1321 | If node2 is None, compare node1 with working directory. |
|
1324 | If node2 is None, compare node1 with working directory. | |
1322 | """ |
|
1325 | """ | |
1323 |
|
1326 | |||
1324 | def mfmatches(ctx): |
|
1327 | def mfmatches(ctx): | |
1325 | mf = ctx.manifest().copy() |
|
1328 | mf = ctx.manifest().copy() | |
1326 | for fn in mf.keys(): |
|
1329 | for fn in mf.keys(): | |
1327 | if not match(fn): |
|
1330 | if not match(fn): | |
1328 | del mf[fn] |
|
1331 | del mf[fn] | |
1329 | return mf |
|
1332 | return mf | |
1330 |
|
1333 | |||
1331 | if isinstance(node1, context.changectx): |
|
1334 | if isinstance(node1, context.changectx): | |
1332 | ctx1 = node1 |
|
1335 | ctx1 = node1 | |
1333 | else: |
|
1336 | else: | |
1334 | ctx1 = self[node1] |
|
1337 | ctx1 = self[node1] | |
1335 | if isinstance(node2, context.changectx): |
|
1338 | if isinstance(node2, context.changectx): | |
1336 | ctx2 = node2 |
|
1339 | ctx2 = node2 | |
1337 | else: |
|
1340 | else: | |
1338 | ctx2 = self[node2] |
|
1341 | ctx2 = self[node2] | |
1339 |
|
1342 | |||
1340 | working = ctx2.rev() is None |
|
1343 | working = ctx2.rev() is None | |
1341 | parentworking = working and ctx1 == self['.'] |
|
1344 | parentworking = working and ctx1 == self['.'] | |
1342 | match = match or matchmod.always(self.root, self.getcwd()) |
|
1345 | match = match or matchmod.always(self.root, self.getcwd()) | |
1343 | listignored, listclean, listunknown = ignored, clean, unknown |
|
1346 | listignored, listclean, listunknown = ignored, clean, unknown | |
1344 |
|
1347 | |||
1345 | # load earliest manifest first for caching reasons |
|
1348 | # load earliest manifest first for caching reasons | |
1346 | if not working and ctx2.rev() < ctx1.rev(): |
|
1349 | if not working and ctx2.rev() < ctx1.rev(): | |
1347 | ctx2.manifest() |
|
1350 | ctx2.manifest() | |
1348 |
|
1351 | |||
1349 | if not parentworking: |
|
1352 | if not parentworking: | |
1350 | def bad(f, msg): |
|
1353 | def bad(f, msg): | |
1351 | if f not in ctx1: |
|
1354 | if f not in ctx1: | |
1352 | self.ui.warn('%s: %s\n' % (self.dirstate.pathto(f), msg)) |
|
1355 | self.ui.warn('%s: %s\n' % (self.dirstate.pathto(f), msg)) | |
1353 | match.bad = bad |
|
1356 | match.bad = bad | |
1354 |
|
1357 | |||
1355 | if working: # we need to scan the working dir |
|
1358 | if working: # we need to scan the working dir | |
1356 | subrepos = [] |
|
1359 | subrepos = [] | |
1357 | if '.hgsub' in self.dirstate: |
|
1360 | if '.hgsub' in self.dirstate: | |
1358 | subrepos = ctx2.substate.keys() |
|
1361 | subrepos = ctx2.substate.keys() | |
1359 | s = self.dirstate.status(match, subrepos, listignored, |
|
1362 | s = self.dirstate.status(match, subrepos, listignored, | |
1360 | listclean, listunknown) |
|
1363 | listclean, listunknown) | |
1361 | cmp, modified, added, removed, deleted, unknown, ignored, clean = s |
|
1364 | cmp, modified, added, removed, deleted, unknown, ignored, clean = s | |
1362 |
|
1365 | |||
1363 | # check for any possibly clean files |
|
1366 | # check for any possibly clean files | |
1364 | if parentworking and cmp: |
|
1367 | if parentworking and cmp: | |
1365 | fixup = [] |
|
1368 | fixup = [] | |
1366 | # do a full compare of any files that might have changed |
|
1369 | # do a full compare of any files that might have changed | |
1367 | for f in sorted(cmp): |
|
1370 | for f in sorted(cmp): | |
1368 | if (f not in ctx1 or ctx2.flags(f) != ctx1.flags(f) |
|
1371 | if (f not in ctx1 or ctx2.flags(f) != ctx1.flags(f) | |
1369 | or ctx1[f].cmp(ctx2[f])): |
|
1372 | or ctx1[f].cmp(ctx2[f])): | |
1370 | modified.append(f) |
|
1373 | modified.append(f) | |
1371 | else: |
|
1374 | else: | |
1372 | fixup.append(f) |
|
1375 | fixup.append(f) | |
1373 |
|
1376 | |||
1374 | # update dirstate for files that are actually clean |
|
1377 | # update dirstate for files that are actually clean | |
1375 | if fixup: |
|
1378 | if fixup: | |
1376 | if listclean: |
|
1379 | if listclean: | |
1377 | clean += fixup |
|
1380 | clean += fixup | |
1378 |
|
1381 | |||
1379 | try: |
|
1382 | try: | |
1380 | # updating the dirstate is optional |
|
1383 | # updating the dirstate is optional | |
1381 | # so we don't wait on the lock |
|
1384 | # so we don't wait on the lock | |
1382 | wlock = self.wlock(False) |
|
1385 | wlock = self.wlock(False) | |
1383 | try: |
|
1386 | try: | |
1384 | for f in fixup: |
|
1387 | for f in fixup: | |
1385 | self.dirstate.normal(f) |
|
1388 | self.dirstate.normal(f) | |
1386 | finally: |
|
1389 | finally: | |
1387 | wlock.release() |
|
1390 | wlock.release() | |
1388 | except error.LockError: |
|
1391 | except error.LockError: | |
1389 | pass |
|
1392 | pass | |
1390 |
|
1393 | |||
1391 | if not parentworking: |
|
1394 | if not parentworking: | |
1392 | mf1 = mfmatches(ctx1) |
|
1395 | mf1 = mfmatches(ctx1) | |
1393 | if working: |
|
1396 | if working: | |
1394 | # we are comparing working dir against non-parent |
|
1397 | # we are comparing working dir against non-parent | |
1395 | # generate a pseudo-manifest for the working dir |
|
1398 | # generate a pseudo-manifest for the working dir | |
1396 | mf2 = mfmatches(self['.']) |
|
1399 | mf2 = mfmatches(self['.']) | |
1397 | for f in cmp + modified + added: |
|
1400 | for f in cmp + modified + added: | |
1398 | mf2[f] = None |
|
1401 | mf2[f] = None | |
1399 | mf2.set(f, ctx2.flags(f)) |
|
1402 | mf2.set(f, ctx2.flags(f)) | |
1400 | for f in removed: |
|
1403 | for f in removed: | |
1401 | if f in mf2: |
|
1404 | if f in mf2: | |
1402 | del mf2[f] |
|
1405 | del mf2[f] | |
1403 | else: |
|
1406 | else: | |
1404 | # we are comparing two revisions |
|
1407 | # we are comparing two revisions | |
1405 | deleted, unknown, ignored = [], [], [] |
|
1408 | deleted, unknown, ignored = [], [], [] | |
1406 | mf2 = mfmatches(ctx2) |
|
1409 | mf2 = mfmatches(ctx2) | |
1407 |
|
1410 | |||
1408 | modified, added, clean = [], [], [] |
|
1411 | modified, added, clean = [], [], [] | |
1409 | for fn in mf2: |
|
1412 | for fn in mf2: | |
1410 | if fn in mf1: |
|
1413 | if fn in mf1: | |
1411 | if (fn not in deleted and |
|
1414 | if (fn not in deleted and | |
1412 | (mf1.flags(fn) != mf2.flags(fn) or |
|
1415 | (mf1.flags(fn) != mf2.flags(fn) or | |
1413 | (mf1[fn] != mf2[fn] and |
|
1416 | (mf1[fn] != mf2[fn] and | |
1414 | (mf2[fn] or ctx1[fn].cmp(ctx2[fn]))))): |
|
1417 | (mf2[fn] or ctx1[fn].cmp(ctx2[fn]))))): | |
1415 | modified.append(fn) |
|
1418 | modified.append(fn) | |
1416 | elif listclean: |
|
1419 | elif listclean: | |
1417 | clean.append(fn) |
|
1420 | clean.append(fn) | |
1418 | del mf1[fn] |
|
1421 | del mf1[fn] | |
1419 | elif fn not in deleted: |
|
1422 | elif fn not in deleted: | |
1420 | added.append(fn) |
|
1423 | added.append(fn) | |
1421 | removed = mf1.keys() |
|
1424 | removed = mf1.keys() | |
1422 |
|
1425 | |||
1423 | if working and modified and not self.dirstate._checklink: |
|
1426 | if working and modified and not self.dirstate._checklink: | |
1424 | # Symlink placeholders may get non-symlink-like contents |
|
1427 | # Symlink placeholders may get non-symlink-like contents | |
1425 | # via user error or dereferencing by NFS or Samba servers, |
|
1428 | # via user error or dereferencing by NFS or Samba servers, | |
1426 | # so we filter out any placeholders that don't look like a |
|
1429 | # so we filter out any placeholders that don't look like a | |
1427 | # symlink |
|
1430 | # symlink | |
1428 | sane = [] |
|
1431 | sane = [] | |
1429 | for f in modified: |
|
1432 | for f in modified: | |
1430 | if ctx2.flags(f) == 'l': |
|
1433 | if ctx2.flags(f) == 'l': | |
1431 | d = ctx2[f].data() |
|
1434 | d = ctx2[f].data() | |
1432 | if len(d) >= 1024 or '\n' in d or util.binary(d): |
|
1435 | if len(d) >= 1024 or '\n' in d or util.binary(d): | |
1433 | self.ui.debug('ignoring suspect symlink placeholder' |
|
1436 | self.ui.debug('ignoring suspect symlink placeholder' | |
1434 | ' "%s"\n' % f) |
|
1437 | ' "%s"\n' % f) | |
1435 | continue |
|
1438 | continue | |
1436 | sane.append(f) |
|
1439 | sane.append(f) | |
1437 | modified = sane |
|
1440 | modified = sane | |
1438 |
|
1441 | |||
1439 | r = modified, added, removed, deleted, unknown, ignored, clean |
|
1442 | r = modified, added, removed, deleted, unknown, ignored, clean | |
1440 |
|
1443 | |||
1441 | if listsubrepos: |
|
1444 | if listsubrepos: | |
1442 | for subpath, sub in subrepo.itersubrepos(ctx1, ctx2): |
|
1445 | for subpath, sub in subrepo.itersubrepos(ctx1, ctx2): | |
1443 | if working: |
|
1446 | if working: | |
1444 | rev2 = None |
|
1447 | rev2 = None | |
1445 | else: |
|
1448 | else: | |
1446 | rev2 = ctx2.substate[subpath][1] |
|
1449 | rev2 = ctx2.substate[subpath][1] | |
1447 | try: |
|
1450 | try: | |
1448 | submatch = matchmod.narrowmatcher(subpath, match) |
|
1451 | submatch = matchmod.narrowmatcher(subpath, match) | |
1449 | s = sub.status(rev2, match=submatch, ignored=listignored, |
|
1452 | s = sub.status(rev2, match=submatch, ignored=listignored, | |
1450 | clean=listclean, unknown=listunknown, |
|
1453 | clean=listclean, unknown=listunknown, | |
1451 | listsubrepos=True) |
|
1454 | listsubrepos=True) | |
1452 | for rfiles, sfiles in zip(r, s): |
|
1455 | for rfiles, sfiles in zip(r, s): | |
1453 | rfiles.extend("%s/%s" % (subpath, f) for f in sfiles) |
|
1456 | rfiles.extend("%s/%s" % (subpath, f) for f in sfiles) | |
1454 | except error.LookupError: |
|
1457 | except error.LookupError: | |
1455 | self.ui.status(_("skipping missing subrepository: %s\n") |
|
1458 | self.ui.status(_("skipping missing subrepository: %s\n") | |
1456 | % subpath) |
|
1459 | % subpath) | |
1457 |
|
1460 | |||
1458 | for l in r: |
|
1461 | for l in r: | |
1459 | l.sort() |
|
1462 | l.sort() | |
1460 | return r |
|
1463 | return r | |
1461 |
|
1464 | |||
1462 | def heads(self, start=None): |
|
1465 | def heads(self, start=None): | |
1463 | heads = self.changelog.heads(start) |
|
1466 | heads = self.changelog.heads(start) | |
1464 | # sort the output in rev descending order |
|
1467 | # sort the output in rev descending order | |
1465 | return sorted(heads, key=self.changelog.rev, reverse=True) |
|
1468 | return sorted(heads, key=self.changelog.rev, reverse=True) | |
1466 |
|
1469 | |||
1467 | def branchheads(self, branch=None, start=None, closed=False): |
|
1470 | def branchheads(self, branch=None, start=None, closed=False): | |
1468 | '''return a (possibly filtered) list of heads for the given branch |
|
1471 | '''return a (possibly filtered) list of heads for the given branch | |
1469 |
|
1472 | |||
1470 | Heads are returned in topological order, from newest to oldest. |
|
1473 | Heads are returned in topological order, from newest to oldest. | |
1471 | If branch is None, use the dirstate branch. |
|
1474 | If branch is None, use the dirstate branch. | |
1472 | If start is not None, return only heads reachable from start. |
|
1475 | If start is not None, return only heads reachable from start. | |
1473 | If closed is True, return heads that are marked as closed as well. |
|
1476 | If closed is True, return heads that are marked as closed as well. | |
1474 | ''' |
|
1477 | ''' | |
1475 | if branch is None: |
|
1478 | if branch is None: | |
1476 | branch = self[None].branch() |
|
1479 | branch = self[None].branch() | |
1477 | branches = self.branchmap() |
|
1480 | branches = self.branchmap() | |
1478 | if branch not in branches: |
|
1481 | if branch not in branches: | |
1479 | return [] |
|
1482 | return [] | |
1480 | # the cache returns heads ordered lowest to highest |
|
1483 | # the cache returns heads ordered lowest to highest | |
1481 | bheads = list(reversed(branches[branch])) |
|
1484 | bheads = list(reversed(branches[branch])) | |
1482 | if start is not None: |
|
1485 | if start is not None: | |
1483 | # filter out the heads that cannot be reached from startrev |
|
1486 | # filter out the heads that cannot be reached from startrev | |
1484 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) |
|
1487 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) | |
1485 | bheads = [h for h in bheads if h in fbheads] |
|
1488 | bheads = [h for h in bheads if h in fbheads] | |
1486 | if not closed: |
|
1489 | if not closed: | |
1487 | bheads = [h for h in bheads if |
|
1490 | bheads = [h for h in bheads if | |
1488 | ('close' not in self.changelog.read(h)[5])] |
|
1491 | ('close' not in self.changelog.read(h)[5])] | |
1489 | return bheads |
|
1492 | return bheads | |
1490 |
|
1493 | |||
1491 | def branches(self, nodes): |
|
1494 | def branches(self, nodes): | |
1492 | if not nodes: |
|
1495 | if not nodes: | |
1493 | nodes = [self.changelog.tip()] |
|
1496 | nodes = [self.changelog.tip()] | |
1494 | b = [] |
|
1497 | b = [] | |
1495 | for n in nodes: |
|
1498 | for n in nodes: | |
1496 | t = n |
|
1499 | t = n | |
1497 | while True: |
|
1500 | while True: | |
1498 | p = self.changelog.parents(n) |
|
1501 | p = self.changelog.parents(n) | |
1499 | if p[1] != nullid or p[0] == nullid: |
|
1502 | if p[1] != nullid or p[0] == nullid: | |
1500 | b.append((t, n, p[0], p[1])) |
|
1503 | b.append((t, n, p[0], p[1])) | |
1501 | break |
|
1504 | break | |
1502 | n = p[0] |
|
1505 | n = p[0] | |
1503 | return b |
|
1506 | return b | |
1504 |
|
1507 | |||
1505 | def between(self, pairs): |
|
1508 | def between(self, pairs): | |
1506 | r = [] |
|
1509 | r = [] | |
1507 |
|
1510 | |||
1508 | for top, bottom in pairs: |
|
1511 | for top, bottom in pairs: | |
1509 | n, l, i = top, [], 0 |
|
1512 | n, l, i = top, [], 0 | |
1510 | f = 1 |
|
1513 | f = 1 | |
1511 |
|
1514 | |||
1512 | while n != bottom and n != nullid: |
|
1515 | while n != bottom and n != nullid: | |
1513 | p = self.changelog.parents(n)[0] |
|
1516 | p = self.changelog.parents(n)[0] | |
1514 | if i == f: |
|
1517 | if i == f: | |
1515 | l.append(n) |
|
1518 | l.append(n) | |
1516 | f = f * 2 |
|
1519 | f = f * 2 | |
1517 | n = p |
|
1520 | n = p | |
1518 | i += 1 |
|
1521 | i += 1 | |
1519 |
|
1522 | |||
1520 | r.append(l) |
|
1523 | r.append(l) | |
1521 |
|
1524 | |||
1522 | return r |
|
1525 | return r | |
1523 |
|
1526 | |||
1524 | def pull(self, remote, heads=None, force=False): |
|
1527 | def pull(self, remote, heads=None, force=False): | |
1525 | lock = self.lock() |
|
1528 | lock = self.lock() | |
1526 | try: |
|
1529 | try: | |
1527 | tmp = discovery.findcommonincoming(self, remote, heads=heads, |
|
1530 | tmp = discovery.findcommonincoming(self, remote, heads=heads, | |
1528 | force=force) |
|
1531 | force=force) | |
1529 | common, fetch, rheads = tmp |
|
1532 | common, fetch, rheads = tmp | |
1530 | if not fetch: |
|
1533 | if not fetch: | |
1531 | self.ui.status(_("no changes found\n")) |
|
1534 | self.ui.status(_("no changes found\n")) | |
1532 | added = [] |
|
1535 | added = [] | |
1533 | result = 0 |
|
1536 | result = 0 | |
1534 | else: |
|
1537 | else: | |
1535 | if heads is None and list(common) == [nullid]: |
|
1538 | if heads is None and list(common) == [nullid]: | |
1536 | self.ui.status(_("requesting all changes\n")) |
|
1539 | self.ui.status(_("requesting all changes\n")) | |
1537 | elif heads is None and remote.capable('changegroupsubset'): |
|
1540 | elif heads is None and remote.capable('changegroupsubset'): | |
1538 | # issue1320, avoid a race if remote changed after discovery |
|
1541 | # issue1320, avoid a race if remote changed after discovery | |
1539 | heads = rheads |
|
1542 | heads = rheads | |
1540 |
|
1543 | |||
1541 | if remote.capable('getbundle'): |
|
1544 | if remote.capable('getbundle'): | |
1542 | cg = remote.getbundle('pull', common=common, |
|
1545 | cg = remote.getbundle('pull', common=common, | |
1543 | heads=heads or rheads) |
|
1546 | heads=heads or rheads) | |
1544 | elif heads is None: |
|
1547 | elif heads is None: | |
1545 | cg = remote.changegroup(fetch, 'pull') |
|
1548 | cg = remote.changegroup(fetch, 'pull') | |
1546 | elif not remote.capable('changegroupsubset'): |
|
1549 | elif not remote.capable('changegroupsubset'): | |
1547 | raise util.Abort(_("partial pull cannot be done because " |
|
1550 | raise util.Abort(_("partial pull cannot be done because " | |
1548 | "other repository doesn't support " |
|
1551 | "other repository doesn't support " | |
1549 | "changegroupsubset.")) |
|
1552 | "changegroupsubset.")) | |
1550 | else: |
|
1553 | else: | |
1551 | cg = remote.changegroupsubset(fetch, heads, 'pull') |
|
1554 | cg = remote.changegroupsubset(fetch, heads, 'pull') | |
1552 | clstart = len(self.changelog) |
|
1555 | clstart = len(self.changelog) | |
1553 | result = self.addchangegroup(cg, 'pull', remote.url()) |
|
1556 | result = self.addchangegroup(cg, 'pull', remote.url()) | |
1554 | clend = len(self.changelog) |
|
1557 | clend = len(self.changelog) | |
1555 | added = [self.changelog.node(r) for r in xrange(clstart, clend)] |
|
1558 | added = [self.changelog.node(r) for r in xrange(clstart, clend)] | |
1556 |
|
1559 | |||
1557 | # compute target subset |
|
1560 | # compute target subset | |
1558 | if heads is None: |
|
1561 | if heads is None: | |
1559 | # We pulled every thing possible |
|
1562 | # We pulled every thing possible | |
1560 | # sync on everything common |
|
1563 | # sync on everything common | |
1561 | subset = common + added |
|
1564 | subset = common + added | |
1562 | else: |
|
1565 | else: | |
1563 | # We pulled a specific subset |
|
1566 | # We pulled a specific subset | |
1564 | # sync on this subset |
|
1567 | # sync on this subset | |
1565 | subset = heads |
|
1568 | subset = heads | |
1566 |
|
1569 | |||
1567 | # Get remote phases data from remote |
|
1570 | # Get remote phases data from remote | |
1568 | remotephases = remote.listkeys('phases') |
|
1571 | remotephases = remote.listkeys('phases') | |
1569 | publishing = bool(remotephases.get('publishing', False)) |
|
1572 | publishing = bool(remotephases.get('publishing', False)) | |
1570 | if remotephases and not publishing: |
|
1573 | if remotephases and not publishing: | |
1571 | # remote is new and unpublishing |
|
1574 | # remote is new and unpublishing | |
1572 | pheads, _dr = phases.analyzeremotephases(self, subset, |
|
1575 | pheads, _dr = phases.analyzeremotephases(self, subset, | |
1573 | remotephases) |
|
1576 | remotephases) | |
1574 | phases.advanceboundary(self, phases.public, pheads) |
|
1577 | phases.advanceboundary(self, phases.public, pheads) | |
1575 | phases.advanceboundary(self, phases.draft, subset) |
|
1578 | phases.advanceboundary(self, phases.draft, subset) | |
1576 | else: |
|
1579 | else: | |
1577 | # Remote is old or publishing all common changesets |
|
1580 | # Remote is old or publishing all common changesets | |
1578 | # should be seen as public |
|
1581 | # should be seen as public | |
1579 | phases.advanceboundary(self, phases.public, subset) |
|
1582 | phases.advanceboundary(self, phases.public, subset) | |
1580 | finally: |
|
1583 | finally: | |
1581 | lock.release() |
|
1584 | lock.release() | |
1582 |
|
1585 | |||
1583 | return result |
|
1586 | return result | |
1584 |
|
1587 | |||
1585 | def checkpush(self, force, revs): |
|
1588 | def checkpush(self, force, revs): | |
1586 | """Extensions can override this function if additional checks have |
|
1589 | """Extensions can override this function if additional checks have | |
1587 | to be performed before pushing, or call it if they override push |
|
1590 | to be performed before pushing, or call it if they override push | |
1588 | command. |
|
1591 | command. | |
1589 | """ |
|
1592 | """ | |
1590 | pass |
|
1593 | pass | |
1591 |
|
1594 | |||
1592 | def push(self, remote, force=False, revs=None, newbranch=False): |
|
1595 | def push(self, remote, force=False, revs=None, newbranch=False): | |
1593 | '''Push outgoing changesets (limited by revs) from the current |
|
1596 | '''Push outgoing changesets (limited by revs) from the current | |
1594 | repository to remote. Return an integer: |
|
1597 | repository to remote. Return an integer: | |
1595 | - None means nothing to push |
|
1598 | - None means nothing to push | |
1596 | - 0 means HTTP error |
|
1599 | - 0 means HTTP error | |
1597 | - 1 means we pushed and remote head count is unchanged *or* |
|
1600 | - 1 means we pushed and remote head count is unchanged *or* | |
1598 | we have outgoing changesets but refused to push |
|
1601 | we have outgoing changesets but refused to push | |
1599 | - other values as described by addchangegroup() |
|
1602 | - other values as described by addchangegroup() | |
1600 | ''' |
|
1603 | ''' | |
1601 | # there are two ways to push to remote repo: |
|
1604 | # there are two ways to push to remote repo: | |
1602 | # |
|
1605 | # | |
1603 | # addchangegroup assumes local user can lock remote |
|
1606 | # addchangegroup assumes local user can lock remote | |
1604 | # repo (local filesystem, old ssh servers). |
|
1607 | # repo (local filesystem, old ssh servers). | |
1605 | # |
|
1608 | # | |
1606 | # unbundle assumes local user cannot lock remote repo (new ssh |
|
1609 | # unbundle assumes local user cannot lock remote repo (new ssh | |
1607 | # servers, http servers). |
|
1610 | # servers, http servers). | |
1608 |
|
1611 | |||
1609 | # get local lock as we might write phase data |
|
1612 | # get local lock as we might write phase data | |
1610 | locallock = self.lock() |
|
1613 | locallock = self.lock() | |
1611 | try: |
|
1614 | try: | |
1612 | self.checkpush(force, revs) |
|
1615 | self.checkpush(force, revs) | |
1613 | lock = None |
|
1616 | lock = None | |
1614 | unbundle = remote.capable('unbundle') |
|
1617 | unbundle = remote.capable('unbundle') | |
1615 | if not unbundle: |
|
1618 | if not unbundle: | |
1616 | lock = remote.lock() |
|
1619 | lock = remote.lock() | |
1617 | try: |
|
1620 | try: | |
1618 | # discovery |
|
1621 | # discovery | |
1619 | fci = discovery.findcommonincoming |
|
1622 | fci = discovery.findcommonincoming | |
1620 | commoninc = fci(self, remote, force=force) |
|
1623 | commoninc = fci(self, remote, force=force) | |
1621 | common, inc, remoteheads = commoninc |
|
1624 | common, inc, remoteheads = commoninc | |
1622 | fco = discovery.findcommonoutgoing |
|
1625 | fco = discovery.findcommonoutgoing | |
1623 | outgoing = fco(self, remote, onlyheads=revs, |
|
1626 | outgoing = fco(self, remote, onlyheads=revs, | |
1624 | commoninc=commoninc, force=force) |
|
1627 | commoninc=commoninc, force=force) | |
1625 |
|
1628 | |||
1626 |
|
1629 | |||
1627 | if not outgoing.missing: |
|
1630 | if not outgoing.missing: | |
1628 | # nothing to push |
|
1631 | # nothing to push | |
1629 | scmutil.nochangesfound(self.ui, outgoing.excluded) |
|
1632 | scmutil.nochangesfound(self.ui, outgoing.excluded) | |
1630 | ret = None |
|
1633 | ret = None | |
1631 | else: |
|
1634 | else: | |
1632 | # something to push |
|
1635 | # something to push | |
1633 | if not force: |
|
1636 | if not force: | |
1634 | discovery.checkheads(self, remote, outgoing, |
|
1637 | discovery.checkheads(self, remote, outgoing, | |
1635 | remoteheads, newbranch, |
|
1638 | remoteheads, newbranch, | |
1636 | bool(inc)) |
|
1639 | bool(inc)) | |
1637 |
|
1640 | |||
1638 | # create a changegroup from local |
|
1641 | # create a changegroup from local | |
1639 | if revs is None and not outgoing.excluded: |
|
1642 | if revs is None and not outgoing.excluded: | |
1640 | # push everything, |
|
1643 | # push everything, | |
1641 | # use the fast path, no race possible on push |
|
1644 | # use the fast path, no race possible on push | |
1642 | cg = self._changegroup(outgoing.missing, 'push') |
|
1645 | cg = self._changegroup(outgoing.missing, 'push') | |
1643 | else: |
|
1646 | else: | |
1644 | cg = self.getlocalbundle('push', outgoing) |
|
1647 | cg = self.getlocalbundle('push', outgoing) | |
1645 |
|
1648 | |||
1646 | # apply changegroup to remote |
|
1649 | # apply changegroup to remote | |
1647 | if unbundle: |
|
1650 | if unbundle: | |
1648 | # local repo finds heads on server, finds out what |
|
1651 | # local repo finds heads on server, finds out what | |
1649 | # revs it must push. once revs transferred, if server |
|
1652 | # revs it must push. once revs transferred, if server | |
1650 | # finds it has different heads (someone else won |
|
1653 | # finds it has different heads (someone else won | |
1651 | # commit/push race), server aborts. |
|
1654 | # commit/push race), server aborts. | |
1652 | if force: |
|
1655 | if force: | |
1653 | remoteheads = ['force'] |
|
1656 | remoteheads = ['force'] | |
1654 | # ssh: return remote's addchangegroup() |
|
1657 | # ssh: return remote's addchangegroup() | |
1655 | # http: return remote's addchangegroup() or 0 for error |
|
1658 | # http: return remote's addchangegroup() or 0 for error | |
1656 | ret = remote.unbundle(cg, remoteheads, 'push') |
|
1659 | ret = remote.unbundle(cg, remoteheads, 'push') | |
1657 | else: |
|
1660 | else: | |
1658 | # we return an integer indicating remote head count change |
|
1661 | # we return an integer indicating remote head count change | |
1659 | ret = remote.addchangegroup(cg, 'push', self.url()) |
|
1662 | ret = remote.addchangegroup(cg, 'push', self.url()) | |
1660 |
|
1663 | |||
1661 | if ret: |
|
1664 | if ret: | |
1662 | # push succeed, synchonize target of the push |
|
1665 | # push succeed, synchonize target of the push | |
1663 | cheads = outgoing.missingheads |
|
1666 | cheads = outgoing.missingheads | |
1664 | elif revs is None: |
|
1667 | elif revs is None: | |
1665 | # All out push fails. synchronize all common |
|
1668 | # All out push fails. synchronize all common | |
1666 | cheads = outgoing.commonheads |
|
1669 | cheads = outgoing.commonheads | |
1667 | else: |
|
1670 | else: | |
1668 | # I want cheads = heads(::missingheads and ::commonheads) |
|
1671 | # I want cheads = heads(::missingheads and ::commonheads) | |
1669 | # (missingheads is revs with secret changeset filtered out) |
|
1672 | # (missingheads is revs with secret changeset filtered out) | |
1670 | # |
|
1673 | # | |
1671 | # This can be expressed as: |
|
1674 | # This can be expressed as: | |
1672 | # cheads = ( (missingheads and ::commonheads) |
|
1675 | # cheads = ( (missingheads and ::commonheads) | |
1673 | # + (commonheads and ::missingheads))" |
|
1676 | # + (commonheads and ::missingheads))" | |
1674 | # ) |
|
1677 | # ) | |
1675 | # |
|
1678 | # | |
1676 | # while trying to push we already computed the following: |
|
1679 | # while trying to push we already computed the following: | |
1677 | # common = (::commonheads) |
|
1680 | # common = (::commonheads) | |
1678 | # missing = ((commonheads::missingheads) - commonheads) |
|
1681 | # missing = ((commonheads::missingheads) - commonheads) | |
1679 | # |
|
1682 | # | |
1680 | # We can pick: |
|
1683 | # We can pick: | |
1681 | # * missingheads part of comon (::commonheads) |
|
1684 | # * missingheads part of comon (::commonheads) | |
1682 | common = set(outgoing.common) |
|
1685 | common = set(outgoing.common) | |
1683 | cheads = [node for node in revs if node in common] |
|
1686 | cheads = [node for node in revs if node in common] | |
1684 | # and |
|
1687 | # and | |
1685 | # * commonheads parents on missing |
|
1688 | # * commonheads parents on missing | |
1686 | revset = self.set('%ln and parents(roots(%ln))', |
|
1689 | revset = self.set('%ln and parents(roots(%ln))', | |
1687 | outgoing.commonheads, |
|
1690 | outgoing.commonheads, | |
1688 | outgoing.missing) |
|
1691 | outgoing.missing) | |
1689 | cheads.extend(c.node() for c in revset) |
|
1692 | cheads.extend(c.node() for c in revset) | |
1690 | # even when we don't push, exchanging phase data is useful |
|
1693 | # even when we don't push, exchanging phase data is useful | |
1691 | remotephases = remote.listkeys('phases') |
|
1694 | remotephases = remote.listkeys('phases') | |
1692 | if not remotephases: # old server or public only repo |
|
1695 | if not remotephases: # old server or public only repo | |
1693 | phases.advanceboundary(self, phases.public, cheads) |
|
1696 | phases.advanceboundary(self, phases.public, cheads) | |
1694 | # don't push any phase data as there is nothing to push |
|
1697 | # don't push any phase data as there is nothing to push | |
1695 | else: |
|
1698 | else: | |
1696 | ana = phases.analyzeremotephases(self, cheads, remotephases) |
|
1699 | ana = phases.analyzeremotephases(self, cheads, remotephases) | |
1697 | pheads, droots = ana |
|
1700 | pheads, droots = ana | |
1698 | ### Apply remote phase on local |
|
1701 | ### Apply remote phase on local | |
1699 | if remotephases.get('publishing', False): |
|
1702 | if remotephases.get('publishing', False): | |
1700 | phases.advanceboundary(self, phases.public, cheads) |
|
1703 | phases.advanceboundary(self, phases.public, cheads) | |
1701 | else: # publish = False |
|
1704 | else: # publish = False | |
1702 | phases.advanceboundary(self, phases.public, pheads) |
|
1705 | phases.advanceboundary(self, phases.public, pheads) | |
1703 | phases.advanceboundary(self, phases.draft, cheads) |
|
1706 | phases.advanceboundary(self, phases.draft, cheads) | |
1704 | ### Apply local phase on remote |
|
1707 | ### Apply local phase on remote | |
1705 |
|
1708 | |||
1706 | # Get the list of all revs draft on remote by public here. |
|
1709 | # Get the list of all revs draft on remote by public here. | |
1707 | # XXX Beware that revset break if droots is not strictly |
|
1710 | # XXX Beware that revset break if droots is not strictly | |
1708 | # XXX root we may want to ensure it is but it is costly |
|
1711 | # XXX root we may want to ensure it is but it is costly | |
1709 | outdated = self.set('heads((%ln::%ln) and public())', |
|
1712 | outdated = self.set('heads((%ln::%ln) and public())', | |
1710 | droots, cheads) |
|
1713 | droots, cheads) | |
1711 | for newremotehead in outdated: |
|
1714 | for newremotehead in outdated: | |
1712 | r = remote.pushkey('phases', |
|
1715 | r = remote.pushkey('phases', | |
1713 | newremotehead.hex(), |
|
1716 | newremotehead.hex(), | |
1714 | str(phases.draft), |
|
1717 | str(phases.draft), | |
1715 | str(phases.public)) |
|
1718 | str(phases.public)) | |
1716 | if not r: |
|
1719 | if not r: | |
1717 | self.ui.warn(_('updating %s to public failed!\n') |
|
1720 | self.ui.warn(_('updating %s to public failed!\n') | |
1718 | % newremotehead) |
|
1721 | % newremotehead) | |
1719 | finally: |
|
1722 | finally: | |
1720 | if lock is not None: |
|
1723 | if lock is not None: | |
1721 | lock.release() |
|
1724 | lock.release() | |
1722 | finally: |
|
1725 | finally: | |
1723 | locallock.release() |
|
1726 | locallock.release() | |
1724 |
|
1727 | |||
1725 | self.ui.debug("checking for updated bookmarks\n") |
|
1728 | self.ui.debug("checking for updated bookmarks\n") | |
1726 | rb = remote.listkeys('bookmarks') |
|
1729 | rb = remote.listkeys('bookmarks') | |
1727 | for k in rb.keys(): |
|
1730 | for k in rb.keys(): | |
1728 | if k in self._bookmarks: |
|
1731 | if k in self._bookmarks: | |
1729 | nr, nl = rb[k], hex(self._bookmarks[k]) |
|
1732 | nr, nl = rb[k], hex(self._bookmarks[k]) | |
1730 | if nr in self: |
|
1733 | if nr in self: | |
1731 | cr = self[nr] |
|
1734 | cr = self[nr] | |
1732 | cl = self[nl] |
|
1735 | cl = self[nl] | |
1733 | if cl in cr.descendants(): |
|
1736 | if cl in cr.descendants(): | |
1734 | r = remote.pushkey('bookmarks', k, nr, nl) |
|
1737 | r = remote.pushkey('bookmarks', k, nr, nl) | |
1735 | if r: |
|
1738 | if r: | |
1736 | self.ui.status(_("updating bookmark %s\n") % k) |
|
1739 | self.ui.status(_("updating bookmark %s\n") % k) | |
1737 | else: |
|
1740 | else: | |
1738 | self.ui.warn(_('updating bookmark %s' |
|
1741 | self.ui.warn(_('updating bookmark %s' | |
1739 | ' failed!\n') % k) |
|
1742 | ' failed!\n') % k) | |
1740 |
|
1743 | |||
1741 | return ret |
|
1744 | return ret | |
1742 |
|
1745 | |||
1743 | def changegroupinfo(self, nodes, source): |
|
1746 | def changegroupinfo(self, nodes, source): | |
1744 | if self.ui.verbose or source == 'bundle': |
|
1747 | if self.ui.verbose or source == 'bundle': | |
1745 | self.ui.status(_("%d changesets found\n") % len(nodes)) |
|
1748 | self.ui.status(_("%d changesets found\n") % len(nodes)) | |
1746 | if self.ui.debugflag: |
|
1749 | if self.ui.debugflag: | |
1747 | self.ui.debug("list of changesets:\n") |
|
1750 | self.ui.debug("list of changesets:\n") | |
1748 | for node in nodes: |
|
1751 | for node in nodes: | |
1749 | self.ui.debug("%s\n" % hex(node)) |
|
1752 | self.ui.debug("%s\n" % hex(node)) | |
1750 |
|
1753 | |||
1751 | def changegroupsubset(self, bases, heads, source): |
|
1754 | def changegroupsubset(self, bases, heads, source): | |
1752 | """Compute a changegroup consisting of all the nodes that are |
|
1755 | """Compute a changegroup consisting of all the nodes that are | |
1753 | descendants of any of the bases and ancestors of any of the heads. |
|
1756 | descendants of any of the bases and ancestors of any of the heads. | |
1754 | Return a chunkbuffer object whose read() method will return |
|
1757 | Return a chunkbuffer object whose read() method will return | |
1755 | successive changegroup chunks. |
|
1758 | successive changegroup chunks. | |
1756 |
|
1759 | |||
1757 | It is fairly complex as determining which filenodes and which |
|
1760 | It is fairly complex as determining which filenodes and which | |
1758 | manifest nodes need to be included for the changeset to be complete |
|
1761 | manifest nodes need to be included for the changeset to be complete | |
1759 | is non-trivial. |
|
1762 | is non-trivial. | |
1760 |
|
1763 | |||
1761 | Another wrinkle is doing the reverse, figuring out which changeset in |
|
1764 | Another wrinkle is doing the reverse, figuring out which changeset in | |
1762 | the changegroup a particular filenode or manifestnode belongs to. |
|
1765 | the changegroup a particular filenode or manifestnode belongs to. | |
1763 | """ |
|
1766 | """ | |
1764 | cl = self.changelog |
|
1767 | cl = self.changelog | |
1765 | if not bases: |
|
1768 | if not bases: | |
1766 | bases = [nullid] |
|
1769 | bases = [nullid] | |
1767 | csets, bases, heads = cl.nodesbetween(bases, heads) |
|
1770 | csets, bases, heads = cl.nodesbetween(bases, heads) | |
1768 | # We assume that all ancestors of bases are known |
|
1771 | # We assume that all ancestors of bases are known | |
1769 | common = set(cl.ancestors(*[cl.rev(n) for n in bases])) |
|
1772 | common = set(cl.ancestors(*[cl.rev(n) for n in bases])) | |
1770 | return self._changegroupsubset(common, csets, heads, source) |
|
1773 | return self._changegroupsubset(common, csets, heads, source) | |
1771 |
|
1774 | |||
1772 | def getlocalbundle(self, source, outgoing): |
|
1775 | def getlocalbundle(self, source, outgoing): | |
1773 | """Like getbundle, but taking a discovery.outgoing as an argument. |
|
1776 | """Like getbundle, but taking a discovery.outgoing as an argument. | |
1774 |
|
1777 | |||
1775 | This is only implemented for local repos and reuses potentially |
|
1778 | This is only implemented for local repos and reuses potentially | |
1776 | precomputed sets in outgoing.""" |
|
1779 | precomputed sets in outgoing.""" | |
1777 | if not outgoing.missing: |
|
1780 | if not outgoing.missing: | |
1778 | return None |
|
1781 | return None | |
1779 | return self._changegroupsubset(outgoing.common, |
|
1782 | return self._changegroupsubset(outgoing.common, | |
1780 | outgoing.missing, |
|
1783 | outgoing.missing, | |
1781 | outgoing.missingheads, |
|
1784 | outgoing.missingheads, | |
1782 | source) |
|
1785 | source) | |
1783 |
|
1786 | |||
1784 | def getbundle(self, source, heads=None, common=None): |
|
1787 | def getbundle(self, source, heads=None, common=None): | |
1785 | """Like changegroupsubset, but returns the set difference between the |
|
1788 | """Like changegroupsubset, but returns the set difference between the | |
1786 | ancestors of heads and the ancestors common. |
|
1789 | ancestors of heads and the ancestors common. | |
1787 |
|
1790 | |||
1788 | If heads is None, use the local heads. If common is None, use [nullid]. |
|
1791 | If heads is None, use the local heads. If common is None, use [nullid]. | |
1789 |
|
1792 | |||
1790 | The nodes in common might not all be known locally due to the way the |
|
1793 | The nodes in common might not all be known locally due to the way the | |
1791 | current discovery protocol works. |
|
1794 | current discovery protocol works. | |
1792 | """ |
|
1795 | """ | |
1793 | cl = self.changelog |
|
1796 | cl = self.changelog | |
1794 | if common: |
|
1797 | if common: | |
1795 | nm = cl.nodemap |
|
1798 | nm = cl.nodemap | |
1796 | common = [n for n in common if n in nm] |
|
1799 | common = [n for n in common if n in nm] | |
1797 | else: |
|
1800 | else: | |
1798 | common = [nullid] |
|
1801 | common = [nullid] | |
1799 | if not heads: |
|
1802 | if not heads: | |
1800 | heads = cl.heads() |
|
1803 | heads = cl.heads() | |
1801 | return self.getlocalbundle(source, |
|
1804 | return self.getlocalbundle(source, | |
1802 | discovery.outgoing(cl, common, heads)) |
|
1805 | discovery.outgoing(cl, common, heads)) | |
1803 |
|
1806 | |||
1804 | def _changegroupsubset(self, commonrevs, csets, heads, source): |
|
1807 | def _changegroupsubset(self, commonrevs, csets, heads, source): | |
1805 |
|
1808 | |||
1806 | cl = self.changelog |
|
1809 | cl = self.changelog | |
1807 | mf = self.manifest |
|
1810 | mf = self.manifest | |
1808 | mfs = {} # needed manifests |
|
1811 | mfs = {} # needed manifests | |
1809 | fnodes = {} # needed file nodes |
|
1812 | fnodes = {} # needed file nodes | |
1810 | changedfiles = set() |
|
1813 | changedfiles = set() | |
1811 | fstate = ['', {}] |
|
1814 | fstate = ['', {}] | |
1812 | count = [0] |
|
1815 | count = [0] | |
1813 |
|
1816 | |||
1814 | # can we go through the fast path ? |
|
1817 | # can we go through the fast path ? | |
1815 | heads.sort() |
|
1818 | heads.sort() | |
1816 | if heads == sorted(self.heads()): |
|
1819 | if heads == sorted(self.heads()): | |
1817 | return self._changegroup(csets, source) |
|
1820 | return self._changegroup(csets, source) | |
1818 |
|
1821 | |||
1819 | # slow path |
|
1822 | # slow path | |
1820 | self.hook('preoutgoing', throw=True, source=source) |
|
1823 | self.hook('preoutgoing', throw=True, source=source) | |
1821 | self.changegroupinfo(csets, source) |
|
1824 | self.changegroupinfo(csets, source) | |
1822 |
|
1825 | |||
1823 | # filter any nodes that claim to be part of the known set |
|
1826 | # filter any nodes that claim to be part of the known set | |
1824 | def prune(revlog, missing): |
|
1827 | def prune(revlog, missing): | |
1825 | return [n for n in missing |
|
1828 | return [n for n in missing | |
1826 | if revlog.linkrev(revlog.rev(n)) not in commonrevs] |
|
1829 | if revlog.linkrev(revlog.rev(n)) not in commonrevs] | |
1827 |
|
1830 | |||
1828 | def lookup(revlog, x): |
|
1831 | def lookup(revlog, x): | |
1829 | if revlog == cl: |
|
1832 | if revlog == cl: | |
1830 | c = cl.read(x) |
|
1833 | c = cl.read(x) | |
1831 | changedfiles.update(c[3]) |
|
1834 | changedfiles.update(c[3]) | |
1832 | mfs.setdefault(c[0], x) |
|
1835 | mfs.setdefault(c[0], x) | |
1833 | count[0] += 1 |
|
1836 | count[0] += 1 | |
1834 | self.ui.progress(_('bundling'), count[0], |
|
1837 | self.ui.progress(_('bundling'), count[0], | |
1835 | unit=_('changesets'), total=len(csets)) |
|
1838 | unit=_('changesets'), total=len(csets)) | |
1836 | return x |
|
1839 | return x | |
1837 | elif revlog == mf: |
|
1840 | elif revlog == mf: | |
1838 | clnode = mfs[x] |
|
1841 | clnode = mfs[x] | |
1839 | mdata = mf.readfast(x) |
|
1842 | mdata = mf.readfast(x) | |
1840 | for f in changedfiles: |
|
1843 | for f in changedfiles: | |
1841 | if f in mdata: |
|
1844 | if f in mdata: | |
1842 | fnodes.setdefault(f, {}).setdefault(mdata[f], clnode) |
|
1845 | fnodes.setdefault(f, {}).setdefault(mdata[f], clnode) | |
1843 | count[0] += 1 |
|
1846 | count[0] += 1 | |
1844 | self.ui.progress(_('bundling'), count[0], |
|
1847 | self.ui.progress(_('bundling'), count[0], | |
1845 | unit=_('manifests'), total=len(mfs)) |
|
1848 | unit=_('manifests'), total=len(mfs)) | |
1846 | return mfs[x] |
|
1849 | return mfs[x] | |
1847 | else: |
|
1850 | else: | |
1848 | self.ui.progress( |
|
1851 | self.ui.progress( | |
1849 | _('bundling'), count[0], item=fstate[0], |
|
1852 | _('bundling'), count[0], item=fstate[0], | |
1850 | unit=_('files'), total=len(changedfiles)) |
|
1853 | unit=_('files'), total=len(changedfiles)) | |
1851 | return fstate[1][x] |
|
1854 | return fstate[1][x] | |
1852 |
|
1855 | |||
1853 | bundler = changegroup.bundle10(lookup) |
|
1856 | bundler = changegroup.bundle10(lookup) | |
1854 | reorder = self.ui.config('bundle', 'reorder', 'auto') |
|
1857 | reorder = self.ui.config('bundle', 'reorder', 'auto') | |
1855 | if reorder == 'auto': |
|
1858 | if reorder == 'auto': | |
1856 | reorder = None |
|
1859 | reorder = None | |
1857 | else: |
|
1860 | else: | |
1858 | reorder = util.parsebool(reorder) |
|
1861 | reorder = util.parsebool(reorder) | |
1859 |
|
1862 | |||
1860 | def gengroup(): |
|
1863 | def gengroup(): | |
1861 | # Create a changenode group generator that will call our functions |
|
1864 | # Create a changenode group generator that will call our functions | |
1862 | # back to lookup the owning changenode and collect information. |
|
1865 | # back to lookup the owning changenode and collect information. | |
1863 | for chunk in cl.group(csets, bundler, reorder=reorder): |
|
1866 | for chunk in cl.group(csets, bundler, reorder=reorder): | |
1864 | yield chunk |
|
1867 | yield chunk | |
1865 | self.ui.progress(_('bundling'), None) |
|
1868 | self.ui.progress(_('bundling'), None) | |
1866 |
|
1869 | |||
1867 | # Create a generator for the manifestnodes that calls our lookup |
|
1870 | # Create a generator for the manifestnodes that calls our lookup | |
1868 | # and data collection functions back. |
|
1871 | # and data collection functions back. | |
1869 | count[0] = 0 |
|
1872 | count[0] = 0 | |
1870 | for chunk in mf.group(prune(mf, mfs), bundler, reorder=reorder): |
|
1873 | for chunk in mf.group(prune(mf, mfs), bundler, reorder=reorder): | |
1871 | yield chunk |
|
1874 | yield chunk | |
1872 | self.ui.progress(_('bundling'), None) |
|
1875 | self.ui.progress(_('bundling'), None) | |
1873 |
|
1876 | |||
1874 | mfs.clear() |
|
1877 | mfs.clear() | |
1875 |
|
1878 | |||
1876 | # Go through all our files in order sorted by name. |
|
1879 | # Go through all our files in order sorted by name. | |
1877 | count[0] = 0 |
|
1880 | count[0] = 0 | |
1878 | for fname in sorted(changedfiles): |
|
1881 | for fname in sorted(changedfiles): | |
1879 | filerevlog = self.file(fname) |
|
1882 | filerevlog = self.file(fname) | |
1880 | if not len(filerevlog): |
|
1883 | if not len(filerevlog): | |
1881 | raise util.Abort(_("empty or missing revlog for %s") % fname) |
|
1884 | raise util.Abort(_("empty or missing revlog for %s") % fname) | |
1882 | fstate[0] = fname |
|
1885 | fstate[0] = fname | |
1883 | fstate[1] = fnodes.pop(fname, {}) |
|
1886 | fstate[1] = fnodes.pop(fname, {}) | |
1884 |
|
1887 | |||
1885 | nodelist = prune(filerevlog, fstate[1]) |
|
1888 | nodelist = prune(filerevlog, fstate[1]) | |
1886 | if nodelist: |
|
1889 | if nodelist: | |
1887 | count[0] += 1 |
|
1890 | count[0] += 1 | |
1888 | yield bundler.fileheader(fname) |
|
1891 | yield bundler.fileheader(fname) | |
1889 | for chunk in filerevlog.group(nodelist, bundler, reorder): |
|
1892 | for chunk in filerevlog.group(nodelist, bundler, reorder): | |
1890 | yield chunk |
|
1893 | yield chunk | |
1891 |
|
1894 | |||
1892 | # Signal that no more groups are left. |
|
1895 | # Signal that no more groups are left. | |
1893 | yield bundler.close() |
|
1896 | yield bundler.close() | |
1894 | self.ui.progress(_('bundling'), None) |
|
1897 | self.ui.progress(_('bundling'), None) | |
1895 |
|
1898 | |||
1896 | if csets: |
|
1899 | if csets: | |
1897 | self.hook('outgoing', node=hex(csets[0]), source=source) |
|
1900 | self.hook('outgoing', node=hex(csets[0]), source=source) | |
1898 |
|
1901 | |||
1899 | return changegroup.unbundle10(util.chunkbuffer(gengroup()), 'UN') |
|
1902 | return changegroup.unbundle10(util.chunkbuffer(gengroup()), 'UN') | |
1900 |
|
1903 | |||
1901 | def changegroup(self, basenodes, source): |
|
1904 | def changegroup(self, basenodes, source): | |
1902 | # to avoid a race we use changegroupsubset() (issue1320) |
|
1905 | # to avoid a race we use changegroupsubset() (issue1320) | |
1903 | return self.changegroupsubset(basenodes, self.heads(), source) |
|
1906 | return self.changegroupsubset(basenodes, self.heads(), source) | |
1904 |
|
1907 | |||
1905 | def _changegroup(self, nodes, source): |
|
1908 | def _changegroup(self, nodes, source): | |
1906 | """Compute the changegroup of all nodes that we have that a recipient |
|
1909 | """Compute the changegroup of all nodes that we have that a recipient | |
1907 | doesn't. Return a chunkbuffer object whose read() method will return |
|
1910 | doesn't. Return a chunkbuffer object whose read() method will return | |
1908 | successive changegroup chunks. |
|
1911 | successive changegroup chunks. | |
1909 |
|
1912 | |||
1910 | This is much easier than the previous function as we can assume that |
|
1913 | This is much easier than the previous function as we can assume that | |
1911 | the recipient has any changenode we aren't sending them. |
|
1914 | the recipient has any changenode we aren't sending them. | |
1912 |
|
1915 | |||
1913 | nodes is the set of nodes to send""" |
|
1916 | nodes is the set of nodes to send""" | |
1914 |
|
1917 | |||
1915 | cl = self.changelog |
|
1918 | cl = self.changelog | |
1916 | mf = self.manifest |
|
1919 | mf = self.manifest | |
1917 | mfs = {} |
|
1920 | mfs = {} | |
1918 | changedfiles = set() |
|
1921 | changedfiles = set() | |
1919 | fstate = [''] |
|
1922 | fstate = [''] | |
1920 | count = [0] |
|
1923 | count = [0] | |
1921 |
|
1924 | |||
1922 | self.hook('preoutgoing', throw=True, source=source) |
|
1925 | self.hook('preoutgoing', throw=True, source=source) | |
1923 | self.changegroupinfo(nodes, source) |
|
1926 | self.changegroupinfo(nodes, source) | |
1924 |
|
1927 | |||
1925 | revset = set([cl.rev(n) for n in nodes]) |
|
1928 | revset = set([cl.rev(n) for n in nodes]) | |
1926 |
|
1929 | |||
1927 | def gennodelst(log): |
|
1930 | def gennodelst(log): | |
1928 | return [log.node(r) for r in log if log.linkrev(r) in revset] |
|
1931 | return [log.node(r) for r in log if log.linkrev(r) in revset] | |
1929 |
|
1932 | |||
1930 | def lookup(revlog, x): |
|
1933 | def lookup(revlog, x): | |
1931 | if revlog == cl: |
|
1934 | if revlog == cl: | |
1932 | c = cl.read(x) |
|
1935 | c = cl.read(x) | |
1933 | changedfiles.update(c[3]) |
|
1936 | changedfiles.update(c[3]) | |
1934 | mfs.setdefault(c[0], x) |
|
1937 | mfs.setdefault(c[0], x) | |
1935 | count[0] += 1 |
|
1938 | count[0] += 1 | |
1936 | self.ui.progress(_('bundling'), count[0], |
|
1939 | self.ui.progress(_('bundling'), count[0], | |
1937 | unit=_('changesets'), total=len(nodes)) |
|
1940 | unit=_('changesets'), total=len(nodes)) | |
1938 | return x |
|
1941 | return x | |
1939 | elif revlog == mf: |
|
1942 | elif revlog == mf: | |
1940 | count[0] += 1 |
|
1943 | count[0] += 1 | |
1941 | self.ui.progress(_('bundling'), count[0], |
|
1944 | self.ui.progress(_('bundling'), count[0], | |
1942 | unit=_('manifests'), total=len(mfs)) |
|
1945 | unit=_('manifests'), total=len(mfs)) | |
1943 | return cl.node(revlog.linkrev(revlog.rev(x))) |
|
1946 | return cl.node(revlog.linkrev(revlog.rev(x))) | |
1944 | else: |
|
1947 | else: | |
1945 | self.ui.progress( |
|
1948 | self.ui.progress( | |
1946 | _('bundling'), count[0], item=fstate[0], |
|
1949 | _('bundling'), count[0], item=fstate[0], | |
1947 | total=len(changedfiles), unit=_('files')) |
|
1950 | total=len(changedfiles), unit=_('files')) | |
1948 | return cl.node(revlog.linkrev(revlog.rev(x))) |
|
1951 | return cl.node(revlog.linkrev(revlog.rev(x))) | |
1949 |
|
1952 | |||
1950 | bundler = changegroup.bundle10(lookup) |
|
1953 | bundler = changegroup.bundle10(lookup) | |
1951 | reorder = self.ui.config('bundle', 'reorder', 'auto') |
|
1954 | reorder = self.ui.config('bundle', 'reorder', 'auto') | |
1952 | if reorder == 'auto': |
|
1955 | if reorder == 'auto': | |
1953 | reorder = None |
|
1956 | reorder = None | |
1954 | else: |
|
1957 | else: | |
1955 | reorder = util.parsebool(reorder) |
|
1958 | reorder = util.parsebool(reorder) | |
1956 |
|
1959 | |||
1957 | def gengroup(): |
|
1960 | def gengroup(): | |
1958 | '''yield a sequence of changegroup chunks (strings)''' |
|
1961 | '''yield a sequence of changegroup chunks (strings)''' | |
1959 | # construct a list of all changed files |
|
1962 | # construct a list of all changed files | |
1960 |
|
1963 | |||
1961 | for chunk in cl.group(nodes, bundler, reorder=reorder): |
|
1964 | for chunk in cl.group(nodes, bundler, reorder=reorder): | |
1962 | yield chunk |
|
1965 | yield chunk | |
1963 | self.ui.progress(_('bundling'), None) |
|
1966 | self.ui.progress(_('bundling'), None) | |
1964 |
|
1967 | |||
1965 | count[0] = 0 |
|
1968 | count[0] = 0 | |
1966 | for chunk in mf.group(gennodelst(mf), bundler, reorder=reorder): |
|
1969 | for chunk in mf.group(gennodelst(mf), bundler, reorder=reorder): | |
1967 | yield chunk |
|
1970 | yield chunk | |
1968 | self.ui.progress(_('bundling'), None) |
|
1971 | self.ui.progress(_('bundling'), None) | |
1969 |
|
1972 | |||
1970 | count[0] = 0 |
|
1973 | count[0] = 0 | |
1971 | for fname in sorted(changedfiles): |
|
1974 | for fname in sorted(changedfiles): | |
1972 | filerevlog = self.file(fname) |
|
1975 | filerevlog = self.file(fname) | |
1973 | if not len(filerevlog): |
|
1976 | if not len(filerevlog): | |
1974 | raise util.Abort(_("empty or missing revlog for %s") % fname) |
|
1977 | raise util.Abort(_("empty or missing revlog for %s") % fname) | |
1975 | fstate[0] = fname |
|
1978 | fstate[0] = fname | |
1976 | nodelist = gennodelst(filerevlog) |
|
1979 | nodelist = gennodelst(filerevlog) | |
1977 | if nodelist: |
|
1980 | if nodelist: | |
1978 | count[0] += 1 |
|
1981 | count[0] += 1 | |
1979 | yield bundler.fileheader(fname) |
|
1982 | yield bundler.fileheader(fname) | |
1980 | for chunk in filerevlog.group(nodelist, bundler, reorder): |
|
1983 | for chunk in filerevlog.group(nodelist, bundler, reorder): | |
1981 | yield chunk |
|
1984 | yield chunk | |
1982 | yield bundler.close() |
|
1985 | yield bundler.close() | |
1983 | self.ui.progress(_('bundling'), None) |
|
1986 | self.ui.progress(_('bundling'), None) | |
1984 |
|
1987 | |||
1985 | if nodes: |
|
1988 | if nodes: | |
1986 | self.hook('outgoing', node=hex(nodes[0]), source=source) |
|
1989 | self.hook('outgoing', node=hex(nodes[0]), source=source) | |
1987 |
|
1990 | |||
1988 | return changegroup.unbundle10(util.chunkbuffer(gengroup()), 'UN') |
|
1991 | return changegroup.unbundle10(util.chunkbuffer(gengroup()), 'UN') | |
1989 |
|
1992 | |||
1990 | def addchangegroup(self, source, srctype, url, emptyok=False): |
|
1993 | def addchangegroup(self, source, srctype, url, emptyok=False): | |
1991 | """Add the changegroup returned by source.read() to this repo. |
|
1994 | """Add the changegroup returned by source.read() to this repo. | |
1992 | srctype is a string like 'push', 'pull', or 'unbundle'. url is |
|
1995 | srctype is a string like 'push', 'pull', or 'unbundle'. url is | |
1993 | the URL of the repo where this changegroup is coming from. |
|
1996 | the URL of the repo where this changegroup is coming from. | |
1994 |
|
1997 | |||
1995 | Return an integer summarizing the change to this repo: |
|
1998 | Return an integer summarizing the change to this repo: | |
1996 | - nothing changed or no source: 0 |
|
1999 | - nothing changed or no source: 0 | |
1997 | - more heads than before: 1+added heads (2..n) |
|
2000 | - more heads than before: 1+added heads (2..n) | |
1998 | - fewer heads than before: -1-removed heads (-2..-n) |
|
2001 | - fewer heads than before: -1-removed heads (-2..-n) | |
1999 | - number of heads stays the same: 1 |
|
2002 | - number of heads stays the same: 1 | |
2000 | """ |
|
2003 | """ | |
2001 | def csmap(x): |
|
2004 | def csmap(x): | |
2002 | self.ui.debug("add changeset %s\n" % short(x)) |
|
2005 | self.ui.debug("add changeset %s\n" % short(x)) | |
2003 | return len(cl) |
|
2006 | return len(cl) | |
2004 |
|
2007 | |||
2005 | def revmap(x): |
|
2008 | def revmap(x): | |
2006 | return cl.rev(x) |
|
2009 | return cl.rev(x) | |
2007 |
|
2010 | |||
2008 | if not source: |
|
2011 | if not source: | |
2009 | return 0 |
|
2012 | return 0 | |
2010 |
|
2013 | |||
2011 | self.hook('prechangegroup', throw=True, source=srctype, url=url) |
|
2014 | self.hook('prechangegroup', throw=True, source=srctype, url=url) | |
2012 |
|
2015 | |||
2013 | changesets = files = revisions = 0 |
|
2016 | changesets = files = revisions = 0 | |
2014 | efiles = set() |
|
2017 | efiles = set() | |
2015 |
|
2018 | |||
2016 | # write changelog data to temp files so concurrent readers will not see |
|
2019 | # write changelog data to temp files so concurrent readers will not see | |
2017 | # inconsistent view |
|
2020 | # inconsistent view | |
2018 | cl = self.changelog |
|
2021 | cl = self.changelog | |
2019 | cl.delayupdate() |
|
2022 | cl.delayupdate() | |
2020 | oldheads = cl.heads() |
|
2023 | oldheads = cl.heads() | |
2021 |
|
2024 | |||
2022 | tr = self.transaction("\n".join([srctype, util.hidepassword(url)])) |
|
2025 | tr = self.transaction("\n".join([srctype, util.hidepassword(url)])) | |
2023 | try: |
|
2026 | try: | |
2024 | trp = weakref.proxy(tr) |
|
2027 | trp = weakref.proxy(tr) | |
2025 | # pull off the changeset group |
|
2028 | # pull off the changeset group | |
2026 | self.ui.status(_("adding changesets\n")) |
|
2029 | self.ui.status(_("adding changesets\n")) | |
2027 | clstart = len(cl) |
|
2030 | clstart = len(cl) | |
2028 | class prog(object): |
|
2031 | class prog(object): | |
2029 | step = _('changesets') |
|
2032 | step = _('changesets') | |
2030 | count = 1 |
|
2033 | count = 1 | |
2031 | ui = self.ui |
|
2034 | ui = self.ui | |
2032 | total = None |
|
2035 | total = None | |
2033 | def __call__(self): |
|
2036 | def __call__(self): | |
2034 | self.ui.progress(self.step, self.count, unit=_('chunks'), |
|
2037 | self.ui.progress(self.step, self.count, unit=_('chunks'), | |
2035 | total=self.total) |
|
2038 | total=self.total) | |
2036 | self.count += 1 |
|
2039 | self.count += 1 | |
2037 | pr = prog() |
|
2040 | pr = prog() | |
2038 | source.callback = pr |
|
2041 | source.callback = pr | |
2039 |
|
2042 | |||
2040 | source.changelogheader() |
|
2043 | source.changelogheader() | |
2041 | srccontent = cl.addgroup(source, csmap, trp) |
|
2044 | srccontent = cl.addgroup(source, csmap, trp) | |
2042 | if not (srccontent or emptyok): |
|
2045 | if not (srccontent or emptyok): | |
2043 | raise util.Abort(_("received changelog group is empty")) |
|
2046 | raise util.Abort(_("received changelog group is empty")) | |
2044 | clend = len(cl) |
|
2047 | clend = len(cl) | |
2045 | changesets = clend - clstart |
|
2048 | changesets = clend - clstart | |
2046 | for c in xrange(clstart, clend): |
|
2049 | for c in xrange(clstart, clend): | |
2047 | efiles.update(self[c].files()) |
|
2050 | efiles.update(self[c].files()) | |
2048 | efiles = len(efiles) |
|
2051 | efiles = len(efiles) | |
2049 | self.ui.progress(_('changesets'), None) |
|
2052 | self.ui.progress(_('changesets'), None) | |
2050 |
|
2053 | |||
2051 | # pull off the manifest group |
|
2054 | # pull off the manifest group | |
2052 | self.ui.status(_("adding manifests\n")) |
|
2055 | self.ui.status(_("adding manifests\n")) | |
2053 | pr.step = _('manifests') |
|
2056 | pr.step = _('manifests') | |
2054 | pr.count = 1 |
|
2057 | pr.count = 1 | |
2055 | pr.total = changesets # manifests <= changesets |
|
2058 | pr.total = changesets # manifests <= changesets | |
2056 | # no need to check for empty manifest group here: |
|
2059 | # no need to check for empty manifest group here: | |
2057 | # if the result of the merge of 1 and 2 is the same in 3 and 4, |
|
2060 | # if the result of the merge of 1 and 2 is the same in 3 and 4, | |
2058 | # no new manifest will be created and the manifest group will |
|
2061 | # no new manifest will be created and the manifest group will | |
2059 | # be empty during the pull |
|
2062 | # be empty during the pull | |
2060 | source.manifestheader() |
|
2063 | source.manifestheader() | |
2061 | self.manifest.addgroup(source, revmap, trp) |
|
2064 | self.manifest.addgroup(source, revmap, trp) | |
2062 | self.ui.progress(_('manifests'), None) |
|
2065 | self.ui.progress(_('manifests'), None) | |
2063 |
|
2066 | |||
2064 | needfiles = {} |
|
2067 | needfiles = {} | |
2065 | if self.ui.configbool('server', 'validate', default=False): |
|
2068 | if self.ui.configbool('server', 'validate', default=False): | |
2066 | # validate incoming csets have their manifests |
|
2069 | # validate incoming csets have their manifests | |
2067 | for cset in xrange(clstart, clend): |
|
2070 | for cset in xrange(clstart, clend): | |
2068 | mfest = self.changelog.read(self.changelog.node(cset))[0] |
|
2071 | mfest = self.changelog.read(self.changelog.node(cset))[0] | |
2069 | mfest = self.manifest.readdelta(mfest) |
|
2072 | mfest = self.manifest.readdelta(mfest) | |
2070 | # store file nodes we must see |
|
2073 | # store file nodes we must see | |
2071 | for f, n in mfest.iteritems(): |
|
2074 | for f, n in mfest.iteritems(): | |
2072 | needfiles.setdefault(f, set()).add(n) |
|
2075 | needfiles.setdefault(f, set()).add(n) | |
2073 |
|
2076 | |||
2074 | # process the files |
|
2077 | # process the files | |
2075 | self.ui.status(_("adding file changes\n")) |
|
2078 | self.ui.status(_("adding file changes\n")) | |
2076 | pr.step = _('files') |
|
2079 | pr.step = _('files') | |
2077 | pr.count = 1 |
|
2080 | pr.count = 1 | |
2078 | pr.total = efiles |
|
2081 | pr.total = efiles | |
2079 | source.callback = None |
|
2082 | source.callback = None | |
2080 |
|
2083 | |||
2081 | while True: |
|
2084 | while True: | |
2082 | chunkdata = source.filelogheader() |
|
2085 | chunkdata = source.filelogheader() | |
2083 | if not chunkdata: |
|
2086 | if not chunkdata: | |
2084 | break |
|
2087 | break | |
2085 | f = chunkdata["filename"] |
|
2088 | f = chunkdata["filename"] | |
2086 | self.ui.debug("adding %s revisions\n" % f) |
|
2089 | self.ui.debug("adding %s revisions\n" % f) | |
2087 | pr() |
|
2090 | pr() | |
2088 | fl = self.file(f) |
|
2091 | fl = self.file(f) | |
2089 | o = len(fl) |
|
2092 | o = len(fl) | |
2090 | if not fl.addgroup(source, revmap, trp): |
|
2093 | if not fl.addgroup(source, revmap, trp): | |
2091 | raise util.Abort(_("received file revlog group is empty")) |
|
2094 | raise util.Abort(_("received file revlog group is empty")) | |
2092 | revisions += len(fl) - o |
|
2095 | revisions += len(fl) - o | |
2093 | files += 1 |
|
2096 | files += 1 | |
2094 | if f in needfiles: |
|
2097 | if f in needfiles: | |
2095 | needs = needfiles[f] |
|
2098 | needs = needfiles[f] | |
2096 | for new in xrange(o, len(fl)): |
|
2099 | for new in xrange(o, len(fl)): | |
2097 | n = fl.node(new) |
|
2100 | n = fl.node(new) | |
2098 | if n in needs: |
|
2101 | if n in needs: | |
2099 | needs.remove(n) |
|
2102 | needs.remove(n) | |
2100 | if not needs: |
|
2103 | if not needs: | |
2101 | del needfiles[f] |
|
2104 | del needfiles[f] | |
2102 | self.ui.progress(_('files'), None) |
|
2105 | self.ui.progress(_('files'), None) | |
2103 |
|
2106 | |||
2104 | for f, needs in needfiles.iteritems(): |
|
2107 | for f, needs in needfiles.iteritems(): | |
2105 | fl = self.file(f) |
|
2108 | fl = self.file(f) | |
2106 | for n in needs: |
|
2109 | for n in needs: | |
2107 | try: |
|
2110 | try: | |
2108 | fl.rev(n) |
|
2111 | fl.rev(n) | |
2109 | except error.LookupError: |
|
2112 | except error.LookupError: | |
2110 | raise util.Abort( |
|
2113 | raise util.Abort( | |
2111 | _('missing file data for %s:%s - run hg verify') % |
|
2114 | _('missing file data for %s:%s - run hg verify') % | |
2112 | (f, hex(n))) |
|
2115 | (f, hex(n))) | |
2113 |
|
2116 | |||
2114 | dh = 0 |
|
2117 | dh = 0 | |
2115 | if oldheads: |
|
2118 | if oldheads: | |
2116 | heads = cl.heads() |
|
2119 | heads = cl.heads() | |
2117 | dh = len(heads) - len(oldheads) |
|
2120 | dh = len(heads) - len(oldheads) | |
2118 | for h in heads: |
|
2121 | for h in heads: | |
2119 | if h not in oldheads and 'close' in self[h].extra(): |
|
2122 | if h not in oldheads and 'close' in self[h].extra(): | |
2120 | dh -= 1 |
|
2123 | dh -= 1 | |
2121 | htext = "" |
|
2124 | htext = "" | |
2122 | if dh: |
|
2125 | if dh: | |
2123 | htext = _(" (%+d heads)") % dh |
|
2126 | htext = _(" (%+d heads)") % dh | |
2124 |
|
2127 | |||
2125 | self.ui.status(_("added %d changesets" |
|
2128 | self.ui.status(_("added %d changesets" | |
2126 | " with %d changes to %d files%s\n") |
|
2129 | " with %d changes to %d files%s\n") | |
2127 | % (changesets, revisions, files, htext)) |
|
2130 | % (changesets, revisions, files, htext)) | |
2128 |
|
2131 | |||
2129 | if changesets > 0: |
|
2132 | if changesets > 0: | |
2130 | p = lambda: cl.writepending() and self.root or "" |
|
2133 | p = lambda: cl.writepending() and self.root or "" | |
2131 | self.hook('pretxnchangegroup', throw=True, |
|
2134 | self.hook('pretxnchangegroup', throw=True, | |
2132 | node=hex(cl.node(clstart)), source=srctype, |
|
2135 | node=hex(cl.node(clstart)), source=srctype, | |
2133 | url=url, pending=p) |
|
2136 | url=url, pending=p) | |
2134 |
|
2137 | |||
2135 | added = [cl.node(r) for r in xrange(clstart, clend)] |
|
2138 | added = [cl.node(r) for r in xrange(clstart, clend)] | |
2136 | publishing = self.ui.configbool('phases', 'publish', True) |
|
2139 | publishing = self.ui.configbool('phases', 'publish', True) | |
2137 | if srctype == 'push': |
|
2140 | if srctype == 'push': | |
2138 | # Old server can not push the boundary themself. |
|
2141 | # Old server can not push the boundary themself. | |
2139 | # New server won't push the boundary if changeset already |
|
2142 | # New server won't push the boundary if changeset already | |
2140 | # existed locally as secrete |
|
2143 | # existed locally as secrete | |
2141 | # |
|
2144 | # | |
2142 | # We should not use added here but the list of all change in |
|
2145 | # We should not use added here but the list of all change in | |
2143 | # the bundle |
|
2146 | # the bundle | |
2144 | if publishing: |
|
2147 | if publishing: | |
2145 | phases.advanceboundary(self, phases.public, srccontent) |
|
2148 | phases.advanceboundary(self, phases.public, srccontent) | |
2146 | else: |
|
2149 | else: | |
2147 | phases.advanceboundary(self, phases.draft, srccontent) |
|
2150 | phases.advanceboundary(self, phases.draft, srccontent) | |
2148 | phases.retractboundary(self, phases.draft, added) |
|
2151 | phases.retractboundary(self, phases.draft, added) | |
2149 | elif srctype != 'strip': |
|
2152 | elif srctype != 'strip': | |
2150 | # publishing only alter behavior during push |
|
2153 | # publishing only alter behavior during push | |
2151 | # |
|
2154 | # | |
2152 | # strip should not touch boundary at all |
|
2155 | # strip should not touch boundary at all | |
2153 | phases.retractboundary(self, phases.draft, added) |
|
2156 | phases.retractboundary(self, phases.draft, added) | |
2154 |
|
2157 | |||
2155 | # make changelog see real files again |
|
2158 | # make changelog see real files again | |
2156 | cl.finalize(trp) |
|
2159 | cl.finalize(trp) | |
2157 |
|
2160 | |||
2158 | tr.close() |
|
2161 | tr.close() | |
2159 |
|
2162 | |||
2160 | if changesets > 0: |
|
2163 | if changesets > 0: | |
2161 | def runhooks(): |
|
2164 | def runhooks(): | |
2162 | # forcefully update the on-disk branch cache |
|
2165 | # forcefully update the on-disk branch cache | |
2163 | self.ui.debug("updating the branch cache\n") |
|
2166 | self.ui.debug("updating the branch cache\n") | |
2164 | self.updatebranchcache() |
|
2167 | self.updatebranchcache() | |
2165 | self.hook("changegroup", node=hex(cl.node(clstart)), |
|
2168 | self.hook("changegroup", node=hex(cl.node(clstart)), | |
2166 | source=srctype, url=url) |
|
2169 | source=srctype, url=url) | |
2167 |
|
2170 | |||
2168 | for n in added: |
|
2171 | for n in added: | |
2169 | self.hook("incoming", node=hex(n), source=srctype, |
|
2172 | self.hook("incoming", node=hex(n), source=srctype, | |
2170 | url=url) |
|
2173 | url=url) | |
2171 | self._afterlock(runhooks) |
|
2174 | self._afterlock(runhooks) | |
2172 |
|
2175 | |||
2173 | finally: |
|
2176 | finally: | |
2174 | tr.release() |
|
2177 | tr.release() | |
2175 | # never return 0 here: |
|
2178 | # never return 0 here: | |
2176 | if dh < 0: |
|
2179 | if dh < 0: | |
2177 | return dh - 1 |
|
2180 | return dh - 1 | |
2178 | else: |
|
2181 | else: | |
2179 | return dh + 1 |
|
2182 | return dh + 1 | |
2180 |
|
2183 | |||
2181 | def stream_in(self, remote, requirements): |
|
2184 | def stream_in(self, remote, requirements): | |
2182 | lock = self.lock() |
|
2185 | lock = self.lock() | |
2183 | try: |
|
2186 | try: | |
2184 | fp = remote.stream_out() |
|
2187 | fp = remote.stream_out() | |
2185 | l = fp.readline() |
|
2188 | l = fp.readline() | |
2186 | try: |
|
2189 | try: | |
2187 | resp = int(l) |
|
2190 | resp = int(l) | |
2188 | except ValueError: |
|
2191 | except ValueError: | |
2189 | raise error.ResponseError( |
|
2192 | raise error.ResponseError( | |
2190 | _('Unexpected response from remote server:'), l) |
|
2193 | _('Unexpected response from remote server:'), l) | |
2191 | if resp == 1: |
|
2194 | if resp == 1: | |
2192 | raise util.Abort(_('operation forbidden by server')) |
|
2195 | raise util.Abort(_('operation forbidden by server')) | |
2193 | elif resp == 2: |
|
2196 | elif resp == 2: | |
2194 | raise util.Abort(_('locking the remote repository failed')) |
|
2197 | raise util.Abort(_('locking the remote repository failed')) | |
2195 | elif resp != 0: |
|
2198 | elif resp != 0: | |
2196 | raise util.Abort(_('the server sent an unknown error code')) |
|
2199 | raise util.Abort(_('the server sent an unknown error code')) | |
2197 | self.ui.status(_('streaming all changes\n')) |
|
2200 | self.ui.status(_('streaming all changes\n')) | |
2198 | l = fp.readline() |
|
2201 | l = fp.readline() | |
2199 | try: |
|
2202 | try: | |
2200 | total_files, total_bytes = map(int, l.split(' ', 1)) |
|
2203 | total_files, total_bytes = map(int, l.split(' ', 1)) | |
2201 | except (ValueError, TypeError): |
|
2204 | except (ValueError, TypeError): | |
2202 | raise error.ResponseError( |
|
2205 | raise error.ResponseError( | |
2203 | _('Unexpected response from remote server:'), l) |
|
2206 | _('Unexpected response from remote server:'), l) | |
2204 | self.ui.status(_('%d files to transfer, %s of data\n') % |
|
2207 | self.ui.status(_('%d files to transfer, %s of data\n') % | |
2205 | (total_files, util.bytecount(total_bytes))) |
|
2208 | (total_files, util.bytecount(total_bytes))) | |
2206 | start = time.time() |
|
2209 | start = time.time() | |
2207 | for i in xrange(total_files): |
|
2210 | for i in xrange(total_files): | |
2208 | # XXX doesn't support '\n' or '\r' in filenames |
|
2211 | # XXX doesn't support '\n' or '\r' in filenames | |
2209 | l = fp.readline() |
|
2212 | l = fp.readline() | |
2210 | try: |
|
2213 | try: | |
2211 | name, size = l.split('\0', 1) |
|
2214 | name, size = l.split('\0', 1) | |
2212 | size = int(size) |
|
2215 | size = int(size) | |
2213 | except (ValueError, TypeError): |
|
2216 | except (ValueError, TypeError): | |
2214 | raise error.ResponseError( |
|
2217 | raise error.ResponseError( | |
2215 | _('Unexpected response from remote server:'), l) |
|
2218 | _('Unexpected response from remote server:'), l) | |
2216 | self.ui.debug('adding %s (%s)\n' % (name, util.bytecount(size))) |
|
2219 | self.ui.debug('adding %s (%s)\n' % (name, util.bytecount(size))) | |
2217 | # for backwards compat, name was partially encoded |
|
2220 | # for backwards compat, name was partially encoded | |
2218 | ofp = self.sopener(store.decodedir(name), 'w') |
|
2221 | ofp = self.sopener(store.decodedir(name), 'w') | |
2219 | for chunk in util.filechunkiter(fp, limit=size): |
|
2222 | for chunk in util.filechunkiter(fp, limit=size): | |
2220 | ofp.write(chunk) |
|
2223 | ofp.write(chunk) | |
2221 | ofp.close() |
|
2224 | ofp.close() | |
2222 | elapsed = time.time() - start |
|
2225 | elapsed = time.time() - start | |
2223 | if elapsed <= 0: |
|
2226 | if elapsed <= 0: | |
2224 | elapsed = 0.001 |
|
2227 | elapsed = 0.001 | |
2225 | self.ui.status(_('transferred %s in %.1f seconds (%s/sec)\n') % |
|
2228 | self.ui.status(_('transferred %s in %.1f seconds (%s/sec)\n') % | |
2226 | (util.bytecount(total_bytes), elapsed, |
|
2229 | (util.bytecount(total_bytes), elapsed, | |
2227 | util.bytecount(total_bytes / elapsed))) |
|
2230 | util.bytecount(total_bytes / elapsed))) | |
2228 |
|
2231 | |||
2229 | # new requirements = old non-format requirements + new format-related |
|
2232 | # new requirements = old non-format requirements + new format-related | |
2230 | # requirements from the streamed-in repository |
|
2233 | # requirements from the streamed-in repository | |
2231 | requirements.update(set(self.requirements) - self.supportedformats) |
|
2234 | requirements.update(set(self.requirements) - self.supportedformats) | |
2232 | self._applyrequirements(requirements) |
|
2235 | self._applyrequirements(requirements) | |
2233 | self._writerequirements() |
|
2236 | self._writerequirements() | |
2234 |
|
2237 | |||
2235 | self.invalidate() |
|
2238 | self.invalidate() | |
2236 | return len(self.heads()) + 1 |
|
2239 | return len(self.heads()) + 1 | |
2237 | finally: |
|
2240 | finally: | |
2238 | lock.release() |
|
2241 | lock.release() | |
2239 |
|
2242 | |||
2240 | def clone(self, remote, heads=[], stream=False): |
|
2243 | def clone(self, remote, heads=[], stream=False): | |
2241 | '''clone remote repository. |
|
2244 | '''clone remote repository. | |
2242 |
|
2245 | |||
2243 | keyword arguments: |
|
2246 | keyword arguments: | |
2244 | heads: list of revs to clone (forces use of pull) |
|
2247 | heads: list of revs to clone (forces use of pull) | |
2245 | stream: use streaming clone if possible''' |
|
2248 | stream: use streaming clone if possible''' | |
2246 |
|
2249 | |||
2247 | # now, all clients that can request uncompressed clones can |
|
2250 | # now, all clients that can request uncompressed clones can | |
2248 | # read repo formats supported by all servers that can serve |
|
2251 | # read repo formats supported by all servers that can serve | |
2249 | # them. |
|
2252 | # them. | |
2250 |
|
2253 | |||
2251 | # if revlog format changes, client will have to check version |
|
2254 | # if revlog format changes, client will have to check version | |
2252 | # and format flags on "stream" capability, and use |
|
2255 | # and format flags on "stream" capability, and use | |
2253 | # uncompressed only if compatible. |
|
2256 | # uncompressed only if compatible. | |
2254 |
|
2257 | |||
2255 | if stream and not heads: |
|
2258 | if stream and not heads: | |
2256 | # 'stream' means remote revlog format is revlogv1 only |
|
2259 | # 'stream' means remote revlog format is revlogv1 only | |
2257 | if remote.capable('stream'): |
|
2260 | if remote.capable('stream'): | |
2258 | return self.stream_in(remote, set(('revlogv1',))) |
|
2261 | return self.stream_in(remote, set(('revlogv1',))) | |
2259 | # otherwise, 'streamreqs' contains the remote revlog format |
|
2262 | # otherwise, 'streamreqs' contains the remote revlog format | |
2260 | streamreqs = remote.capable('streamreqs') |
|
2263 | streamreqs = remote.capable('streamreqs') | |
2261 | if streamreqs: |
|
2264 | if streamreqs: | |
2262 | streamreqs = set(streamreqs.split(',')) |
|
2265 | streamreqs = set(streamreqs.split(',')) | |
2263 | # if we support it, stream in and adjust our requirements |
|
2266 | # if we support it, stream in and adjust our requirements | |
2264 | if not streamreqs - self.supportedformats: |
|
2267 | if not streamreqs - self.supportedformats: | |
2265 | return self.stream_in(remote, streamreqs) |
|
2268 | return self.stream_in(remote, streamreqs) | |
2266 | return self.pull(remote, heads) |
|
2269 | return self.pull(remote, heads) | |
2267 |
|
2270 | |||
2268 | def pushkey(self, namespace, key, old, new): |
|
2271 | def pushkey(self, namespace, key, old, new): | |
2269 | self.hook('prepushkey', throw=True, namespace=namespace, key=key, |
|
2272 | self.hook('prepushkey', throw=True, namespace=namespace, key=key, | |
2270 | old=old, new=new) |
|
2273 | old=old, new=new) | |
2271 | ret = pushkey.push(self, namespace, key, old, new) |
|
2274 | ret = pushkey.push(self, namespace, key, old, new) | |
2272 | self.hook('pushkey', namespace=namespace, key=key, old=old, new=new, |
|
2275 | self.hook('pushkey', namespace=namespace, key=key, old=old, new=new, | |
2273 | ret=ret) |
|
2276 | ret=ret) | |
2274 | return ret |
|
2277 | return ret | |
2275 |
|
2278 | |||
2276 | def listkeys(self, namespace): |
|
2279 | def listkeys(self, namespace): | |
2277 | self.hook('prelistkeys', throw=True, namespace=namespace) |
|
2280 | self.hook('prelistkeys', throw=True, namespace=namespace) | |
2278 | values = pushkey.list(self, namespace) |
|
2281 | values = pushkey.list(self, namespace) | |
2279 | self.hook('listkeys', namespace=namespace, values=values) |
|
2282 | self.hook('listkeys', namespace=namespace, values=values) | |
2280 | return values |
|
2283 | return values | |
2281 |
|
2284 | |||
2282 | def debugwireargs(self, one, two, three=None, four=None, five=None): |
|
2285 | def debugwireargs(self, one, two, three=None, four=None, five=None): | |
2283 | '''used to test argument passing over the wire''' |
|
2286 | '''used to test argument passing over the wire''' | |
2284 | return "%s %s %s %s %s" % (one, two, three, four, five) |
|
2287 | return "%s %s %s %s %s" % (one, two, three, four, five) | |
2285 |
|
2288 | |||
2286 | def savecommitmessage(self, text): |
|
2289 | def savecommitmessage(self, text): | |
2287 | fp = self.opener('last-message.txt', 'wb') |
|
2290 | fp = self.opener('last-message.txt', 'wb') | |
2288 | try: |
|
2291 | try: | |
2289 | fp.write(text) |
|
2292 | fp.write(text) | |
2290 | finally: |
|
2293 | finally: | |
2291 | fp.close() |
|
2294 | fp.close() | |
2292 | return self.pathto(fp.name[len(self.root)+1:]) |
|
2295 | return self.pathto(fp.name[len(self.root)+1:]) | |
2293 |
|
2296 | |||
2294 | # used to avoid circular references so destructors work |
|
2297 | # used to avoid circular references so destructors work | |
2295 | def aftertrans(files): |
|
2298 | def aftertrans(files): | |
2296 | renamefiles = [tuple(t) for t in files] |
|
2299 | renamefiles = [tuple(t) for t in files] | |
2297 | def a(): |
|
2300 | def a(): | |
2298 | for src, dest in renamefiles: |
|
2301 | for src, dest in renamefiles: | |
2299 | util.rename(src, dest) |
|
2302 | util.rename(src, dest) | |
2300 | return a |
|
2303 | return a | |
2301 |
|
2304 | |||
2302 | def undoname(fn): |
|
2305 | def undoname(fn): | |
2303 | base, name = os.path.split(fn) |
|
2306 | base, name = os.path.split(fn) | |
2304 | assert name.startswith('journal') |
|
2307 | assert name.startswith('journal') | |
2305 | return os.path.join(base, name.replace('journal', 'undo', 1)) |
|
2308 | return os.path.join(base, name.replace('journal', 'undo', 1)) | |
2306 |
|
2309 | |||
2307 | def instance(ui, path, create): |
|
2310 | def instance(ui, path, create): | |
2308 | return localrepository(ui, util.urllocalpath(path), create) |
|
2311 | return localrepository(ui, util.urllocalpath(path), create) | |
2309 |
|
2312 | |||
2310 | def islocal(path): |
|
2313 | def islocal(path): | |
2311 | return True |
|
2314 | return True |
@@ -1,221 +1,232 b'' | |||||
1 | import sys, os, struct, subprocess, cStringIO, re, shutil |
|
1 | import sys, os, struct, subprocess, cStringIO, re, shutil | |
2 |
|
2 | |||
3 | def connect(path=None): |
|
3 | def connect(path=None): | |
4 | cmdline = ['hg', 'serve', '--cmdserver', 'pipe'] |
|
4 | cmdline = ['hg', 'serve', '--cmdserver', 'pipe'] | |
5 | if path: |
|
5 | if path: | |
6 | cmdline += ['-R', path] |
|
6 | cmdline += ['-R', path] | |
7 |
|
7 | |||
8 | server = subprocess.Popen(cmdline, stdin=subprocess.PIPE, |
|
8 | server = subprocess.Popen(cmdline, stdin=subprocess.PIPE, | |
9 | stdout=subprocess.PIPE) |
|
9 | stdout=subprocess.PIPE) | |
10 |
|
10 | |||
11 | return server |
|
11 | return server | |
12 |
|
12 | |||
13 | def writeblock(server, data): |
|
13 | def writeblock(server, data): | |
14 | server.stdin.write(struct.pack('>I', len(data))) |
|
14 | server.stdin.write(struct.pack('>I', len(data))) | |
15 | server.stdin.write(data) |
|
15 | server.stdin.write(data) | |
16 | server.stdin.flush() |
|
16 | server.stdin.flush() | |
17 |
|
17 | |||
18 | def readchannel(server): |
|
18 | def readchannel(server): | |
19 | data = server.stdout.read(5) |
|
19 | data = server.stdout.read(5) | |
20 | if not data: |
|
20 | if not data: | |
21 | raise EOFError() |
|
21 | raise EOFError() | |
22 | channel, length = struct.unpack('>cI', data) |
|
22 | channel, length = struct.unpack('>cI', data) | |
23 | if channel in 'IL': |
|
23 | if channel in 'IL': | |
24 | return channel, length |
|
24 | return channel, length | |
25 | else: |
|
25 | else: | |
26 | return channel, server.stdout.read(length) |
|
26 | return channel, server.stdout.read(length) | |
27 |
|
27 | |||
28 | def runcommand(server, args, output=sys.stdout, error=sys.stderr, input=None): |
|
28 | def runcommand(server, args, output=sys.stdout, error=sys.stderr, input=None): | |
29 | print ' runcommand', ' '.join(args) |
|
29 | print ' runcommand', ' '.join(args) | |
30 | server.stdin.write('runcommand\n') |
|
30 | server.stdin.write('runcommand\n') | |
31 | writeblock(server, '\0'.join(args)) |
|
31 | writeblock(server, '\0'.join(args)) | |
32 |
|
32 | |||
33 | if not input: |
|
33 | if not input: | |
34 | input = cStringIO.StringIO() |
|
34 | input = cStringIO.StringIO() | |
35 |
|
35 | |||
36 | while True: |
|
36 | while True: | |
37 | ch, data = readchannel(server) |
|
37 | ch, data = readchannel(server) | |
38 | if ch == 'o': |
|
38 | if ch == 'o': | |
39 | output.write(data) |
|
39 | output.write(data) | |
40 | output.flush() |
|
40 | output.flush() | |
41 | elif ch == 'e': |
|
41 | elif ch == 'e': | |
42 | error.write(data) |
|
42 | error.write(data) | |
43 | error.flush() |
|
43 | error.flush() | |
44 | elif ch == 'I': |
|
44 | elif ch == 'I': | |
45 | writeblock(server, input.read(data)) |
|
45 | writeblock(server, input.read(data)) | |
46 | elif ch == 'L': |
|
46 | elif ch == 'L': | |
47 | writeblock(server, input.readline(data)) |
|
47 | writeblock(server, input.readline(data)) | |
48 | elif ch == 'r': |
|
48 | elif ch == 'r': | |
49 | return struct.unpack('>i', data)[0] |
|
49 | return struct.unpack('>i', data)[0] | |
50 | else: |
|
50 | else: | |
51 | print "unexpected channel %c: %r" % (ch, data) |
|
51 | print "unexpected channel %c: %r" % (ch, data) | |
52 | if ch.isupper(): |
|
52 | if ch.isupper(): | |
53 | return |
|
53 | return | |
54 |
|
54 | |||
55 | def check(func, repopath=None): |
|
55 | def check(func, repopath=None): | |
56 |
|
56 | |||
57 | print 'testing %s:' % func.__name__ |
|
57 | print 'testing %s:' % func.__name__ | |
58 |
|
58 | |||
59 | server = connect(repopath) |
|
59 | server = connect(repopath) | |
60 | try: |
|
60 | try: | |
61 | return func(server) |
|
61 | return func(server) | |
62 | finally: |
|
62 | finally: | |
63 | server.stdin.close() |
|
63 | server.stdin.close() | |
64 | server.wait() |
|
64 | server.wait() | |
65 |
|
65 | |||
66 | def unknowncommand(server): |
|
66 | def unknowncommand(server): | |
67 | server.stdin.write('unknowncommand\n') |
|
67 | server.stdin.write('unknowncommand\n') | |
68 |
|
68 | |||
69 | def hellomessage(server): |
|
69 | def hellomessage(server): | |
70 | ch, data = readchannel(server) |
|
70 | ch, data = readchannel(server) | |
71 | # escaping python tests output not supported |
|
71 | # escaping python tests output not supported | |
72 | print '%c, %r' % (ch, re.sub('encoding: [a-zA-Z0-9-]+', 'encoding: ***', data)) |
|
72 | print '%c, %r' % (ch, re.sub('encoding: [a-zA-Z0-9-]+', 'encoding: ***', data)) | |
73 |
|
73 | |||
74 | # run an arbitrary command to make sure the next thing the server sends |
|
74 | # run an arbitrary command to make sure the next thing the server sends | |
75 | # isn't part of the hello message |
|
75 | # isn't part of the hello message | |
76 | runcommand(server, ['id']) |
|
76 | runcommand(server, ['id']) | |
77 |
|
77 | |||
78 | def checkruncommand(server): |
|
78 | def checkruncommand(server): | |
79 | # hello block |
|
79 | # hello block | |
80 | readchannel(server) |
|
80 | readchannel(server) | |
81 |
|
81 | |||
82 | # no args |
|
82 | # no args | |
83 | runcommand(server, []) |
|
83 | runcommand(server, []) | |
84 |
|
84 | |||
85 | # global options |
|
85 | # global options | |
86 | runcommand(server, ['id', '--quiet']) |
|
86 | runcommand(server, ['id', '--quiet']) | |
87 |
|
87 | |||
88 | # make sure global options don't stick through requests |
|
88 | # make sure global options don't stick through requests | |
89 | runcommand(server, ['id']) |
|
89 | runcommand(server, ['id']) | |
90 |
|
90 | |||
91 | # --config |
|
91 | # --config | |
92 | runcommand(server, ['id', '--config', 'ui.quiet=True']) |
|
92 | runcommand(server, ['id', '--config', 'ui.quiet=True']) | |
93 |
|
93 | |||
94 | # make sure --config doesn't stick |
|
94 | # make sure --config doesn't stick | |
95 | runcommand(server, ['id']) |
|
95 | runcommand(server, ['id']) | |
96 |
|
96 | |||
97 | def inputeof(server): |
|
97 | def inputeof(server): | |
98 | readchannel(server) |
|
98 | readchannel(server) | |
99 | server.stdin.write('runcommand\n') |
|
99 | server.stdin.write('runcommand\n') | |
100 | # close stdin while server is waiting for input |
|
100 | # close stdin while server is waiting for input | |
101 | server.stdin.close() |
|
101 | server.stdin.close() | |
102 |
|
102 | |||
103 | # server exits with 1 if the pipe closed while reading the command |
|
103 | # server exits with 1 if the pipe closed while reading the command | |
104 | print 'server exit code =', server.wait() |
|
104 | print 'server exit code =', server.wait() | |
105 |
|
105 | |||
106 | def serverinput(server): |
|
106 | def serverinput(server): | |
107 | readchannel(server) |
|
107 | readchannel(server) | |
108 |
|
108 | |||
109 | patch = """ |
|
109 | patch = """ | |
110 | # HG changeset patch |
|
110 | # HG changeset patch | |
111 | # User test |
|
111 | # User test | |
112 | # Date 0 0 |
|
112 | # Date 0 0 | |
113 | # Node ID c103a3dec114d882c98382d684d8af798d09d857 |
|
113 | # Node ID c103a3dec114d882c98382d684d8af798d09d857 | |
114 | # Parent 0000000000000000000000000000000000000000 |
|
114 | # Parent 0000000000000000000000000000000000000000 | |
115 | 1 |
|
115 | 1 | |
116 |
|
116 | |||
117 | diff -r 000000000000 -r c103a3dec114 a |
|
117 | diff -r 000000000000 -r c103a3dec114 a | |
118 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
118 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 | |
119 | +++ b/a Thu Jan 01 00:00:00 1970 +0000 |
|
119 | +++ b/a Thu Jan 01 00:00:00 1970 +0000 | |
120 | @@ -0,0 +1,1 @@ |
|
120 | @@ -0,0 +1,1 @@ | |
121 | +1 |
|
121 | +1 | |
122 | """ |
|
122 | """ | |
123 |
|
123 | |||
124 | runcommand(server, ['import', '-'], input=cStringIO.StringIO(patch)) |
|
124 | runcommand(server, ['import', '-'], input=cStringIO.StringIO(patch)) | |
125 | runcommand(server, ['log']) |
|
125 | runcommand(server, ['log']) | |
126 |
|
126 | |||
127 | def cwd(server): |
|
127 | def cwd(server): | |
128 | """ check that --cwd doesn't persist between requests """ |
|
128 | """ check that --cwd doesn't persist between requests """ | |
129 | readchannel(server) |
|
129 | readchannel(server) | |
130 | os.mkdir('foo') |
|
130 | os.mkdir('foo') | |
131 | f = open('foo/bar', 'wb') |
|
131 | f = open('foo/bar', 'wb') | |
132 | f.write('a') |
|
132 | f.write('a') | |
133 | f.close() |
|
133 | f.close() | |
134 | runcommand(server, ['--cwd', 'foo', 'st', 'bar']) |
|
134 | runcommand(server, ['--cwd', 'foo', 'st', 'bar']) | |
135 | runcommand(server, ['st', 'foo/bar']) |
|
135 | runcommand(server, ['st', 'foo/bar']) | |
136 | os.remove('foo/bar') |
|
136 | os.remove('foo/bar') | |
137 |
|
137 | |||
138 | def localhgrc(server): |
|
138 | def localhgrc(server): | |
139 | """ check that local configs for the cached repo aren't inherited when -R |
|
139 | """ check that local configs for the cached repo aren't inherited when -R | |
140 | is used """ |
|
140 | is used """ | |
141 | readchannel(server) |
|
141 | readchannel(server) | |
142 |
|
142 | |||
143 | # the cached repo local hgrc contains ui.foo=bar, so showconfig should show it |
|
143 | # the cached repo local hgrc contains ui.foo=bar, so showconfig should show it | |
144 | runcommand(server, ['showconfig']) |
|
144 | runcommand(server, ['showconfig']) | |
145 |
|
145 | |||
146 | # but not for this repo |
|
146 | # but not for this repo | |
147 | runcommand(server, ['init', 'foo']) |
|
147 | runcommand(server, ['init', 'foo']) | |
148 | runcommand(server, ['-R', 'foo', 'showconfig', 'ui', 'defaults']) |
|
148 | runcommand(server, ['-R', 'foo', 'showconfig', 'ui', 'defaults']) | |
149 | shutil.rmtree('foo') |
|
149 | shutil.rmtree('foo') | |
150 |
|
150 | |||
151 | def hook(**args): |
|
151 | def hook(**args): | |
152 | print 'hook talking' |
|
152 | print 'hook talking' | |
153 | print 'now try to read something: %r' % sys.stdin.read() |
|
153 | print 'now try to read something: %r' % sys.stdin.read() | |
154 |
|
154 | |||
155 | def hookoutput(server): |
|
155 | def hookoutput(server): | |
156 | readchannel(server) |
|
156 | readchannel(server) | |
157 | runcommand(server, ['--config', |
|
157 | runcommand(server, ['--config', | |
158 | 'hooks.pre-identify=python:test-commandserver.hook', 'id'], |
|
158 | 'hooks.pre-identify=python:test-commandserver.hook', 'id'], | |
159 | input=cStringIO.StringIO('some input')) |
|
159 | input=cStringIO.StringIO('some input')) | |
160 |
|
160 | |||
161 | def outsidechanges(server): |
|
161 | def outsidechanges(server): | |
162 | readchannel(server) |
|
162 | readchannel(server) | |
163 | f = open('a', 'ab') |
|
163 | f = open('a', 'ab') | |
164 | f.write('a\n') |
|
164 | f.write('a\n') | |
165 | f.close() |
|
165 | f.close() | |
166 | runcommand(server, ['status']) |
|
166 | runcommand(server, ['status']) | |
167 | os.system('hg ci -Am2') |
|
167 | os.system('hg ci -Am2') | |
168 | runcommand(server, ['tip']) |
|
168 | runcommand(server, ['tip']) | |
169 | runcommand(server, ['status']) |
|
169 | runcommand(server, ['status']) | |
170 |
|
170 | |||
171 | def bookmarks(server): |
|
171 | def bookmarks(server): | |
172 | readchannel(server) |
|
172 | readchannel(server) | |
173 | runcommand(server, ['bookmarks']) |
|
173 | runcommand(server, ['bookmarks']) | |
174 |
|
174 | |||
175 | # changes .hg/bookmarks |
|
175 | # changes .hg/bookmarks | |
176 | os.system('hg bookmark -i bm1') |
|
176 | os.system('hg bookmark -i bm1') | |
177 | os.system('hg bookmark -i bm2') |
|
177 | os.system('hg bookmark -i bm2') | |
178 | runcommand(server, ['bookmarks']) |
|
178 | runcommand(server, ['bookmarks']) | |
179 |
|
179 | |||
180 | # changes .hg/bookmarks.current |
|
180 | # changes .hg/bookmarks.current | |
181 | os.system('hg upd bm1 -q') |
|
181 | os.system('hg upd bm1 -q') | |
182 | runcommand(server, ['bookmarks']) |
|
182 | runcommand(server, ['bookmarks']) | |
183 |
|
183 | |||
184 | runcommand(server, ['bookmarks', 'bm3']) |
|
184 | runcommand(server, ['bookmarks', 'bm3']) | |
185 | f = open('a', 'ab') |
|
185 | f = open('a', 'ab') | |
186 | f.write('a\n') |
|
186 | f.write('a\n') | |
187 | f.close() |
|
187 | f.close() | |
188 | runcommand(server, ['commit', '-Amm']) |
|
188 | runcommand(server, ['commit', '-Amm']) | |
189 | runcommand(server, ['bookmarks']) |
|
189 | runcommand(server, ['bookmarks']) | |
190 |
|
190 | |||
191 | def tagscache(server): |
|
191 | def tagscache(server): | |
192 | readchannel(server) |
|
192 | readchannel(server) | |
193 | runcommand(server, ['id', '-t', '-r', '0']) |
|
193 | runcommand(server, ['id', '-t', '-r', '0']) | |
194 | os.system('hg tag -r 0 foo') |
|
194 | os.system('hg tag -r 0 foo') | |
195 | runcommand(server, ['id', '-t', '-r', '0']) |
|
195 | runcommand(server, ['id', '-t', '-r', '0']) | |
196 |
|
196 | |||
197 | def setphase(server): |
|
197 | def setphase(server): | |
198 | readchannel(server) |
|
198 | readchannel(server) | |
199 | runcommand(server, ['phase', '-r', '.']) |
|
199 | runcommand(server, ['phase', '-r', '.']) | |
200 | os.system('hg phase -r . -p') |
|
200 | os.system('hg phase -r . -p') | |
201 | runcommand(server, ['phase', '-r', '.']) |
|
201 | runcommand(server, ['phase', '-r', '.']) | |
202 |
|
202 | |||
|
203 | def rollback(server): | |||
|
204 | readchannel(server) | |||
|
205 | runcommand(server, ['phase', '-r', '.', '-p']) | |||
|
206 | f = open('a', 'ab') | |||
|
207 | f.write('a\n') | |||
|
208 | f.close() | |||
|
209 | runcommand(server, ['commit', '-Am.']) | |||
|
210 | runcommand(server, ['rollback']) | |||
|
211 | runcommand(server, ['phase', '-r', '.']) | |||
|
212 | ||||
203 | if __name__ == '__main__': |
|
213 | if __name__ == '__main__': | |
204 | os.system('hg init') |
|
214 | os.system('hg init') | |
205 |
|
215 | |||
206 | check(hellomessage) |
|
216 | check(hellomessage) | |
207 | check(unknowncommand) |
|
217 | check(unknowncommand) | |
208 | check(checkruncommand) |
|
218 | check(checkruncommand) | |
209 | check(inputeof) |
|
219 | check(inputeof) | |
210 | check(serverinput) |
|
220 | check(serverinput) | |
211 | check(cwd) |
|
221 | check(cwd) | |
212 |
|
222 | |||
213 | hgrc = open('.hg/hgrc', 'a') |
|
223 | hgrc = open('.hg/hgrc', 'a') | |
214 | hgrc.write('[ui]\nfoo=bar\n') |
|
224 | hgrc.write('[ui]\nfoo=bar\n') | |
215 | hgrc.close() |
|
225 | hgrc.close() | |
216 | check(localhgrc) |
|
226 | check(localhgrc) | |
217 | check(hookoutput) |
|
227 | check(hookoutput) | |
218 | check(outsidechanges) |
|
228 | check(outsidechanges) | |
219 | check(bookmarks) |
|
229 | check(bookmarks) | |
220 | check(tagscache) |
|
230 | check(tagscache) | |
221 | check(setphase) |
|
231 | check(setphase) | |
|
232 | check(rollback) |
@@ -1,136 +1,147 b'' | |||||
1 |
|
1 | |||
2 | testing hellomessage: |
|
2 | testing hellomessage: | |
3 |
|
3 | |||
4 | o, 'capabilities: getencoding runcommand\nencoding: ***' |
|
4 | o, 'capabilities: getencoding runcommand\nencoding: ***' | |
5 | runcommand id |
|
5 | runcommand id | |
6 | 000000000000 tip |
|
6 | 000000000000 tip | |
7 | abort: unknown command unknowncommand |
|
7 | abort: unknown command unknowncommand | |
8 |
|
8 | |||
9 | testing unknowncommand: |
|
9 | testing unknowncommand: | |
10 |
|
10 | |||
11 |
|
11 | |||
12 | testing checkruncommand: |
|
12 | testing checkruncommand: | |
13 |
|
13 | |||
14 | runcommand |
|
14 | runcommand | |
15 | Mercurial Distributed SCM |
|
15 | Mercurial Distributed SCM | |
16 |
|
16 | |||
17 | basic commands: |
|
17 | basic commands: | |
18 |
|
18 | |||
19 | add add the specified files on the next commit |
|
19 | add add the specified files on the next commit | |
20 | annotate show changeset information by line for each file |
|
20 | annotate show changeset information by line for each file | |
21 | clone make a copy of an existing repository |
|
21 | clone make a copy of an existing repository | |
22 | commit commit the specified files or all outstanding changes |
|
22 | commit commit the specified files or all outstanding changes | |
23 | diff diff repository (or selected files) |
|
23 | diff diff repository (or selected files) | |
24 | export dump the header and diffs for one or more changesets |
|
24 | export dump the header and diffs for one or more changesets | |
25 | forget forget the specified files on the next commit |
|
25 | forget forget the specified files on the next commit | |
26 | init create a new repository in the given directory |
|
26 | init create a new repository in the given directory | |
27 | log show revision history of entire repository or files |
|
27 | log show revision history of entire repository or files | |
28 | merge merge working directory with another revision |
|
28 | merge merge working directory with another revision | |
29 | phase set or show the current phase name |
|
29 | phase set or show the current phase name | |
30 | pull pull changes from the specified source |
|
30 | pull pull changes from the specified source | |
31 | push push changes to the specified destination |
|
31 | push push changes to the specified destination | |
32 | remove remove the specified files on the next commit |
|
32 | remove remove the specified files on the next commit | |
33 | serve start stand-alone webserver |
|
33 | serve start stand-alone webserver | |
34 | status show changed files in the working directory |
|
34 | status show changed files in the working directory | |
35 | summary summarize working directory state |
|
35 | summary summarize working directory state | |
36 | update update working directory (or switch revisions) |
|
36 | update update working directory (or switch revisions) | |
37 |
|
37 | |||
38 | use "hg help" for the full list of commands or "hg -v" for details |
|
38 | use "hg help" for the full list of commands or "hg -v" for details | |
39 | runcommand id --quiet |
|
39 | runcommand id --quiet | |
40 | 000000000000 |
|
40 | 000000000000 | |
41 | runcommand id |
|
41 | runcommand id | |
42 | 000000000000 tip |
|
42 | 000000000000 tip | |
43 | runcommand id --config ui.quiet=True |
|
43 | runcommand id --config ui.quiet=True | |
44 | 000000000000 |
|
44 | 000000000000 | |
45 | runcommand id |
|
45 | runcommand id | |
46 | 000000000000 tip |
|
46 | 000000000000 tip | |
47 |
|
47 | |||
48 | testing inputeof: |
|
48 | testing inputeof: | |
49 |
|
49 | |||
50 | server exit code = 1 |
|
50 | server exit code = 1 | |
51 |
|
51 | |||
52 | testing serverinput: |
|
52 | testing serverinput: | |
53 |
|
53 | |||
54 | runcommand import - |
|
54 | runcommand import - | |
55 | applying patch from stdin |
|
55 | applying patch from stdin | |
56 | runcommand log |
|
56 | runcommand log | |
57 | changeset: 0:eff892de26ec |
|
57 | changeset: 0:eff892de26ec | |
58 | tag: tip |
|
58 | tag: tip | |
59 | user: test |
|
59 | user: test | |
60 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
60 | date: Thu Jan 01 00:00:00 1970 +0000 | |
61 | summary: 1 |
|
61 | summary: 1 | |
62 |
|
62 | |||
63 |
|
63 | |||
64 | testing cwd: |
|
64 | testing cwd: | |
65 |
|
65 | |||
66 | runcommand --cwd foo st bar |
|
66 | runcommand --cwd foo st bar | |
67 | ? bar |
|
67 | ? bar | |
68 | runcommand st foo/bar |
|
68 | runcommand st foo/bar | |
69 | ? foo/bar |
|
69 | ? foo/bar | |
70 |
|
70 | |||
71 | testing localhgrc: |
|
71 | testing localhgrc: | |
72 |
|
72 | |||
73 | runcommand showconfig |
|
73 | runcommand showconfig | |
74 | bundle.mainreporoot=$TESTTMP |
|
74 | bundle.mainreporoot=$TESTTMP | |
75 | defaults.backout=-d "0 0" |
|
75 | defaults.backout=-d "0 0" | |
76 | defaults.commit=-d "0 0" |
|
76 | defaults.commit=-d "0 0" | |
77 | defaults.tag=-d "0 0" |
|
77 | defaults.tag=-d "0 0" | |
78 | ui.slash=True |
|
78 | ui.slash=True | |
79 | ui.foo=bar |
|
79 | ui.foo=bar | |
80 | runcommand init foo |
|
80 | runcommand init foo | |
81 | runcommand -R foo showconfig ui defaults |
|
81 | runcommand -R foo showconfig ui defaults | |
82 | defaults.backout=-d "0 0" |
|
82 | defaults.backout=-d "0 0" | |
83 | defaults.commit=-d "0 0" |
|
83 | defaults.commit=-d "0 0" | |
84 | defaults.tag=-d "0 0" |
|
84 | defaults.tag=-d "0 0" | |
85 | ui.slash=True |
|
85 | ui.slash=True | |
86 |
|
86 | |||
87 | testing hookoutput: |
|
87 | testing hookoutput: | |
88 |
|
88 | |||
89 | runcommand --config hooks.pre-identify=python:test-commandserver.hook id |
|
89 | runcommand --config hooks.pre-identify=python:test-commandserver.hook id | |
90 | hook talking |
|
90 | hook talking | |
91 | now try to read something: 'some input' |
|
91 | now try to read something: 'some input' | |
92 | eff892de26ec tip |
|
92 | eff892de26ec tip | |
93 |
|
93 | |||
94 | testing outsidechanges: |
|
94 | testing outsidechanges: | |
95 |
|
95 | |||
96 | runcommand status |
|
96 | runcommand status | |
97 | M a |
|
97 | M a | |
98 | runcommand tip |
|
98 | runcommand tip | |
99 | changeset: 1:d3a0a68be6de |
|
99 | changeset: 1:d3a0a68be6de | |
100 | tag: tip |
|
100 | tag: tip | |
101 | user: test |
|
101 | user: test | |
102 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
102 | date: Thu Jan 01 00:00:00 1970 +0000 | |
103 | summary: 2 |
|
103 | summary: 2 | |
104 |
|
104 | |||
105 | runcommand status |
|
105 | runcommand status | |
106 |
|
106 | |||
107 | testing bookmarks: |
|
107 | testing bookmarks: | |
108 |
|
108 | |||
109 | runcommand bookmarks |
|
109 | runcommand bookmarks | |
110 | no bookmarks set |
|
110 | no bookmarks set | |
111 | runcommand bookmarks |
|
111 | runcommand bookmarks | |
112 | bm1 1:d3a0a68be6de |
|
112 | bm1 1:d3a0a68be6de | |
113 | bm2 1:d3a0a68be6de |
|
113 | bm2 1:d3a0a68be6de | |
114 | runcommand bookmarks |
|
114 | runcommand bookmarks | |
115 | * bm1 1:d3a0a68be6de |
|
115 | * bm1 1:d3a0a68be6de | |
116 | bm2 1:d3a0a68be6de |
|
116 | bm2 1:d3a0a68be6de | |
117 | runcommand bookmarks bm3 |
|
117 | runcommand bookmarks bm3 | |
118 | runcommand commit -Amm |
|
118 | runcommand commit -Amm | |
119 | runcommand bookmarks |
|
119 | runcommand bookmarks | |
120 | bm1 1:d3a0a68be6de |
|
120 | bm1 1:d3a0a68be6de | |
121 | bm2 1:d3a0a68be6de |
|
121 | bm2 1:d3a0a68be6de | |
122 | * bm3 2:aef17e88f5f0 |
|
122 | * bm3 2:aef17e88f5f0 | |
123 |
|
123 | |||
124 | testing tagscache: |
|
124 | testing tagscache: | |
125 |
|
125 | |||
126 | runcommand id -t -r 0 |
|
126 | runcommand id -t -r 0 | |
127 |
|
127 | |||
128 | runcommand id -t -r 0 |
|
128 | runcommand id -t -r 0 | |
129 | foo |
|
129 | foo | |
130 |
|
130 | |||
131 | testing setphase: |
|
131 | testing setphase: | |
132 |
|
132 | |||
133 | runcommand phase -r . |
|
133 | runcommand phase -r . | |
134 | 3: draft |
|
134 | 3: draft | |
135 | runcommand phase -r . |
|
135 | runcommand phase -r . | |
136 | 3: public |
|
136 | 3: public | |
|
137 | no phases changed | |||
|
138 | ||||
|
139 | testing rollback: | |||
|
140 | ||||
|
141 | runcommand phase -r . -p | |||
|
142 | runcommand commit -Am. | |||
|
143 | runcommand rollback | |||
|
144 | repository tip rolled back to revision 3 (undo commit) | |||
|
145 | working directory now based on revision 3 | |||
|
146 | runcommand phase -r . | |||
|
147 | 3: public |
General Comments 0
You need to be logged in to leave comments.
Login now