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