author | Georges Racinet <georges.racinet@octobus.net> |
Fri, 20 Oct 2023 08:54:49 +0200 | |
changeset 51228 | 61a6ef876efd |
parent 50928 | d718eddf01d9 |
child 51690 | 493034cc3265 |
permissions | -rw-r--r-- |
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 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
15 |
import collections |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
16 |
import os |
29502
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
17 |
import weakref |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
18 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
19 |
from mercurial.i18n import _ |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
43506
diff
changeset
|
20 |
from mercurial.node import ( |
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
43506
diff
changeset
|
21 |
bin, |
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
43506
diff
changeset
|
22 |
hex, |
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
43506
diff
changeset
|
23 |
) |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
24 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
25 |
from mercurial import ( |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
26 |
bookmarks, |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
27 |
cmdutil, |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
28 |
dispatch, |
36666
d79d68bb9f7c
py3: replace __str__ to __bytes__ in hgext/journal.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36653
diff
changeset
|
29 |
encoding, |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
30 |
error, |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
31 |
extensions, |
29503
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
32 |
hg, |
29502
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
33 |
localrepo, |
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
34 |
lock, |
35888
c8e2d6ed1f9e
cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35462
diff
changeset
|
35 |
logcmdutil, |
35000
135edf120d76
py3: handle keyword arguments in hgext/journal.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33923
diff
changeset
|
36 |
pycompat, |
32337
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32291
diff
changeset
|
37 |
registrar, |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
38 |
util, |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
39 |
) |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36668
diff
changeset
|
40 |
from mercurial.utils import ( |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36668
diff
changeset
|
41 |
dateutil, |
37120
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37084
diff
changeset
|
42 |
procutil, |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36668
diff
changeset
|
43 |
stringutil, |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36668
diff
changeset
|
44 |
) |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
45 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
46 |
cmdtable = {} |
32337
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32291
diff
changeset
|
47 |
command = registrar.command(cmdtable) |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
48 |
|
29841
d5883fd055c6
extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents:
29773
diff
changeset
|
49 |
# 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
|
50 |
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
51 |
# 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
|
52 |
# leave the attribute unspecified. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
53 |
testedwith = b'ships-with-hg-core' |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
54 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
55 |
# storage format version; increment when the format changes |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
56 |
storageversion = 0 |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
57 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
58 |
# namespaces |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
59 |
bookmarktype = b'bookmark' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
60 |
wdirparenttype = b'wdirparent' |
29503
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
61 |
# 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
|
62 |
# to indicate this namespace is shared with the source? |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
63 |
sharednamespaces = { |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
64 |
bookmarktype: hg.sharedbookmarks, |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
65 |
} |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
66 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
67 |
# Journal recording, register hooks and storage object |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
68 |
def extsetup(ui): |
50783
f642063c8147
wrapfunction: use sysstr instead of bytes as argument in "journal"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49860
diff
changeset
|
69 |
extensions.wrapfunction(dispatch, 'runcommand', runcommand) |
f642063c8147
wrapfunction: use sysstr instead of bytes as argument in "journal"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49860
diff
changeset
|
70 |
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
|
71 |
extensions.wrapfilecache( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
72 |
localrepo.localrepository, b'dirstate', wrapdirstate |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
73 |
) |
50783
f642063c8147
wrapfunction: use sysstr instead of bytes as argument in "journal"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49860
diff
changeset
|
74 |
extensions.wrapfunction(hg, 'postshare', wrappostshare) |
f642063c8147
wrapfunction: use sysstr instead of bytes as argument in "journal"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49860
diff
changeset
|
75 |
extensions.wrapfunction(hg, 'copystore', unsharejournal) |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
76 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
77 |
|
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
78 |
def reposetup(ui, repo): |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
79 |
if repo.local(): |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
80 |
repo.journal = journalstorage(repo) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
81 |
repo._wlockfreeprefix.add(b'namejournal') |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
82 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
83 |
dirstate, cached = localrepo.isfilecached(repo, b'dirstate') |
33383
774beab915fe
journal: execute setup procedures for already instantiated dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
32375
diff
changeset
|
84 |
if cached: |
774beab915fe
journal: execute setup procedures for already instantiated dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
32375
diff
changeset
|
85 |
# 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
|
86 |
# "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
|
87 |
# wrapped by own wrapdirstate() |
774beab915fe
journal: execute setup procedures for already instantiated dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
32375
diff
changeset
|
88 |
_setupdirstate(repo, dirstate) |
774beab915fe
journal: execute setup procedures for already instantiated dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
32375
diff
changeset
|
89 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
90 |
|
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
91 |
def runcommand(orig, lui, repo, cmd, fullargs, *args): |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
92 |
"""Track the command line options for recording in the journal""" |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
93 |
journalstorage.recordcommand(*fullargs) |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
94 |
return orig(lui, repo, cmd, fullargs, *args) |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
95 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
96 |
|
33383
774beab915fe
journal: execute setup procedures for already instantiated dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
32375
diff
changeset
|
97 |
def _setupdirstate(repo, dirstate): |
774beab915fe
journal: execute setup procedures for already instantiated dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
32375
diff
changeset
|
98 |
dirstate.journalstorage = repo.journal |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
99 |
dirstate.addparentchangecallback(b'journal', recorddirstateparents) |
33383
774beab915fe
journal: execute setup procedures for already instantiated dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
32375
diff
changeset
|
100 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
101 |
|
29502
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
102 |
# hooks to record dirstate changes |
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
103 |
def wrapdirstate(orig, repo): |
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
104 |
"""Make journal storage available to the dirstate object""" |
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
105 |
dirstate = orig(repo) |
50928
d718eddf01d9
safehasattr: drop usage in favor of hasattr
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50808
diff
changeset
|
106 |
if hasattr(repo, 'journal'): |
33383
774beab915fe
journal: execute setup procedures for already instantiated dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
32375
diff
changeset
|
107 |
_setupdirstate(repo, dirstate) |
29502
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
108 |
return dirstate |
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
109 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
110 |
|
29773
f2241c13d5a1
journal: use the dirstate parentchange callbacks
Mateusz Kwapich <mitrandir@fb.com>
parents:
29756
diff
changeset
|
111 |
def recorddirstateparents(dirstate, old, new): |
29502
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
112 |
"""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
|
113 |
old = list(old) |
f2241c13d5a1
journal: use the dirstate parentchange callbacks
Mateusz Kwapich <mitrandir@fb.com>
parents:
29756
diff
changeset
|
114 |
new = list(new) |
50928
d718eddf01d9
safehasattr: drop usage in favor of hasattr
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50808
diff
changeset
|
115 |
if hasattr(dirstate, 'journalstorage'): |
29773
f2241c13d5a1
journal: use the dirstate parentchange callbacks
Mateusz Kwapich <mitrandir@fb.com>
parents:
29756
diff
changeset
|
116 |
# only record two hashes if there was a merge |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46113
diff
changeset
|
117 |
oldhashes = old[:1] if old[1] == dirstate._nodeconstants.nullid else old |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46113
diff
changeset
|
118 |
newhashes = new[:1] if new[1] == dirstate._nodeconstants.nullid else new |
29773
f2241c13d5a1
journal: use the dirstate parentchange callbacks
Mateusz Kwapich <mitrandir@fb.com>
parents:
29756
diff
changeset
|
119 |
dirstate.journalstorage.record( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
120 |
wdirparenttype, b'.', oldhashes, newhashes |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
121 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
122 |
|
29502
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
123 |
|
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
124 |
# hooks to record bookmark changes (both local and remote) |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
125 |
def recordbookmarks(orig, store, fp): |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
126 |
"""Records all bookmark changes in the journal.""" |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
127 |
repo = store._repo |
50928
d718eddf01d9
safehasattr: drop usage in favor of hasattr
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50808
diff
changeset
|
128 |
if hasattr(repo, 'journal'): |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
129 |
oldmarks = bookmarks.bmstore(repo) |
50808
e9a2e1c77f28
journal: track bookmark deletion
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50783
diff
changeset
|
130 |
all_marks = set(b for b, n in oldmarks.items()) |
e9a2e1c77f28
journal: track bookmark deletion
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50783
diff
changeset
|
131 |
all_marks.update(b for b, n in store.items()) |
e9a2e1c77f28
journal: track bookmark deletion
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50783
diff
changeset
|
132 |
for mark in sorted(all_marks): |
e9a2e1c77f28
journal: track bookmark deletion
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50783
diff
changeset
|
133 |
value = store.get(mark, repo.nullid) |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46113
diff
changeset
|
134 |
oldvalue = oldmarks.get(mark, repo.nullid) |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
135 |
if value != oldvalue: |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
136 |
repo.journal.record(bookmarktype, mark, oldvalue, value) |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
137 |
return orig(store, fp) |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
138 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
139 |
|
29503
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
140 |
# shared repository support |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
141 |
def _readsharedfeatures(repo): |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
142 |
"""A set of shared features for this repository""" |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
143 |
try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
144 |
return set(repo.vfs.read(b'shared').splitlines()) |
49306
2e726c934fcd
py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents:
48946
diff
changeset
|
145 |
except FileNotFoundError: |
29503
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
146 |
return set() |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
147 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
148 |
|
29503
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
149 |
def _mergeentriesiter(*iterables, **kwargs): |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
150 |
"""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
|
151 |
|
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
152 |
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
|
153 |
""" |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43115
diff
changeset
|
154 |
order = kwargs.pop('order', max) |
29503
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
155 |
iterables = [iter(it) for it in iterables] |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
156 |
# 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
|
157 |
# 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
|
158 |
# 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
|
159 |
# time. |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
160 |
iterable_map = {} |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
161 |
for key, it in enumerate(iterables): |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
162 |
try: |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
163 |
iterable_map[key] = [next(it), key, it] |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
164 |
except StopIteration: |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
165 |
# empty entry, can be ignored |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
166 |
pass |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
167 |
|
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
168 |
while iterable_map: |
48935
2cce2fa5bcf7
py3: replace pycompat.itervalues(x) with x.values()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48913
diff
changeset
|
169 |
value, key, it = order(iterable_map.values()) |
29503
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
170 |
yield value |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
171 |
try: |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
172 |
iterable_map[key][0] = next(it) |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
173 |
except StopIteration: |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
174 |
# this iterable is empty, remove it from consideration |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
175 |
del iterable_map[key] |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
176 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
177 |
|
29503
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
178 |
def wrappostshare(orig, sourcerepo, destrepo, **kwargs): |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
179 |
"""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
|
180 |
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
|
181 |
orig(sourcerepo, destrepo, **kwargs) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
182 |
with destrepo.vfs(b'shared', b'a') as fp: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
183 |
fp.write(b'journal\n') |
29503
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
184 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
185 |
|
29503
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
186 |
def unsharejournal(orig, ui, repo, repopath): |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
187 |
"""Copy shared journal entries into this repo when unsharing""" |
50928
d718eddf01d9
safehasattr: drop usage in favor of hasattr
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50808
diff
changeset
|
188 |
if repo.path == repopath and repo.shared() and hasattr(repo, 'journal'): |
36159
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35954
diff
changeset
|
189 |
sharedrepo = hg.sharedreposource(repo) |
29503
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
190 |
sharedfeatures = _readsharedfeatures(repo) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
191 |
if sharedrepo and sharedfeatures > {b'journal'}: |
29503
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
192 |
# 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
|
193 |
# 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
|
194 |
# move the local file first |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
195 |
if repo.vfs.exists(b'namejournal'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
196 |
journalpath = repo.vfs.join(b'namejournal') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
197 |
util.rename(journalpath, journalpath + b'.bak') |
29503
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
198 |
storage = repo.journal |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
199 |
local = storage._open( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
200 |
repo.vfs, filename=b'namejournal.bak', _newestfirst=False |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
201 |
) |
29503
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
202 |
shared = ( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
203 |
e |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
204 |
for e in storage._open(sharedrepo.vfs, _newestfirst=False) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
205 |
if sharednamespaces.get(e.namespace) in sharedfeatures |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
206 |
) |
29503
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
207 |
for entry in _mergeentriesiter(local, shared, order=min): |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
208 |
storage._write(repo.vfs, entry) |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
209 |
|
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
210 |
return orig(ui, repo, repopath) |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
211 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
212 |
|
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
213 |
class journalentry( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
214 |
collections.namedtuple( |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43115
diff
changeset
|
215 |
'journalentry', |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43115
diff
changeset
|
216 |
'timestamp user command namespace name oldhashes newhashes', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
217 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
218 |
): |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
219 |
"""Individual journal entry |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
220 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
221 |
* timestamp: a mercurial (time, timezone) tuple |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
222 |
* user: the username that ran the command |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
223 |
* namespace: the entry namespace, an opaque string |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
224 |
* 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
|
225 |
namespace |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
226 |
* command: the hg command that triggered this record |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
227 |
* 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
|
228 |
* 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
|
229 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
230 |
Handles serialisation from and to the storage format. Fields are |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
231 |
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
|
232 |
timestamp and timezone are separated by a space. |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
233 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
234 |
""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
235 |
|
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
236 |
@classmethod |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
237 |
def fromstorage(cls, line): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
238 |
( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
239 |
time, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
240 |
user, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
241 |
command, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
242 |
namespace, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
243 |
name, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
244 |
oldhashes, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
245 |
newhashes, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
246 |
) = line.split(b'\n') |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
247 |
timestamp, tz = time.split() |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
248 |
timestamp, tz = float(timestamp), int(tz) |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
43506
diff
changeset
|
249 |
oldhashes = tuple(bin(hash) for hash in oldhashes.split(b',')) |
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
43506
diff
changeset
|
250 |
newhashes = tuple(bin(hash) for hash in newhashes.split(b',')) |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
251 |
return cls( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
252 |
(timestamp, tz), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
253 |
user, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
254 |
command, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
255 |
namespace, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
256 |
name, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
257 |
oldhashes, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
258 |
newhashes, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
259 |
) |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
260 |
|
36666
d79d68bb9f7c
py3: replace __str__ to __bytes__ in hgext/journal.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36653
diff
changeset
|
261 |
def __bytes__(self): |
d79d68bb9f7c
py3: replace __str__ to __bytes__ in hgext/journal.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36653
diff
changeset
|
262 |
"""bytes representation for storage""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
263 |
time = b' '.join(map(pycompat.bytestr, self.timestamp)) |
46113
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
43506
diff
changeset
|
264 |
oldhashes = b','.join([hex(hash) for hash in self.oldhashes]) |
59fa3890d40a
node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents:
43506
diff
changeset
|
265 |
newhashes = b','.join([hex(hash) for hash in self.newhashes]) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
266 |
return b'\n'.join( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
267 |
( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
268 |
time, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
269 |
self.user, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
270 |
self.command, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
271 |
self.namespace, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
272 |
self.name, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
273 |
oldhashes, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
274 |
newhashes, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
275 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
276 |
) |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
277 |
|
36666
d79d68bb9f7c
py3: replace __str__ to __bytes__ in hgext/journal.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36653
diff
changeset
|
278 |
__str__ = encoding.strmethod(__bytes__) |
d79d68bb9f7c
py3: replace __str__ to __bytes__ in hgext/journal.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36653
diff
changeset
|
279 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
280 |
|
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48935
diff
changeset
|
281 |
class journalstorage: |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
282 |
"""Storage for journal entries |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
283 |
|
29503
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
284 |
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
|
285 |
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
|
286 |
multiple working copies when shared using the share extension. |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
287 |
|
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
288 |
Entries are stored with NUL bytes as separators. See the journalentry |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
289 |
class for the per-entry structure. |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
290 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
291 |
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
|
292 |
|
29502
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
293 |
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
|
294 |
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
|
295 |
the dirstate). |
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
296 |
|
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
297 |
""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
298 |
|
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
299 |
_currentcommand = () |
29502
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
300 |
_lockref = None |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
301 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
302 |
def __init__(self, repo): |
37120
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37084
diff
changeset
|
303 |
self.user = procutil.getuser() |
29502
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
304 |
self.ui = repo.ui |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
305 |
self.vfs = repo.vfs |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
306 |
|
29503
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
307 |
# is this working copy using a shared storage? |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
308 |
self.sharedfeatures = self.sharedvfs = None |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
309 |
if repo.shared(): |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
310 |
features = _readsharedfeatures(repo) |
36159
0fe7e39dc683
hg: move share._getsrcrepo into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35954
diff
changeset
|
311 |
sharedrepo = hg.sharedreposource(repo) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
312 |
if sharedrepo is not None and b'journal' in features: |
29503
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
313 |
self.sharedvfs = sharedrepo.vfs |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
314 |
self.sharedfeatures = features |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
315 |
|
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
316 |
# track the current command for recording in journal entries |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
317 |
@property |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
318 |
def command(self): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
319 |
commandstr = b' '.join( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
320 |
map(procutil.shellquote, journalstorage._currentcommand) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
321 |
) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
322 |
if b'\n' in commandstr: |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
323 |
# truncate multi-line commands |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
324 |
commandstr = commandstr.partition(b'\n')[0] + b' ...' |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
325 |
return commandstr |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
326 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
327 |
@classmethod |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
328 |
def recordcommand(cls, *fullargs): |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
329 |
"""Set the current hg arguments, stored with recorded entries""" |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
330 |
# 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
|
331 |
# with a non-local repo (cloning for example). |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
332 |
cls._currentcommand = fullargs |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
333 |
|
29928
e5a97ec6ebb8
journal: properly check for held lock (issue5349)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29870
diff
changeset
|
334 |
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
|
335 |
"""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
|
336 |
|
e5a97ec6ebb8
journal: properly check for held lock (issue5349)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29870
diff
changeset
|
337 |
(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
|
338 |
""" |
e5a97ec6ebb8
journal: properly check for held lock (issue5349)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29870
diff
changeset
|
339 |
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
|
340 |
return None |
e5a97ec6ebb8
journal: properly check for held lock (issue5349)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29870
diff
changeset
|
341 |
l = lockref() |
e5a97ec6ebb8
journal: properly check for held lock (issue5349)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29870
diff
changeset
|
342 |
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
|
343 |
return None |
e5a97ec6ebb8
journal: properly check for held lock (issue5349)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29870
diff
changeset
|
344 |
return l |
e5a97ec6ebb8
journal: properly check for held lock (issue5349)
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
29870
diff
changeset
|
345 |
|
29503
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
346 |
def jlock(self, vfs): |
29502
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
347 |
"""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
|
348 |
if self._currentlock(self._lockref) is not None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
349 |
raise error.Abort(_(b'journal lock does not support nesting')) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
350 |
desc = _(b'journal of %s') % vfs.base |
29502
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
351 |
try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
352 |
l = lock.lock(vfs, b'namejournal.lock', 0, desc=desc) |
29502
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
353 |
except error.LockHeld as inst: |
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
354 |
self.ui.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
355 |
_(b"waiting for lock on %s held by %r\n") % (desc, inst.locker) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
356 |
) |
29502
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
357 |
# default to 600 seconds timeout |
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
358 |
l = lock.lock( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
359 |
vfs, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
360 |
b'namejournal.lock', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
361 |
self.ui.configint(b"ui", b"timeout"), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
362 |
desc=desc, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
363 |
) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
364 |
self.ui.warn(_(b"got lock after %s seconds\n") % l.delay) |
29502
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
365 |
self._lockref = weakref.ref(l) |
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
366 |
return l |
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
367 |
|
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
368 |
def record(self, namespace, name, oldhashes, newhashes): |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
369 |
"""Record a new journal entry |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
370 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
371 |
* 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
|
372 |
of recorded entries. |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
373 |
* name: the name defining this entry; for bookmarks, this is the |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
374 |
bookmark name. Can be filtered on when retrieving entries. |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
375 |
* 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
|
376 |
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
|
377 |
item. |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
378 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
379 |
""" |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
380 |
if not isinstance(oldhashes, list): |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
381 |
oldhashes = [oldhashes] |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
382 |
if not isinstance(newhashes, list): |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
383 |
newhashes = [newhashes] |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
384 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
385 |
entry = journalentry( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
386 |
dateutil.makedate(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
387 |
self.user, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
388 |
self.command, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
389 |
namespace, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
390 |
name, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
391 |
oldhashes, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
392 |
newhashes, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
393 |
) |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
394 |
|
29503
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
395 |
vfs = self.vfs |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
396 |
if self.sharedvfs is not None: |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
397 |
# 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
|
398 |
# shared between working copies. |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
399 |
if sharednamespaces.get(namespace) in self.sharedfeatures: |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
400 |
vfs = self.sharedvfs |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
401 |
|
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
402 |
self._write(vfs, entry) |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
403 |
|
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
404 |
def _write(self, vfs, entry): |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
405 |
with self.jlock(vfs): |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
406 |
# open file in amend mode to ensure it is created if missing |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
407 |
with vfs(b'namejournal', mode=b'a+b') as f: |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
408 |
f.seek(0, os.SEEK_SET) |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
409 |
# 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
|
410 |
# digits plus separator) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
411 |
version = f.read(3).partition(b'\0')[0] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
412 |
if version and version != b"%d" % storageversion: |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
413 |
# different version of the storage. Exit early (and not |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
414 |
# 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
|
415 |
# the file is corrupt. In future, perhaps rotate the file |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
416 |
# instead? |
29502
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
417 |
self.ui.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
418 |
_(b"unsupported journal file version '%s'\n") % version |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
419 |
) |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
420 |
return |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
421 |
if not version: |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
422 |
# empty file, write version first |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
423 |
f.write((b"%d" % storageversion) + b'\0') |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
424 |
f.seek(0, os.SEEK_END) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
425 |
f.write(bytes(entry) + b'\0') |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
426 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
427 |
def filtered(self, namespace=None, name=None): |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
428 |
"""Yield all journal entries with the given namespace or name |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
429 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
430 |
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
|
431 |
entries in the journal are produced. |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
432 |
|
29504
7503d8874617
journal: add support for seaching by pattern
Martijn Pieters <mjpieters@fb.com>
parents:
29503
diff
changeset
|
433 |
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
|
434 |
(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
|
435 |
|
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
436 |
""" |
29504
7503d8874617
journal: add support for seaching by pattern
Martijn Pieters <mjpieters@fb.com>
parents:
29503
diff
changeset
|
437 |
if namespace is not None: |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36668
diff
changeset
|
438 |
namespace = stringutil.stringmatcher(namespace)[-1] |
29504
7503d8874617
journal: add support for seaching by pattern
Martijn Pieters <mjpieters@fb.com>
parents:
29503
diff
changeset
|
439 |
if name is not None: |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36668
diff
changeset
|
440 |
name = stringutil.stringmatcher(name)[-1] |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
441 |
for entry in self: |
29504
7503d8874617
journal: add support for seaching by pattern
Martijn Pieters <mjpieters@fb.com>
parents:
29503
diff
changeset
|
442 |
if namespace is not None and not namespace(entry.namespace): |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
443 |
continue |
29504
7503d8874617
journal: add support for seaching by pattern
Martijn Pieters <mjpieters@fb.com>
parents:
29503
diff
changeset
|
444 |
if name is not None and not name(entry.name): |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
445 |
continue |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
446 |
yield entry |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
447 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
448 |
def __iter__(self): |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
449 |
"""Iterate over the storage |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
450 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
451 |
Yields journalentry instances for each contained journal record. |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
452 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
453 |
""" |
29503
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
454 |
local = self._open(self.vfs) |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
455 |
|
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
456 |
if self.sharedvfs is None: |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
457 |
return local |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
458 |
|
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
459 |
# 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
|
460 |
# shared entries that are among the currently shared features |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
461 |
shared = ( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
462 |
e |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
463 |
for e in self._open(self.sharedvfs) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
464 |
if sharednamespaces.get(e.namespace) in self.sharedfeatures |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
465 |
) |
29503
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
466 |
return _mergeentriesiter(local, shared) |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
467 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
468 |
def _open(self, vfs, filename=b'namejournal', _newestfirst=True): |
29503
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
469 |
if not vfs.exists(filename): |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
470 |
return |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
471 |
|
29503
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
472 |
with vfs(filename) as f: |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
473 |
raw = f.read() |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
474 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
475 |
lines = raw.split(b'\0') |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
476 |
version = lines and lines[0] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
477 |
if version != b"%d" % storageversion: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
478 |
version = version or _(b'not available') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
479 |
raise error.Abort(_(b"unknown journal file version '%s'") % version) |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
480 |
|
29503
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
481 |
# 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
|
482 |
# 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
|
483 |
# a shared storage do we forgo reversing. |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
484 |
lines = lines[1:] |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
485 |
if _newestfirst: |
0103b673d6ca
journal: add share extension support
Martijn Pieters <mjpieters@fb.com>
parents:
29502
diff
changeset
|
486 |
lines = reversed(lines) |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
487 |
for line in lines: |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
488 |
if not line: |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
489 |
continue |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
490 |
yield journalentry.fromstorage(line) |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
491 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
492 |
|
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
493 |
# journal reading |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
494 |
# log options that don't make sense for journal |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
495 |
_ignoreopts = (b'no-merges', b'graph') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
496 |
|
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
497 |
|
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
498 |
@command( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
499 |
b'journal', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
500 |
[ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
501 |
(b'', b'all', None, b'show history for all names'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
502 |
(b'c', b'commits', None, b'show commit metadata'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
503 |
] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
504 |
+ [opt for opt in cmdutil.logopts if opt[1] not in _ignoreopts], |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
505 |
b'[OPTION]... [BOOKMARKNAME]', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
506 |
helpcategory=command.CATEGORY_CHANGE_ORGANIZATION, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
507 |
) |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
508 |
def journal(ui, repo, *args, **opts): |
29502
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
509 |
"""show the previous position of bookmarks and the working copy |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
510 |
|
29502
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
511 |
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
|
512 |
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
|
513 |
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
|
514 |
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
|
515 |
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
|
516 |
name, or '.' for the working copy, as well. |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
517 |
|
29504
7503d8874617
journal: add support for seaching by pattern
Martijn Pieters <mjpieters@fb.com>
parents:
29503
diff
changeset
|
518 |
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
|
519 |
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
|
520 |
use the prefix `literal:`. |
7503d8874617
journal: add support for seaching by pattern
Martijn Pieters <mjpieters@fb.com>
parents:
29503
diff
changeset
|
521 |
|
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
522 |
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
|
523 |
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
|
524 |
the time at which it happened. |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
525 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
526 |
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
|
527 |
point you can use the usual `--patch`, `--git`, `--stat` and `--template` |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
528 |
switches to alter the log output for these. |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
529 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
530 |
`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
|
531 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
532 |
""" |
35000
135edf120d76
py3: handle keyword arguments in hgext/journal.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33923
diff
changeset
|
533 |
opts = pycompat.byteskwargs(opts) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
534 |
name = b'.' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
535 |
if opts.get(b'all'): |
29502
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
536 |
if args: |
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
537 |
raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
538 |
_(b"You can't combine --all and filtering on a name") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
539 |
) |
29502
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
540 |
name = None |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
541 |
if args: |
29502
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
542 |
name = args[0] |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
543 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
544 |
fm = ui.formatter(b'journal', opts) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
545 |
|
39702
a7b91509776d
journal: inline formatted nodes and date into expression
Yuya Nishihara <yuya@tcha.org>
parents:
39701
diff
changeset
|
546 |
def formatnodes(nodes): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
547 |
return fm.formatlist(map(fm.hexfunc, nodes), name=b'node', sep=b',') |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
548 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
549 |
if opts.get(b"template") != b"json": |
29502
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
550 |
if name is None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
551 |
displayname = _(b'the working copy and bookmarks') |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
552 |
else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
553 |
displayname = b"'%s'" % name |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
554 |
ui.status(_(b"previous locations of %s:\n") % displayname) |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
555 |
|
35888
c8e2d6ed1f9e
cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35462
diff
changeset
|
556 |
limit = logcmdutil.getlimit(opts) |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
557 |
entry = None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
558 |
ui.pager(b'journal') |
29502
8361131b4768
journal: add dirstate tracking
Martijn Pieters <mjpieters@fb.com>
parents:
29443
diff
changeset
|
559 |
for count, entry in enumerate(repo.journal.filtered(name=name)): |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
560 |
if count == limit: |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
561 |
break |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
562 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
563 |
fm.startitem() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
564 |
fm.condwrite( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
565 |
ui.verbose, b'oldnodes', b'%s -> ', formatnodes(entry.oldhashes) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
566 |
) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
567 |
fm.write(b'newnodes', b'%s', formatnodes(entry.newhashes)) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
568 |
fm.condwrite(ui.verbose, b'user', b' %-8s', entry.user) |
49860
d5116e4dc744
typing: disable an attribute-error warning in the journal extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
49306
diff
changeset
|
569 |
|
d5116e4dc744
typing: disable an attribute-error warning in the journal extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
49306
diff
changeset
|
570 |
# ``name`` is bytes, or None only if 'all' was an option. |
29504
7503d8874617
journal: add support for seaching by pattern
Martijn Pieters <mjpieters@fb.com>
parents:
29503
diff
changeset
|
571 |
fm.condwrite( |
49860
d5116e4dc744
typing: disable an attribute-error warning in the journal extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
49306
diff
changeset
|
572 |
# pytype: disable=attribute-error |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
573 |
opts.get(b'all') or name.startswith(b're:'), |
49860
d5116e4dc744
typing: disable an attribute-error warning in the journal extension
Matt Harbison <matt_harbison@yahoo.com>
parents:
49306
diff
changeset
|
574 |
# pytype: enable=attribute-error |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
575 |
b'name', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
576 |
b' %-8s', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
577 |
entry.name, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
578 |
) |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
579 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
580 |
fm.condwrite( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
581 |
ui.verbose, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
582 |
b'date', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
583 |
b' %s', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
584 |
fm.formatdate(entry.timestamp, b'%Y-%m-%d %H:%M %1%2'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
585 |
) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
586 |
fm.write(b'command', b' %s\n', entry.command) |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
587 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
588 |
if opts.get(b"commits"): |
39704
aa647457df14
journal: use changesetformatter to properly nest list of commits in JSON
Yuya Nishihara <yuya@tcha.org>
parents:
39703
diff
changeset
|
589 |
if fm.isplain(): |
aa647457df14
journal: use changesetformatter to properly nest list of commits in JSON
Yuya Nishihara <yuya@tcha.org>
parents:
39703
diff
changeset
|
590 |
displayer = logcmdutil.changesetdisplayer(ui, repo, opts) |
aa647457df14
journal: use changesetformatter to properly nest list of commits in JSON
Yuya Nishihara <yuya@tcha.org>
parents:
39703
diff
changeset
|
591 |
else: |
aa647457df14
journal: use changesetformatter to properly nest list of commits in JSON
Yuya Nishihara <yuya@tcha.org>
parents:
39703
diff
changeset
|
592 |
displayer = logcmdutil.changesetformatter( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
593 |
ui, repo, fm.nested(b'changesets'), diffopts=opts |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41834
diff
changeset
|
594 |
) |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
595 |
for hash in entry.newhashes: |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
596 |
try: |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
597 |
ctx = repo[hash] |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
598 |
displayer.show(ctx) |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
599 |
except error.RepoLookupError as e: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
600 |
fm.plain(b"%s\n\n" % pycompat.bytestr(e)) |
29443
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
601 |
displayer.close() |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
602 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
603 |
fm.end() |
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
604 |
|
cf092a3d202a
journal: new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
605 |
if entry is None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
606 |
ui.status(_(b"no recorded locations\n")) |