Show More
@@ -1,523 +1,523 b'' | |||
|
1 | 1 | # journal.py |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2014-2016 Facebook, Inc. |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | """track previous positions of bookmarks (EXPERIMENTAL) |
|
8 | 8 | |
|
9 | 9 | This extension adds a new command: `hg journal`, which shows you where |
|
10 | 10 | bookmarks were previously located. |
|
11 | 11 | |
|
12 | 12 | """ |
|
13 | 13 | |
|
14 | 14 | from __future__ import absolute_import |
|
15 | 15 | |
|
16 | 16 | import collections |
|
17 | 17 | import errno |
|
18 | 18 | import os |
|
19 | 19 | import weakref |
|
20 | 20 | |
|
21 | 21 | from mercurial.i18n import _ |
|
22 | 22 | |
|
23 | 23 | from mercurial import ( |
|
24 | 24 | bookmarks, |
|
25 | 25 | cmdutil, |
|
26 | 26 | dispatch, |
|
27 | 27 | encoding, |
|
28 | 28 | error, |
|
29 | 29 | extensions, |
|
30 | 30 | hg, |
|
31 | 31 | localrepo, |
|
32 | 32 | lock, |
|
33 | 33 | logcmdutil, |
|
34 | 34 | node, |
|
35 | 35 | pycompat, |
|
36 | 36 | registrar, |
|
37 | 37 | util, |
|
38 | 38 | ) |
|
39 | 39 | from mercurial.utils import ( |
|
40 | 40 | dateutil, |
|
41 | 41 | procutil, |
|
42 | 42 | stringutil, |
|
43 | 43 | ) |
|
44 | 44 | |
|
45 | 45 | cmdtable = {} |
|
46 | 46 | command = registrar.command(cmdtable) |
|
47 | 47 | |
|
48 | 48 | # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
|
49 | 49 | # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
|
50 | 50 | # be specifying the version(s) of Mercurial they are tested with, or |
|
51 | 51 | # leave the attribute unspecified. |
|
52 | 52 | testedwith = 'ships-with-hg-core' |
|
53 | 53 | |
|
54 | 54 | # storage format version; increment when the format changes |
|
55 | 55 | storageversion = 0 |
|
56 | 56 | |
|
57 | 57 | # namespaces |
|
58 | 58 | bookmarktype = 'bookmark' |
|
59 | 59 | wdirparenttype = 'wdirparent' |
|
60 | 60 | # In a shared repository, what shared feature name is used |
|
61 | 61 | # to indicate this namespace is shared with the source? |
|
62 | 62 | sharednamespaces = { |
|
63 | 63 | bookmarktype: hg.sharedbookmarks, |
|
64 | 64 | } |
|
65 | 65 | |
|
66 | 66 | # Journal recording, register hooks and storage object |
|
67 | 67 | def extsetup(ui): |
|
68 | 68 | extensions.wrapfunction(dispatch, 'runcommand', runcommand) |
|
69 | 69 | extensions.wrapfunction(bookmarks.bmstore, '_write', recordbookmarks) |
|
70 | 70 | extensions.wrapfilecache( |
|
71 | 71 | localrepo.localrepository, 'dirstate', wrapdirstate) |
|
72 | 72 | extensions.wrapfunction(hg, 'postshare', wrappostshare) |
|
73 | 73 | extensions.wrapfunction(hg, 'copystore', unsharejournal) |
|
74 | 74 | |
|
75 | 75 | def reposetup(ui, repo): |
|
76 | 76 | if repo.local(): |
|
77 | 77 | repo.journal = journalstorage(repo) |
|
78 | 78 | repo._wlockfreeprefix.add('namejournal') |
|
79 | 79 | |
|
80 | 80 | dirstate, cached = localrepo.isfilecached(repo, 'dirstate') |
|
81 | 81 | if cached: |
|
82 | 82 | # already instantiated dirstate isn't yet marked as |
|
83 | 83 | # "journal"-ing, even though repo.dirstate() was already |
|
84 | 84 | # wrapped by own wrapdirstate() |
|
85 | 85 | _setupdirstate(repo, dirstate) |
|
86 | 86 | |
|
87 | 87 | def runcommand(orig, lui, repo, cmd, fullargs, *args): |
|
88 | 88 | """Track the command line options for recording in the journal""" |
|
89 | 89 | journalstorage.recordcommand(*fullargs) |
|
90 | 90 | return orig(lui, repo, cmd, fullargs, *args) |
|
91 | 91 | |
|
92 | 92 | def _setupdirstate(repo, dirstate): |
|
93 | 93 | dirstate.journalstorage = repo.journal |
|
94 | 94 | dirstate.addparentchangecallback('journal', recorddirstateparents) |
|
95 | 95 | |
|
96 | 96 | # hooks to record dirstate changes |
|
97 | 97 | def wrapdirstate(orig, repo): |
|
98 | 98 | """Make journal storage available to the dirstate object""" |
|
99 | 99 | dirstate = orig(repo) |
|
100 | 100 | if util.safehasattr(repo, 'journal'): |
|
101 | 101 | _setupdirstate(repo, dirstate) |
|
102 | 102 | return dirstate |
|
103 | 103 | |
|
104 | 104 | def recorddirstateparents(dirstate, old, new): |
|
105 | 105 | """Records all dirstate parent changes in the journal.""" |
|
106 | 106 | old = list(old) |
|
107 | 107 | new = list(new) |
|
108 | 108 | if util.safehasattr(dirstate, 'journalstorage'): |
|
109 | 109 | # only record two hashes if there was a merge |
|
110 | 110 | oldhashes = old[:1] if old[1] == node.nullid else old |
|
111 | 111 | newhashes = new[:1] if new[1] == node.nullid else new |
|
112 | 112 | dirstate.journalstorage.record( |
|
113 | 113 | wdirparenttype, '.', oldhashes, newhashes) |
|
114 | 114 | |
|
115 | 115 | # hooks to record bookmark changes (both local and remote) |
|
116 | 116 | def recordbookmarks(orig, store, fp): |
|
117 | 117 | """Records all bookmark changes in the journal.""" |
|
118 | 118 | repo = store._repo |
|
119 | 119 | if util.safehasattr(repo, 'journal'): |
|
120 | 120 | oldmarks = bookmarks.bmstore(repo) |
|
121 | 121 | for mark, value in store.iteritems(): |
|
122 | 122 | oldvalue = oldmarks.get(mark, node.nullid) |
|
123 | 123 | if value != oldvalue: |
|
124 | 124 | repo.journal.record(bookmarktype, mark, oldvalue, value) |
|
125 | 125 | return orig(store, fp) |
|
126 | 126 | |
|
127 | 127 | # shared repository support |
|
128 | 128 | def _readsharedfeatures(repo): |
|
129 | 129 | """A set of shared features for this repository""" |
|
130 | 130 | try: |
|
131 | 131 | return set(repo.vfs.read('shared').splitlines()) |
|
132 | 132 | except IOError as inst: |
|
133 | 133 | if inst.errno != errno.ENOENT: |
|
134 | 134 | raise |
|
135 | 135 | return set() |
|
136 | 136 | |
|
137 | 137 | def _mergeentriesiter(*iterables, **kwargs): |
|
138 | 138 | """Given a set of sorted iterables, yield the next entry in merged order |
|
139 | 139 | |
|
140 | 140 | Note that by default entries go from most recent to oldest. |
|
141 | 141 | """ |
|
142 | 142 | order = kwargs.pop(r'order', max) |
|
143 | 143 | iterables = [iter(it) for it in iterables] |
|
144 | 144 | # this tracks still active iterables; iterables are deleted as they are |
|
145 | 145 | # exhausted, which is why this is a dictionary and why each entry also |
|
146 | 146 | # stores the key. Entries are mutable so we can store the next value each |
|
147 | 147 | # time. |
|
148 | 148 | iterable_map = {} |
|
149 | 149 | for key, it in enumerate(iterables): |
|
150 | 150 | try: |
|
151 | 151 | iterable_map[key] = [next(it), key, it] |
|
152 | 152 | except StopIteration: |
|
153 | 153 | # empty entry, can be ignored |
|
154 | 154 | pass |
|
155 | 155 | |
|
156 | 156 | while iterable_map: |
|
157 | 157 | value, key, it = order(iterable_map.itervalues()) |
|
158 | 158 | yield value |
|
159 | 159 | try: |
|
160 | 160 | iterable_map[key][0] = next(it) |
|
161 | 161 | except StopIteration: |
|
162 | 162 | # this iterable is empty, remove it from consideration |
|
163 | 163 | del iterable_map[key] |
|
164 | 164 | |
|
165 | 165 | def wrappostshare(orig, sourcerepo, destrepo, **kwargs): |
|
166 | 166 | """Mark this shared working copy as sharing journal information""" |
|
167 | 167 | with destrepo.wlock(): |
|
168 | 168 | orig(sourcerepo, destrepo, **kwargs) |
|
169 | 169 | with destrepo.vfs('shared', 'a') as fp: |
|
170 | 170 | fp.write('journal\n') |
|
171 | 171 | |
|
172 | 172 | def unsharejournal(orig, ui, repo, repopath): |
|
173 | 173 | """Copy shared journal entries into this repo when unsharing""" |
|
174 | 174 | if (repo.path == repopath and repo.shared() and |
|
175 | 175 | util.safehasattr(repo, 'journal')): |
|
176 | 176 | sharedrepo = hg.sharedreposource(repo) |
|
177 | 177 | sharedfeatures = _readsharedfeatures(repo) |
|
178 | 178 | if sharedrepo and sharedfeatures > {'journal'}: |
|
179 | 179 | # there is a shared repository and there are shared journal entries |
|
180 | 180 | # to copy. move shared date over from source to destination but |
|
181 | 181 | # move the local file first |
|
182 | 182 | if repo.vfs.exists('namejournal'): |
|
183 | 183 | journalpath = repo.vfs.join('namejournal') |
|
184 | 184 | util.rename(journalpath, journalpath + '.bak') |
|
185 | 185 | storage = repo.journal |
|
186 | 186 | local = storage._open( |
|
187 | 187 | repo.vfs, filename='namejournal.bak', _newestfirst=False) |
|
188 | 188 | shared = ( |
|
189 | 189 | e for e in storage._open(sharedrepo.vfs, _newestfirst=False) |
|
190 | 190 | if sharednamespaces.get(e.namespace) in sharedfeatures) |
|
191 | 191 | for entry in _mergeentriesiter(local, shared, order=min): |
|
192 | 192 | storage._write(repo.vfs, entry) |
|
193 | 193 | |
|
194 | 194 | return orig(ui, repo, repopath) |
|
195 | 195 | |
|
196 | 196 | class journalentry(collections.namedtuple( |
|
197 | 197 | u'journalentry', |
|
198 | 198 | u'timestamp user command namespace name oldhashes newhashes')): |
|
199 | 199 | """Individual journal entry |
|
200 | 200 | |
|
201 | 201 | * timestamp: a mercurial (time, timezone) tuple |
|
202 | 202 | * user: the username that ran the command |
|
203 | 203 | * namespace: the entry namespace, an opaque string |
|
204 | 204 | * name: the name of the changed item, opaque string with meaning in the |
|
205 | 205 | namespace |
|
206 | 206 | * command: the hg command that triggered this record |
|
207 | 207 | * oldhashes: a tuple of one or more binary hashes for the old location |
|
208 | 208 | * newhashes: a tuple of one or more binary hashes for the new location |
|
209 | 209 | |
|
210 | 210 | Handles serialisation from and to the storage format. Fields are |
|
211 | 211 | separated by newlines, hashes are written out in hex separated by commas, |
|
212 | 212 | timestamp and timezone are separated by a space. |
|
213 | 213 | |
|
214 | 214 | """ |
|
215 | 215 | @classmethod |
|
216 | 216 | def fromstorage(cls, line): |
|
217 | 217 | (time, user, command, namespace, name, |
|
218 | 218 | oldhashes, newhashes) = line.split('\n') |
|
219 | 219 | timestamp, tz = time.split() |
|
220 | 220 | timestamp, tz = float(timestamp), int(tz) |
|
221 | 221 | oldhashes = tuple(node.bin(hash) for hash in oldhashes.split(',')) |
|
222 | 222 | newhashes = tuple(node.bin(hash) for hash in newhashes.split(',')) |
|
223 | 223 | return cls( |
|
224 | 224 | (timestamp, tz), user, command, namespace, name, |
|
225 | 225 | oldhashes, newhashes) |
|
226 | 226 | |
|
227 | 227 | def __bytes__(self): |
|
228 | 228 | """bytes representation for storage""" |
|
229 | 229 | time = ' '.join(map(pycompat.bytestr, self.timestamp)) |
|
230 | 230 | oldhashes = ','.join([node.hex(hash) for hash in self.oldhashes]) |
|
231 | 231 | newhashes = ','.join([node.hex(hash) for hash in self.newhashes]) |
|
232 | 232 | return '\n'.join(( |
|
233 | 233 | time, self.user, self.command, self.namespace, self.name, |
|
234 | 234 | oldhashes, newhashes)) |
|
235 | 235 | |
|
236 | 236 | __str__ = encoding.strmethod(__bytes__) |
|
237 | 237 | |
|
238 | 238 | class journalstorage(object): |
|
239 | 239 | """Storage for journal entries |
|
240 | 240 | |
|
241 | 241 | Entries are divided over two files; one with entries that pertain to the |
|
242 | 242 | local working copy *only*, and one with entries that are shared across |
|
243 | 243 | multiple working copies when shared using the share extension. |
|
244 | 244 | |
|
245 | 245 | Entries are stored with NUL bytes as separators. See the journalentry |
|
246 | 246 | class for the per-entry structure. |
|
247 | 247 | |
|
248 | 248 | The file format starts with an integer version, delimited by a NUL. |
|
249 | 249 | |
|
250 | 250 | This storage uses a dedicated lock; this makes it easier to avoid issues |
|
251 | 251 | with adding entries that added when the regular wlock is unlocked (e.g. |
|
252 | 252 | the dirstate). |
|
253 | 253 | |
|
254 | 254 | """ |
|
255 | 255 | _currentcommand = () |
|
256 | 256 | _lockref = None |
|
257 | 257 | |
|
258 | 258 | def __init__(self, repo): |
|
259 | 259 | self.user = procutil.getuser() |
|
260 | 260 | self.ui = repo.ui |
|
261 | 261 | self.vfs = repo.vfs |
|
262 | 262 | |
|
263 | 263 | # is this working copy using a shared storage? |
|
264 | 264 | self.sharedfeatures = self.sharedvfs = None |
|
265 | 265 | if repo.shared(): |
|
266 | 266 | features = _readsharedfeatures(repo) |
|
267 | 267 | sharedrepo = hg.sharedreposource(repo) |
|
268 | 268 | if sharedrepo is not None and 'journal' in features: |
|
269 | 269 | self.sharedvfs = sharedrepo.vfs |
|
270 | 270 | self.sharedfeatures = features |
|
271 | 271 | |
|
272 | 272 | # track the current command for recording in journal entries |
|
273 | 273 | @property |
|
274 | 274 | def command(self): |
|
275 | 275 | commandstr = ' '.join( |
|
276 | 276 | map(procutil.shellquote, journalstorage._currentcommand)) |
|
277 | 277 | if '\n' in commandstr: |
|
278 | 278 | # truncate multi-line commands |
|
279 | 279 | commandstr = commandstr.partition('\n')[0] + ' ...' |
|
280 | 280 | return commandstr |
|
281 | 281 | |
|
282 | 282 | @classmethod |
|
283 | 283 | def recordcommand(cls, *fullargs): |
|
284 | 284 | """Set the current hg arguments, stored with recorded entries""" |
|
285 | 285 | # Set the current command on the class because we may have started |
|
286 | 286 | # with a non-local repo (cloning for example). |
|
287 | 287 | cls._currentcommand = fullargs |
|
288 | 288 | |
|
289 | 289 | def _currentlock(self, lockref): |
|
290 | 290 | """Returns the lock if it's held, or None if it's not. |
|
291 | 291 | |
|
292 | 292 | (This is copied from the localrepo class) |
|
293 | 293 | """ |
|
294 | 294 | if lockref is None: |
|
295 | 295 | return None |
|
296 | 296 | l = lockref() |
|
297 | 297 | if l is None or not l.held: |
|
298 | 298 | return None |
|
299 | 299 | return l |
|
300 | 300 | |
|
301 | 301 | def jlock(self, vfs): |
|
302 | 302 | """Create a lock for the journal file""" |
|
303 | 303 | if self._currentlock(self._lockref) is not None: |
|
304 | 304 | raise error.Abort(_('journal lock does not support nesting')) |
|
305 | 305 | desc = _('journal of %s') % vfs.base |
|
306 | 306 | try: |
|
307 | 307 | l = lock.lock(vfs, 'namejournal.lock', 0, desc=desc) |
|
308 | 308 | except error.LockHeld as inst: |
|
309 | 309 | self.ui.warn( |
|
310 | 310 | _("waiting for lock on %s held by %r\n") % (desc, inst.locker)) |
|
311 | 311 | # default to 600 seconds timeout |
|
312 | 312 | l = lock.lock( |
|
313 | 313 | vfs, 'namejournal.lock', |
|
314 | 314 | self.ui.configint("ui", "timeout"), desc=desc) |
|
315 | 315 | self.ui.warn(_("got lock after %s seconds\n") % l.delay) |
|
316 | 316 | self._lockref = weakref.ref(l) |
|
317 | 317 | return l |
|
318 | 318 | |
|
319 | 319 | def record(self, namespace, name, oldhashes, newhashes): |
|
320 | 320 | """Record a new journal entry |
|
321 | 321 | |
|
322 | 322 | * namespace: an opaque string; this can be used to filter on the type |
|
323 | 323 | of recorded entries. |
|
324 | 324 | * name: the name defining this entry; for bookmarks, this is the |
|
325 | 325 | bookmark name. Can be filtered on when retrieving entries. |
|
326 | 326 | * oldhashes and newhashes: each a single binary hash, or a list of |
|
327 | 327 | binary hashes. These represent the old and new position of the named |
|
328 | 328 | item. |
|
329 | 329 | |
|
330 | 330 | """ |
|
331 | 331 | if not isinstance(oldhashes, list): |
|
332 | 332 | oldhashes = [oldhashes] |
|
333 | 333 | if not isinstance(newhashes, list): |
|
334 | 334 | newhashes = [newhashes] |
|
335 | 335 | |
|
336 | 336 | entry = journalentry( |
|
337 | 337 | dateutil.makedate(), self.user, self.command, namespace, name, |
|
338 | 338 | oldhashes, newhashes) |
|
339 | 339 | |
|
340 | 340 | vfs = self.vfs |
|
341 | 341 | if self.sharedvfs is not None: |
|
342 | 342 | # write to the shared repository if this feature is being |
|
343 | 343 | # shared between working copies. |
|
344 | 344 | if sharednamespaces.get(namespace) in self.sharedfeatures: |
|
345 | 345 | vfs = self.sharedvfs |
|
346 | 346 | |
|
347 | 347 | self._write(vfs, entry) |
|
348 | 348 | |
|
349 | 349 | def _write(self, vfs, entry): |
|
350 | 350 | with self.jlock(vfs): |
|
351 | 351 | version = None |
|
352 | 352 | # open file in amend mode to ensure it is created if missing |
|
353 | 353 | with vfs('namejournal', mode='a+b') as f: |
|
354 | 354 | f.seek(0, os.SEEK_SET) |
|
355 | 355 | # Read just enough bytes to get a version number (up to 2 |
|
356 | 356 | # digits plus separator) |
|
357 | 357 | version = f.read(3).partition('\0')[0] |
|
358 | 358 | if version and version != "%d" % storageversion: |
|
359 | 359 | # different version of the storage. Exit early (and not |
|
360 | 360 | # write anything) if this is not a version we can handle or |
|
361 | 361 | # the file is corrupt. In future, perhaps rotate the file |
|
362 | 362 | # instead? |
|
363 | 363 | self.ui.warn( |
|
364 | 364 | _("unsupported journal file version '%s'\n") % version) |
|
365 | 365 | return |
|
366 | 366 | if not version: |
|
367 | 367 | # empty file, write version first |
|
368 | 368 | f.write(("%d" % storageversion) + '\0') |
|
369 | 369 | f.seek(0, os.SEEK_END) |
|
370 | 370 | f.write(bytes(entry) + '\0') |
|
371 | 371 | |
|
372 | 372 | def filtered(self, namespace=None, name=None): |
|
373 | 373 | """Yield all journal entries with the given namespace or name |
|
374 | 374 | |
|
375 | 375 | Both the namespace and the name are optional; if neither is given all |
|
376 | 376 | entries in the journal are produced. |
|
377 | 377 | |
|
378 | 378 | Matching supports regular expressions by using the `re:` prefix |
|
379 | 379 | (use `literal:` to match names or namespaces that start with `re:`) |
|
380 | 380 | |
|
381 | 381 | """ |
|
382 | 382 | if namespace is not None: |
|
383 | 383 | namespace = stringutil.stringmatcher(namespace)[-1] |
|
384 | 384 | if name is not None: |
|
385 | 385 | name = stringutil.stringmatcher(name)[-1] |
|
386 | 386 | for entry in self: |
|
387 | 387 | if namespace is not None and not namespace(entry.namespace): |
|
388 | 388 | continue |
|
389 | 389 | if name is not None and not name(entry.name): |
|
390 | 390 | continue |
|
391 | 391 | yield entry |
|
392 | 392 | |
|
393 | 393 | def __iter__(self): |
|
394 | 394 | """Iterate over the storage |
|
395 | 395 | |
|
396 | 396 | Yields journalentry instances for each contained journal record. |
|
397 | 397 | |
|
398 | 398 | """ |
|
399 | 399 | local = self._open(self.vfs) |
|
400 | 400 | |
|
401 | 401 | if self.sharedvfs is None: |
|
402 | 402 | return local |
|
403 | 403 | |
|
404 | 404 | # iterate over both local and shared entries, but only those |
|
405 | 405 | # shared entries that are among the currently shared features |
|
406 | 406 | shared = ( |
|
407 | 407 | e for e in self._open(self.sharedvfs) |
|
408 | 408 | if sharednamespaces.get(e.namespace) in self.sharedfeatures) |
|
409 | 409 | return _mergeentriesiter(local, shared) |
|
410 | 410 | |
|
411 | 411 | def _open(self, vfs, filename='namejournal', _newestfirst=True): |
|
412 | 412 | if not vfs.exists(filename): |
|
413 | 413 | return |
|
414 | 414 | |
|
415 | 415 | with vfs(filename) as f: |
|
416 | 416 | raw = f.read() |
|
417 | 417 | |
|
418 | 418 | lines = raw.split('\0') |
|
419 | 419 | version = lines and lines[0] |
|
420 | 420 | if version != "%d" % storageversion: |
|
421 | 421 | version = version or _('not available') |
|
422 | 422 | raise error.Abort(_("unknown journal file version '%s'") % version) |
|
423 | 423 | |
|
424 | 424 | # Skip the first line, it's a version number. Normally we iterate over |
|
425 | 425 | # these in reverse order to list newest first; only when copying across |
|
426 | 426 | # a shared storage do we forgo reversing. |
|
427 | 427 | lines = lines[1:] |
|
428 | 428 | if _newestfirst: |
|
429 | 429 | lines = reversed(lines) |
|
430 | 430 | for line in lines: |
|
431 | 431 | if not line: |
|
432 | 432 | continue |
|
433 | 433 | yield journalentry.fromstorage(line) |
|
434 | 434 | |
|
435 | 435 | # journal reading |
|
436 | 436 | # log options that don't make sense for journal |
|
437 | 437 | _ignoreopts = ('no-merges', 'graph') |
|
438 | 438 | @command( |
|
439 | 439 | 'journal', [ |
|
440 | 440 | ('', 'all', None, 'show history for all names'), |
|
441 | 441 | ('c', 'commits', None, 'show commit metadata'), |
|
442 | 442 | ] + [opt for opt in cmdutil.logopts if opt[1] not in _ignoreopts], |
|
443 | 443 | '[OPTION]... [BOOKMARKNAME]') |
|
444 | 444 | def journal(ui, repo, *args, **opts): |
|
445 | 445 | """show the previous position of bookmarks and the working copy |
|
446 | 446 | |
|
447 | 447 | The journal is used to see the previous commits that bookmarks and the |
|
448 | 448 | working copy pointed to. By default the previous locations for the working |
|
449 | 449 | copy. Passing a bookmark name will show all the previous positions of |
|
450 | 450 | that bookmark. Use the --all switch to show previous locations for all |
|
451 | 451 | bookmarks and the working copy; each line will then include the bookmark |
|
452 | 452 | name, or '.' for the working copy, as well. |
|
453 | 453 | |
|
454 | 454 | If `name` starts with `re:`, the remainder of the name is treated as |
|
455 | 455 | a regular expression. To match a name that actually starts with `re:`, |
|
456 | 456 | use the prefix `literal:`. |
|
457 | 457 | |
|
458 | 458 | By default hg journal only shows the commit hash and the command that was |
|
459 | 459 | running at that time. -v/--verbose will show the prior hash, the user, and |
|
460 | 460 | the time at which it happened. |
|
461 | 461 | |
|
462 | 462 | Use -c/--commits to output log information on each commit hash; at this |
|
463 | 463 | point you can use the usual `--patch`, `--git`, `--stat` and `--template` |
|
464 | 464 | switches to alter the log output for these. |
|
465 | 465 | |
|
466 | 466 | `hg journal -T json` can be used to produce machine readable output. |
|
467 | 467 | |
|
468 | 468 | """ |
|
469 | 469 | opts = pycompat.byteskwargs(opts) |
|
470 | 470 | name = '.' |
|
471 | 471 | if opts.get('all'): |
|
472 | 472 | if args: |
|
473 | 473 | raise error.Abort( |
|
474 | 474 | _("You can't combine --all and filtering on a name")) |
|
475 | 475 | name = None |
|
476 | 476 | if args: |
|
477 | 477 | name = args[0] |
|
478 | 478 | |
|
479 | 479 | fm = ui.formatter('journal', opts) |
|
480 | 480 | def formatnodes(nodes): |
|
481 | 481 | return fm.formatlist(map(fm.hexfunc, nodes), name='node', sep=',') |
|
482 | 482 | |
|
483 | 483 | if opts.get("template") != "json": |
|
484 | 484 | if name is None: |
|
485 | 485 | displayname = _('the working copy and bookmarks') |
|
486 | 486 | else: |
|
487 | 487 | displayname = "'%s'" % name |
|
488 | 488 | ui.status(_("previous locations of %s:\n") % displayname) |
|
489 | 489 | |
|
490 | 490 | limit = logcmdutil.getlimit(opts) |
|
491 | 491 | entry = None |
|
492 | 492 | ui.pager('journal') |
|
493 | 493 | for count, entry in enumerate(repo.journal.filtered(name=name)): |
|
494 | 494 | if count == limit: |
|
495 | 495 | break |
|
496 | 496 | |
|
497 | 497 | fm.startitem() |
|
498 | 498 | fm.condwrite(ui.verbose, 'oldnodes', '%s -> ', |
|
499 | 499 | formatnodes(entry.oldhashes)) |
|
500 | 500 | fm.write('newnodes', '%s', formatnodes(entry.newhashes)) |
|
501 | 501 | fm.condwrite(ui.verbose, 'user', ' %-8s', entry.user) |
|
502 | 502 | fm.condwrite( |
|
503 | 503 | opts.get('all') or name.startswith('re:'), |
|
504 | 504 | 'name', ' %-8s', entry.name) |
|
505 | 505 | |
|
506 | 506 | fm.condwrite(ui.verbose, 'date', ' %s', |
|
507 | 507 | fm.formatdate(entry.timestamp, '%Y-%m-%d %H:%M %1%2')) |
|
508 | 508 | fm.write('command', ' %s\n', entry.command) |
|
509 | 509 | |
|
510 | 510 | if opts.get("commits"): |
|
511 | 511 | displayer = logcmdutil.changesetdisplayer(ui, repo, opts) |
|
512 | 512 | for hash in entry.newhashes: |
|
513 | 513 | try: |
|
514 | 514 | ctx = repo[hash] |
|
515 | 515 | displayer.show(ctx) |
|
516 | 516 | except error.RepoLookupError as e: |
|
517 |
fm. |
|
|
517 | fm.plain("%s\n\n" % pycompat.bytestr(e)) | |
|
518 | 518 | displayer.close() |
|
519 | 519 | |
|
520 | 520 | fm.end() |
|
521 | 521 | |
|
522 | 522 | if entry is None: |
|
523 | 523 | ui.status(_("no recorded locations\n")) |
General Comments 0
You need to be logged in to leave comments.
Login now