author | Laurent Charignon <lcharignon@fb.com> |
Tue, 10 Mar 2015 17:09:07 -0700 | |
changeset 24271 | 18792f2e38bb |
parent 24270 | c256ae48fd26 |
child 24272 | 26a1c617e047 |
permissions | -rw-r--r-- |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
1 |
# record.py |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
2 |
# |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
3 |
# Copyright 2007 Bryan O'Sullivan <bos@serpentine.com> |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
4 |
# |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8208
diff
changeset
|
5 |
# This software may be used and distributed according to the terms of the |
10263 | 6 |
# GNU General Public License version 2 or any later version. |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
7 |
|
8934
9dda4c73fc3b
extensions: change descriptions for extensions providing a few commands
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8894
diff
changeset
|
8 |
'''commands to interactively select changes for commit/qrefresh''' |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
9 |
|
20266
061766323061
record: use "ui.extractchoices()" to get the list of available responses
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20171
diff
changeset
|
10 |
from mercurial.i18n import _ |
24271
18792f2e38bb
record: remove dependency on hg module in record
Laurent Charignon <lcharignon@fb.com>
parents:
24270
diff
changeset
|
11 |
from mercurial import cmdutil, commands, extensions, patch |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
12 |
from mercurial import util |
24271
18792f2e38bb
record: remove dependency on hg module in record
Laurent Charignon <lcharignon@fb.com>
parents:
24270
diff
changeset
|
13 |
from mercurial import merge as mergemod |
24269
9a745ced79a9
record: move filterpatch from record to patch
Laurent Charignon <lcharignon@fb.com>
parents:
24268
diff
changeset
|
14 |
import cStringIO, errno, os, shutil, tempfile |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
15 |
|
14408
054da1e0afbe
record: use cmdutil.command decorator
Idan Kamara <idankk86@gmail.com>
parents:
14407
diff
changeset
|
16 |
cmdtable = {} |
054da1e0afbe
record: use cmdutil.command decorator
Idan Kamara <idankk86@gmail.com>
parents:
14407
diff
changeset
|
17 |
command = cmdutil.command(cmdtable) |
16743
38caf405d010
hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents:
16683
diff
changeset
|
18 |
testedwith = 'internal' |
14408
054da1e0afbe
record: use cmdutil.command decorator
Idan Kamara <idankk86@gmail.com>
parents:
14407
diff
changeset
|
19 |
|
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
20 |
|
14408
054da1e0afbe
record: use cmdutil.command decorator
Idan Kamara <idankk86@gmail.com>
parents:
14407
diff
changeset
|
21 |
@command("record", |
14597
3f1dccea9510
record: add white space diff options
Ingo Proetel <proetel@aicas.de>
parents:
14441
diff
changeset
|
22 |
# same options as commit + white space diff options |
20300
0076643077a3
record: use commands.diffwsopts instead of ad-hoc diffopts
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
20266
diff
changeset
|
23 |
commands.table['^commit|ci'][1][:] + commands.diffwsopts, |
14408
054da1e0afbe
record: use cmdutil.command decorator
Idan Kamara <idankk86@gmail.com>
parents:
14407
diff
changeset
|
24 |
_('hg record [OPTION]... [FILE]...')) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
25 |
def record(ui, repo, *pats, **opts): |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
26 |
'''interactively select changes to commit |
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
27 |
|
10973
49a07f441496
Use hg role in help strings
Martin Geisler <mg@aragost.com>
parents:
10890
diff
changeset
|
28 |
If a list of files is omitted, all changes reported by :hg:`status` |
9272
784899697571
record: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9157
diff
changeset
|
29 |
will be candidates for recording. |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
30 |
|
10973
49a07f441496
Use hg role in help strings
Martin Geisler <mg@aragost.com>
parents:
10890
diff
changeset
|
31 |
See :hg:`help dates` for a list of formats valid for -d/--date. |
6163
1f733c2f0165
Document log date ranges and mention 'hg help dates' for all commands (issue998)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5932
diff
changeset
|
32 |
|
9272
784899697571
record: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9157
diff
changeset
|
33 |
You will be prompted for whether to record changes to each |
784899697571
record: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9157
diff
changeset
|
34 |
modified file, and for files with multiple changes, for each |
784899697571
record: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9157
diff
changeset
|
35 |
change to use. For each query, the following responses are |
784899697571
record: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9157
diff
changeset
|
36 |
possible:: |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
37 |
|
9157
9261667e9b82
commands: use minirst parser when displaying help
Martin Geisler <mg@lazybytes.net>
parents:
9087
diff
changeset
|
38 |
y - record this change |
9261667e9b82
commands: use minirst parser when displaying help
Martin Geisler <mg@lazybytes.net>
parents:
9087
diff
changeset
|
39 |
n - skip this change |
16324
46b991a1f428
record: allow splitting of hunks by manually editing patches
A. S. Budden <abudden@gmail.com>
parents:
15184
diff
changeset
|
40 |
e - edit this change manually |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
41 |
|
9157
9261667e9b82
commands: use minirst parser when displaying help
Martin Geisler <mg@lazybytes.net>
parents:
9087
diff
changeset
|
42 |
s - skip remaining changes to this file |
9261667e9b82
commands: use minirst parser when displaying help
Martin Geisler <mg@lazybytes.net>
parents:
9087
diff
changeset
|
43 |
f - record remaining changes to this file |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
44 |
|
9157
9261667e9b82
commands: use minirst parser when displaying help
Martin Geisler <mg@lazybytes.net>
parents:
9087
diff
changeset
|
45 |
d - done, skip remaining changes and files |
9261667e9b82
commands: use minirst parser when displaying help
Martin Geisler <mg@lazybytes.net>
parents:
9087
diff
changeset
|
46 |
a - record all changes to all remaining files |
9261667e9b82
commands: use minirst parser when displaying help
Martin Geisler <mg@lazybytes.net>
parents:
9087
diff
changeset
|
47 |
q - quit, recording no changes |
5154
67afecb8d6cc
record: improve docs, improve prompts
Bryan O'Sullivan <bos@serpentine.com>
parents:
5147
diff
changeset
|
48 |
|
11237
feb2a58fc592
record: check that we are not committing a merge before patch selection
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11236
diff
changeset
|
49 |
? - display help |
feb2a58fc592
record: check that we are not committing a merge before patch selection
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11236
diff
changeset
|
50 |
|
feb2a58fc592
record: check that we are not committing a merge before patch selection
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11236
diff
changeset
|
51 |
This command is not available when committing a merge.''' |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
52 |
|
14425
e89534504fb9
record: add an option to backup all wc modifications
Idan Kamara <idankk86@gmail.com>
parents:
14424
diff
changeset
|
53 |
dorecord(ui, repo, commands.commit, 'commit', False, *pats, **opts) |
5830
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
54 |
|
15184
351a9292e430
record: use command wrapper properly for qnew/qrefresh (issue3001)
Matt Mackall <mpm@selenic.com>
parents:
14597
diff
changeset
|
55 |
def qrefresh(origfn, ui, repo, *pats, **opts): |
351a9292e430
record: use command wrapper properly for qnew/qrefresh (issue3001)
Matt Mackall <mpm@selenic.com>
parents:
14597
diff
changeset
|
56 |
if not opts['interactive']: |
351a9292e430
record: use command wrapper properly for qnew/qrefresh (issue3001)
Matt Mackall <mpm@selenic.com>
parents:
14597
diff
changeset
|
57 |
return origfn(ui, repo, *pats, **opts) |
351a9292e430
record: use command wrapper properly for qnew/qrefresh (issue3001)
Matt Mackall <mpm@selenic.com>
parents:
14597
diff
changeset
|
58 |
|
14426
1df64ccef23e
record: add qrefresh -i/--interactive
Idan Kamara <idankk86@gmail.com>
parents:
14425
diff
changeset
|
59 |
mq = extensions.find('mq') |
1df64ccef23e
record: add qrefresh -i/--interactive
Idan Kamara <idankk86@gmail.com>
parents:
14425
diff
changeset
|
60 |
|
1df64ccef23e
record: add qrefresh -i/--interactive
Idan Kamara <idankk86@gmail.com>
parents:
14425
diff
changeset
|
61 |
def committomq(ui, repo, *pats, **opts): |
1df64ccef23e
record: add qrefresh -i/--interactive
Idan Kamara <idankk86@gmail.com>
parents:
14425
diff
changeset
|
62 |
# At this point the working copy contains only changes that |
1df64ccef23e
record: add qrefresh -i/--interactive
Idan Kamara <idankk86@gmail.com>
parents:
14425
diff
changeset
|
63 |
# were accepted. All other changes were reverted. |
1df64ccef23e
record: add qrefresh -i/--interactive
Idan Kamara <idankk86@gmail.com>
parents:
14425
diff
changeset
|
64 |
# We can't pass *pats here since qrefresh will undo all other |
1df64ccef23e
record: add qrefresh -i/--interactive
Idan Kamara <idankk86@gmail.com>
parents:
14425
diff
changeset
|
65 |
# changed files in the patch that aren't in pats. |
1df64ccef23e
record: add qrefresh -i/--interactive
Idan Kamara <idankk86@gmail.com>
parents:
14425
diff
changeset
|
66 |
mq.refresh(ui, repo, **opts) |
1df64ccef23e
record: add qrefresh -i/--interactive
Idan Kamara <idankk86@gmail.com>
parents:
14425
diff
changeset
|
67 |
|
1df64ccef23e
record: add qrefresh -i/--interactive
Idan Kamara <idankk86@gmail.com>
parents:
14425
diff
changeset
|
68 |
# backup all changed files |
1df64ccef23e
record: add qrefresh -i/--interactive
Idan Kamara <idankk86@gmail.com>
parents:
14425
diff
changeset
|
69 |
dorecord(ui, repo, committomq, 'qrefresh', True, *pats, **opts) |
5830
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
70 |
|
21251
a836fa58b512
record: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
20334
diff
changeset
|
71 |
# This command registration is replaced during uisetup(). |
21787
fb5f34bb3867
record: define inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21251
diff
changeset
|
72 |
@command('qrecord', |
fb5f34bb3867
record: define inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21251
diff
changeset
|
73 |
[], |
fb5f34bb3867
record: define inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21251
diff
changeset
|
74 |
_('hg qrecord [OPTION]... PATCH [FILE]...'), |
fb5f34bb3867
record: define inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21251
diff
changeset
|
75 |
inferrepo=True) |
5932
b014ff3fdaeb
qrecord: record complements commit, so qrecord should complement qnew
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5830
diff
changeset
|
76 |
def qrecord(ui, repo, patch, *pats, **opts): |
b014ff3fdaeb
qrecord: record complements commit, so qrecord should complement qnew
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5830
diff
changeset
|
77 |
'''interactively record a new patch |
5830
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
78 |
|
10973
49a07f441496
Use hg role in help strings
Martin Geisler <mg@aragost.com>
parents:
10890
diff
changeset
|
79 |
See :hg:`help qnew` & :hg:`help record` for more information and |
9272
784899697571
record: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9157
diff
changeset
|
80 |
usage. |
5830
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
81 |
''' |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
82 |
|
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
83 |
try: |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
84 |
mq = extensions.find('mq') |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
85 |
except KeyError: |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
86 |
raise util.Abort(_("'mq' extension not loaded")) |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
87 |
|
14424
4eb88d296f63
record: check patch name is valid before prompting in qrecord
Idan Kamara <idankk86@gmail.com>
parents:
14408
diff
changeset
|
88 |
repo.mq.checkpatchname(patch) |
4eb88d296f63
record: check patch name is valid before prompting in qrecord
Idan Kamara <idankk86@gmail.com>
parents:
14408
diff
changeset
|
89 |
|
10323
0aa59f532ef9
record: function variable naming & signature cleanup.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
10282
diff
changeset
|
90 |
def committomq(ui, repo, *pats, **opts): |
14424
4eb88d296f63
record: check patch name is valid before prompting in qrecord
Idan Kamara <idankk86@gmail.com>
parents:
14408
diff
changeset
|
91 |
opts['checkname'] = False |
5932
b014ff3fdaeb
qrecord: record complements commit, so qrecord should complement qnew
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5830
diff
changeset
|
92 |
mq.new(ui, repo, patch, *pats, **opts) |
5830
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
93 |
|
14425
e89534504fb9
record: add an option to backup all wc modifications
Idan Kamara <idankk86@gmail.com>
parents:
14424
diff
changeset
|
94 |
dorecord(ui, repo, committomq, 'qnew', False, *pats, **opts) |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
95 |
|
15184
351a9292e430
record: use command wrapper properly for qnew/qrefresh (issue3001)
Matt Mackall <mpm@selenic.com>
parents:
14597
diff
changeset
|
96 |
def qnew(origfn, ui, repo, patch, *args, **opts): |
351a9292e430
record: use command wrapper properly for qnew/qrefresh (issue3001)
Matt Mackall <mpm@selenic.com>
parents:
14597
diff
changeset
|
97 |
if opts['interactive']: |
351a9292e430
record: use command wrapper properly for qnew/qrefresh (issue3001)
Matt Mackall <mpm@selenic.com>
parents:
14597
diff
changeset
|
98 |
return qrecord(ui, repo, patch, *args, **opts) |
351a9292e430
record: use command wrapper properly for qnew/qrefresh (issue3001)
Matt Mackall <mpm@selenic.com>
parents:
14597
diff
changeset
|
99 |
return origfn(ui, repo, patch, *args, **opts) |
351a9292e430
record: use command wrapper properly for qnew/qrefresh (issue3001)
Matt Mackall <mpm@selenic.com>
parents:
14597
diff
changeset
|
100 |
|
14425
e89534504fb9
record: add an option to backup all wc modifications
Idan Kamara <idankk86@gmail.com>
parents:
14424
diff
changeset
|
101 |
def dorecord(ui, repo, commitfunc, cmdsuggest, backupall, *pats, **opts): |
8208
32a2a1e244f1
ui: make interactive a method
Matt Mackall <mpm@selenic.com>
parents:
8152
diff
changeset
|
102 |
if not ui.interactive(): |
14407
51cabd567ac6
record: suggest the right command when running non interactively
Idan Kamara <idankk86@gmail.com>
parents:
14370
diff
changeset
|
103 |
raise util.Abort(_('running non-interactively, use %s instead') % |
51cabd567ac6
record: suggest the right command when running non interactively
Idan Kamara <idankk86@gmail.com>
parents:
14370
diff
changeset
|
104 |
cmdsuggest) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
105 |
|
17446
3de04c07966a
record: checks for valid username before starting recording process (issue3456)
Sumeet <sumeet@fb.com>
parents:
17425
diff
changeset
|
106 |
# make sure username is set before going interactive |
20171
a765611e06dc
record: --user/-u now works with record when ui.username not set (issue3857)
Prasoon Shukla <prasoon92.iitr@gmail.com>
parents:
19497
diff
changeset
|
107 |
if not opts.get('user'): |
a765611e06dc
record: --user/-u now works with record when ui.username not set (issue3857)
Prasoon Shukla <prasoon92.iitr@gmail.com>
parents:
19497
diff
changeset
|
108 |
ui.username() # raise exception, username not provided |
17446
3de04c07966a
record: checks for valid username before starting recording process (issue3456)
Sumeet <sumeet@fb.com>
parents:
17425
diff
changeset
|
109 |
|
6600
b822a379860b
match: stop passing files through commitfunc
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
110 |
def recordfunc(ui, repo, message, match, opts): |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
111 |
"""This is generic record driver. |
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
112 |
|
13195
f14cfcc488fb
record: clean up comments and docstrings
Kevin Bullock <kbullock@ringworld.org>
parents:
13157
diff
changeset
|
113 |
Its job is to interactively filter local changes, and |
f14cfcc488fb
record: clean up comments and docstrings
Kevin Bullock <kbullock@ringworld.org>
parents:
13157
diff
changeset
|
114 |
accordingly prepare working directory into a state in which the |
f14cfcc488fb
record: clean up comments and docstrings
Kevin Bullock <kbullock@ringworld.org>
parents:
13157
diff
changeset
|
115 |
job can be delegated to a non-interactive commit command such as |
f14cfcc488fb
record: clean up comments and docstrings
Kevin Bullock <kbullock@ringworld.org>
parents:
13157
diff
changeset
|
116 |
'commit' or 'qrefresh'. |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
117 |
|
13195
f14cfcc488fb
record: clean up comments and docstrings
Kevin Bullock <kbullock@ringworld.org>
parents:
13157
diff
changeset
|
118 |
After the actual job is done by non-interactive command, the |
f14cfcc488fb
record: clean up comments and docstrings
Kevin Bullock <kbullock@ringworld.org>
parents:
13157
diff
changeset
|
119 |
working directory is restored to its original state. |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
120 |
|
13195
f14cfcc488fb
record: clean up comments and docstrings
Kevin Bullock <kbullock@ringworld.org>
parents:
13157
diff
changeset
|
121 |
In the end we'll record interesting changes, and everything else |
f14cfcc488fb
record: clean up comments and docstrings
Kevin Bullock <kbullock@ringworld.org>
parents:
13157
diff
changeset
|
122 |
will be left in place, so the user can continue working. |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
123 |
""" |
7754
ab00d2c281a8
record: minimize number of status calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7718
diff
changeset
|
124 |
|
19497
e012a20061ed
record: add checkunfinished support (issue3955)
Matt Mackall <mpm@selenic.com>
parents:
19226
diff
changeset
|
125 |
cmdutil.checkunfinished(repo, commit=True) |
11237
feb2a58fc592
record: check that we are not committing a merge before patch selection
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11236
diff
changeset
|
126 |
merge = len(repo[None].parents()) > 1 |
feb2a58fc592
record: check that we are not committing a merge before patch selection
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11236
diff
changeset
|
127 |
if merge: |
feb2a58fc592
record: check that we are not committing a merge before patch selection
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11236
diff
changeset
|
128 |
raise util.Abort(_('cannot partially commit a merge ' |
13023
3e2281b85990
record: quote command in use hg commit message
timeless <timeless@gmail.com>
parents:
12674
diff
changeset
|
129 |
'(use "hg commit" instead)')) |
11237
feb2a58fc592
record: check that we are not committing a merge before patch selection
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11236
diff
changeset
|
130 |
|
22921
75e7d4a0f135
record: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
21805
diff
changeset
|
131 |
status = repo.status(match=match) |
23435
486a1fe09422
record: don't honor format-changing diffopts (issue4459)
Siddharth Agarwal <sid0@fb.com>
parents:
23270
diff
changeset
|
132 |
diffopts = patch.difffeatureopts(ui, opts=opts, whitespace=True) |
486a1fe09422
record: don't honor format-changing diffopts (issue4459)
Siddharth Agarwal <sid0@fb.com>
parents:
23270
diff
changeset
|
133 |
diffopts.nodates = True |
486a1fe09422
record: don't honor format-changing diffopts (issue4459)
Siddharth Agarwal <sid0@fb.com>
parents:
23270
diff
changeset
|
134 |
diffopts.git = True |
24235
79fceed67676
record: allow editing new files (issue4304)
Laurent Charignon <lcharignon@fb.com>
parents:
23435
diff
changeset
|
135 |
originalchunks = patch.diff(repo, changes=status, opts=diffopts) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
136 |
fp = cStringIO.StringIO() |
24235
79fceed67676
record: allow editing new files (issue4304)
Laurent Charignon <lcharignon@fb.com>
parents:
23435
diff
changeset
|
137 |
fp.write(''.join(originalchunks)) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
138 |
fp.seek(0) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
139 |
|
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
140 |
# 1. filter patch, so we have intending-to apply subset of it |
18953
e4ae397595e8
record: abort on malformed patches instead of crashing
Mads Kiilerich <madski@unity3d.com>
parents:
18287
diff
changeset
|
141 |
try: |
24269
9a745ced79a9
record: move filterpatch from record to patch
Laurent Charignon <lcharignon@fb.com>
parents:
24268
diff
changeset
|
142 |
chunks = patch.filterpatch(ui, patch.parsepatch(fp)) |
18953
e4ae397595e8
record: abort on malformed patches instead of crashing
Mads Kiilerich <madski@unity3d.com>
parents:
18287
diff
changeset
|
143 |
except patch.PatchError, err: |
e4ae397595e8
record: abort on malformed patches instead of crashing
Mads Kiilerich <madski@unity3d.com>
parents:
18287
diff
changeset
|
144 |
raise util.Abort(_('error parsing patch: %s') % err) |
e4ae397595e8
record: abort on malformed patches instead of crashing
Mads Kiilerich <madski@unity3d.com>
parents:
18287
diff
changeset
|
145 |
|
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
146 |
del fp |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
147 |
|
8152
08e1baf924ca
replace set-like dictionaries with real sets
Martin Geisler <mg@lazybytes.net>
parents:
7983
diff
changeset
|
148 |
contenders = set() |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
149 |
for h in chunks: |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
150 |
try: |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
151 |
contenders.update(set(h.files())) |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
152 |
except AttributeError: |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
153 |
pass |
5143
d4fa6bafc43a
Remove trailing spaces, fix indentation
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5129
diff
changeset
|
154 |
|
22921
75e7d4a0f135
record: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
21805
diff
changeset
|
155 |
changed = status.modified + status.added + status.removed |
7754
ab00d2c281a8
record: minimize number of status calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7718
diff
changeset
|
156 |
newfiles = [f for f in changed if f in contenders] |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
157 |
if not newfiles: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
158 |
ui.status(_('no changes to record\n')) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
159 |
return 0 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
160 |
|
24235
79fceed67676
record: allow editing new files (issue4304)
Laurent Charignon <lcharignon@fb.com>
parents:
23435
diff
changeset
|
161 |
newandmodifiedfiles = set() |
79fceed67676
record: allow editing new files (issue4304)
Laurent Charignon <lcharignon@fb.com>
parents:
23435
diff
changeset
|
162 |
for h in chunks: |
24263
a45d1c51109e
record: move hunk class from record to patch
Laurent Charignon <lcharignon@fb.com>
parents:
24262
diff
changeset
|
163 |
ishunk = isinstance(h, patch.recordhunk) |
24235
79fceed67676
record: allow editing new files (issue4304)
Laurent Charignon <lcharignon@fb.com>
parents:
23435
diff
changeset
|
164 |
isnew = h.filename() in status.added |
79fceed67676
record: allow editing new files (issue4304)
Laurent Charignon <lcharignon@fb.com>
parents:
23435
diff
changeset
|
165 |
if ishunk and isnew and not h in originalchunks: |
79fceed67676
record: allow editing new files (issue4304)
Laurent Charignon <lcharignon@fb.com>
parents:
23435
diff
changeset
|
166 |
newandmodifiedfiles.add(h.filename()) |
79fceed67676
record: allow editing new files (issue4304)
Laurent Charignon <lcharignon@fb.com>
parents:
23435
diff
changeset
|
167 |
|
22921
75e7d4a0f135
record: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
21805
diff
changeset
|
168 |
modified = set(status.modified) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
169 |
|
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
170 |
# 2. backup changed files, so we can restore them in the end |
24235
79fceed67676
record: allow editing new files (issue4304)
Laurent Charignon <lcharignon@fb.com>
parents:
23435
diff
changeset
|
171 |
|
14425
e89534504fb9
record: add an option to backup all wc modifications
Idan Kamara <idankk86@gmail.com>
parents:
14424
diff
changeset
|
172 |
if backupall: |
e89534504fb9
record: add an option to backup all wc modifications
Idan Kamara <idankk86@gmail.com>
parents:
14424
diff
changeset
|
173 |
tobackup = changed |
e89534504fb9
record: add an option to backup all wc modifications
Idan Kamara <idankk86@gmail.com>
parents:
14424
diff
changeset
|
174 |
else: |
24235
79fceed67676
record: allow editing new files (issue4304)
Laurent Charignon <lcharignon@fb.com>
parents:
23435
diff
changeset
|
175 |
tobackup = [f for f in newfiles |
79fceed67676
record: allow editing new files (issue4304)
Laurent Charignon <lcharignon@fb.com>
parents:
23435
diff
changeset
|
176 |
if f in modified or f in newandmodifiedfiles] |
14425
e89534504fb9
record: add an option to backup all wc modifications
Idan Kamara <idankk86@gmail.com>
parents:
14424
diff
changeset
|
177 |
|
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
178 |
backups = {} |
14425
e89534504fb9
record: add an option to backup all wc modifications
Idan Kamara <idankk86@gmail.com>
parents:
14424
diff
changeset
|
179 |
if tobackup: |
e89534504fb9
record: add an option to backup all wc modifications
Idan Kamara <idankk86@gmail.com>
parents:
14424
diff
changeset
|
180 |
backupdir = repo.join('record-backups') |
e89534504fb9
record: add an option to backup all wc modifications
Idan Kamara <idankk86@gmail.com>
parents:
14424
diff
changeset
|
181 |
try: |
e89534504fb9
record: add an option to backup all wc modifications
Idan Kamara <idankk86@gmail.com>
parents:
14424
diff
changeset
|
182 |
os.mkdir(backupdir) |
e89534504fb9
record: add an option to backup all wc modifications
Idan Kamara <idankk86@gmail.com>
parents:
14424
diff
changeset
|
183 |
except OSError, err: |
e89534504fb9
record: add an option to backup all wc modifications
Idan Kamara <idankk86@gmail.com>
parents:
14424
diff
changeset
|
184 |
if err.errno != errno.EEXIST: |
e89534504fb9
record: add an option to backup all wc modifications
Idan Kamara <idankk86@gmail.com>
parents:
14424
diff
changeset
|
185 |
raise |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
186 |
try: |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
187 |
# backup continues |
14425
e89534504fb9
record: add an option to backup all wc modifications
Idan Kamara <idankk86@gmail.com>
parents:
14424
diff
changeset
|
188 |
for f in tobackup: |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
189 |
fd, tmpname = tempfile.mkstemp(prefix=f.replace('/', '_')+'.', |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
190 |
dir=backupdir) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
191 |
os.close(fd) |
9467
4c041f1ee1b4
do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents:
9272
diff
changeset
|
192 |
ui.debug('backup %r as %r\n' % (f, tmpname)) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
193 |
util.copyfile(repo.wjoin(f), tmpname) |
13099
a08b49d2f116
record: move copystat() hack out of util.copyfile() and into record
Brodie Rao <brodie@bitheap.org>
parents:
13075
diff
changeset
|
194 |
shutil.copystat(repo.wjoin(f), tmpname) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
195 |
backups[f] = tmpname |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
196 |
|
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
197 |
fp = cStringIO.StringIO() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
198 |
for c in chunks: |
24235
79fceed67676
record: allow editing new files (issue4304)
Laurent Charignon <lcharignon@fb.com>
parents:
23435
diff
changeset
|
199 |
fname = c.filename() |
79fceed67676
record: allow editing new files (issue4304)
Laurent Charignon <lcharignon@fb.com>
parents:
23435
diff
changeset
|
200 |
if fname in backups or fname in newandmodifiedfiles: |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
201 |
c.write(fp) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
202 |
dopatch = fp.tell() |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
203 |
fp.seek(0) |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
204 |
|
24235
79fceed67676
record: allow editing new files (issue4304)
Laurent Charignon <lcharignon@fb.com>
parents:
23435
diff
changeset
|
205 |
[os.unlink(c) for c in newandmodifiedfiles] |
79fceed67676
record: allow editing new files (issue4304)
Laurent Charignon <lcharignon@fb.com>
parents:
23435
diff
changeset
|
206 |
|
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
207 |
# 3a. apply filtered patch to clean repo (clean) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
208 |
if backups: |
24271
18792f2e38bb
record: remove dependency on hg module in record
Laurent Charignon <lcharignon@fb.com>
parents:
24270
diff
changeset
|
209 |
# Equivalent to hg.revert |
18792f2e38bb
record: remove dependency on hg module in record
Laurent Charignon <lcharignon@fb.com>
parents:
24270
diff
changeset
|
210 |
choices = lambda key: key in backups |
18792f2e38bb
record: remove dependency on hg module in record
Laurent Charignon <lcharignon@fb.com>
parents:
24270
diff
changeset
|
211 |
mergemod.update(repo, repo.dirstate.p1(), |
18792f2e38bb
record: remove dependency on hg module in record
Laurent Charignon <lcharignon@fb.com>
parents:
24270
diff
changeset
|
212 |
False, True, choices) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
213 |
|
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
214 |
# 3b. (apply) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
215 |
if dopatch: |
6950
381a892159d9
record: catch PatchErrors from internalpatch and display error message
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6949
diff
changeset
|
216 |
try: |
9467
4c041f1ee1b4
do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents:
9272
diff
changeset
|
217 |
ui.debug('applying patch\n') |
6950
381a892159d9
record: catch PatchErrors from internalpatch and display error message
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6949
diff
changeset
|
218 |
ui.debug(fp.getvalue()) |
24268
cf7d252d8c30
patch.internalpatch: add a default value for prefix
Siddharth Agarwal <sid0@fb.com>
parents:
24265
diff
changeset
|
219 |
patch.internalpatch(ui, repo, fp, 1, eolmode=None) |
6950
381a892159d9
record: catch PatchErrors from internalpatch and display error message
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6949
diff
changeset
|
220 |
except patch.PatchError, err: |
12674
aa2fe1f52ff4
patch: always raise PatchError with a message, simplify handling
Patrick Mezard <pmezard@gmail.com>
parents:
12266
diff
changeset
|
221 |
raise util.Abort(str(err)) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
222 |
del fp |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
223 |
|
13195
f14cfcc488fb
record: clean up comments and docstrings
Kevin Bullock <kbullock@ringworld.org>
parents:
13157
diff
changeset
|
224 |
# 4. We prepared working directory according to filtered |
f14cfcc488fb
record: clean up comments and docstrings
Kevin Bullock <kbullock@ringworld.org>
parents:
13157
diff
changeset
|
225 |
# patch. Now is the time to delegate the job to |
f14cfcc488fb
record: clean up comments and docstrings
Kevin Bullock <kbullock@ringworld.org>
parents:
13157
diff
changeset
|
226 |
# commit/qrefresh or the like! |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
227 |
|
21805
23f3241406ff
record: update comment to match code
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21787
diff
changeset
|
228 |
# Make all of the pathnames absolute. |
20334
205599e31870
record: use absolute path instead of os.chdir
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20301
diff
changeset
|
229 |
newfiles = [repo.wjoin(nf) for nf in newfiles] |
205599e31870
record: use absolute path instead of os.chdir
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20301
diff
changeset
|
230 |
commitfunc(ui, repo, *newfiles, **opts) |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
231 |
|
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
232 |
return 0 |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
233 |
finally: |
5827
0c29977bd7db
record: refactor record into generic record driver
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5826
diff
changeset
|
234 |
# 5. finally restore backed-up files |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
235 |
try: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
236 |
for realname, tmpname in backups.iteritems(): |
9467
4c041f1ee1b4
do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents:
9272
diff
changeset
|
237 |
ui.debug('restoring %r to %r\n' % (tmpname, realname)) |
5128
c9126c24e098
record: work properly if invoked in a subdirectory
Bryan O'Sullivan <bos@serpentine.com>
parents:
5040
diff
changeset
|
238 |
util.copyfile(tmpname, repo.wjoin(realname)) |
13099
a08b49d2f116
record: move copystat() hack out of util.copyfile() and into record
Brodie Rao <brodie@bitheap.org>
parents:
13075
diff
changeset
|
239 |
# Our calls to copystat() here and above are a |
a08b49d2f116
record: move copystat() hack out of util.copyfile() and into record
Brodie Rao <brodie@bitheap.org>
parents:
13075
diff
changeset
|
240 |
# hack to trick any editors that have f open that |
a08b49d2f116
record: move copystat() hack out of util.copyfile() and into record
Brodie Rao <brodie@bitheap.org>
parents:
13075
diff
changeset
|
241 |
# we haven't modified them. |
a08b49d2f116
record: move copystat() hack out of util.copyfile() and into record
Brodie Rao <brodie@bitheap.org>
parents:
13075
diff
changeset
|
242 |
# |
a08b49d2f116
record: move copystat() hack out of util.copyfile() and into record
Brodie Rao <brodie@bitheap.org>
parents:
13075
diff
changeset
|
243 |
# Also note that this racy as an editor could |
a08b49d2f116
record: move copystat() hack out of util.copyfile() and into record
Brodie Rao <brodie@bitheap.org>
parents:
13075
diff
changeset
|
244 |
# notice the file's mtime before we've finished |
a08b49d2f116
record: move copystat() hack out of util.copyfile() and into record
Brodie Rao <brodie@bitheap.org>
parents:
13075
diff
changeset
|
245 |
# writing it. |
a08b49d2f116
record: move copystat() hack out of util.copyfile() and into record
Brodie Rao <brodie@bitheap.org>
parents:
13075
diff
changeset
|
246 |
shutil.copystat(tmpname, repo.wjoin(realname)) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
247 |
os.unlink(tmpname) |
14425
e89534504fb9
record: add an option to backup all wc modifications
Idan Kamara <idankk86@gmail.com>
parents:
14424
diff
changeset
|
248 |
if tobackup: |
e89534504fb9
record: add an option to backup all wc modifications
Idan Kamara <idankk86@gmail.com>
parents:
14424
diff
changeset
|
249 |
os.rmdir(backupdir) |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
250 |
except OSError: |
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
251 |
pass |
10825
781689b9b6bb
record: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10694
diff
changeset
|
252 |
|
781689b9b6bb
record: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10694
diff
changeset
|
253 |
# wrap ui.write so diff output can be labeled/colorized |
781689b9b6bb
record: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10694
diff
changeset
|
254 |
def wrapwrite(orig, *args, **kw): |
781689b9b6bb
record: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10694
diff
changeset
|
255 |
label = kw.pop('label', '') |
781689b9b6bb
record: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10694
diff
changeset
|
256 |
for chunk, l in patch.difflabel(lambda: args): |
781689b9b6bb
record: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10694
diff
changeset
|
257 |
orig(chunk, label=label + l) |
781689b9b6bb
record: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10694
diff
changeset
|
258 |
oldwrite = ui.write |
24270
c256ae48fd26
record: remove dependency on extensions module in dorecord
Laurent Charignon <lcharignon@fb.com>
parents:
24269
diff
changeset
|
259 |
|
c256ae48fd26
record: remove dependency on extensions module in dorecord
Laurent Charignon <lcharignon@fb.com>
parents:
24269
diff
changeset
|
260 |
def wrap(*args, **kwargs): |
c256ae48fd26
record: remove dependency on extensions module in dorecord
Laurent Charignon <lcharignon@fb.com>
parents:
24269
diff
changeset
|
261 |
return wrapwrite(oldwrite, *args, **kwargs) |
c256ae48fd26
record: remove dependency on extensions module in dorecord
Laurent Charignon <lcharignon@fb.com>
parents:
24269
diff
changeset
|
262 |
setattr(ui, 'write', wrap) |
c256ae48fd26
record: remove dependency on extensions module in dorecord
Laurent Charignon <lcharignon@fb.com>
parents:
24269
diff
changeset
|
263 |
|
10825
781689b9b6bb
record: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10694
diff
changeset
|
264 |
try: |
781689b9b6bb
record: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10694
diff
changeset
|
265 |
return cmdutil.commit(ui, repo, recordfunc, pats, opts) |
781689b9b6bb
record: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10694
diff
changeset
|
266 |
finally: |
781689b9b6bb
record: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10694
diff
changeset
|
267 |
ui.write = oldwrite |
5037
b2607267236d
Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
268 |
|
9710
1765599f4899
record: use uisetup instead of extsetup to register qrecord
Martin Geisler <mg@lazybytes.net>
parents:
9688
diff
changeset
|
269 |
def uisetup(ui): |
5830
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
270 |
try: |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
271 |
mq = extensions.find('mq') |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
272 |
except KeyError: |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
273 |
return |
c32d41affb68
hg qrecord -- like record, but for mq
Kirill Smelkov <kirr@mns.spb.ru>
parents:
5827
diff
changeset
|
274 |
|
14408
054da1e0afbe
record: use cmdutil.command decorator
Idan Kamara <idankk86@gmail.com>
parents:
14407
diff
changeset
|
275 |
cmdtable["qrecord"] = \ |
14427
9d4cabd189df
record: alias qrecord to qnew -i/--interactive
Idan Kamara <idankk86@gmail.com>
parents:
14426
diff
changeset
|
276 |
(qrecord, |
9d4cabd189df
record: alias qrecord to qnew -i/--interactive
Idan Kamara <idankk86@gmail.com>
parents:
14426
diff
changeset
|
277 |
# same options as qnew, but copy them so we don't get |
14597
3f1dccea9510
record: add white space diff options
Ingo Proetel <proetel@aicas.de>
parents:
14441
diff
changeset
|
278 |
# -i/--interactive for qrecord and add white space diff options |
20300
0076643077a3
record: use commands.diffwsopts instead of ad-hoc diffopts
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
20266
diff
changeset
|
279 |
mq.cmdtable['^qnew'][1][:] + commands.diffwsopts, |
14408
054da1e0afbe
record: use cmdutil.command decorator
Idan Kamara <idankk86@gmail.com>
parents:
14407
diff
changeset
|
280 |
_('hg qrecord [OPTION]... PATCH [FILE]...')) |
14426
1df64ccef23e
record: add qrefresh -i/--interactive
Idan Kamara <idankk86@gmail.com>
parents:
14425
diff
changeset
|
281 |
|
15184
351a9292e430
record: use command wrapper properly for qnew/qrefresh (issue3001)
Matt Mackall <mpm@selenic.com>
parents:
14597
diff
changeset
|
282 |
_wrapcmd('qnew', mq.cmdtable, qnew, _("interactively record a new patch")) |
14426
1df64ccef23e
record: add qrefresh -i/--interactive
Idan Kamara <idankk86@gmail.com>
parents:
14425
diff
changeset
|
283 |
_wrapcmd('qrefresh', mq.cmdtable, qrefresh, |
1df64ccef23e
record: add qrefresh -i/--interactive
Idan Kamara <idankk86@gmail.com>
parents:
14425
diff
changeset
|
284 |
_("interactively select changes to refresh")) |
1df64ccef23e
record: add qrefresh -i/--interactive
Idan Kamara <idankk86@gmail.com>
parents:
14425
diff
changeset
|
285 |
|
1df64ccef23e
record: add qrefresh -i/--interactive
Idan Kamara <idankk86@gmail.com>
parents:
14425
diff
changeset
|
286 |
def _wrapcmd(cmd, table, wrapfn, msg): |
15184
351a9292e430
record: use command wrapper properly for qnew/qrefresh (issue3001)
Matt Mackall <mpm@selenic.com>
parents:
14597
diff
changeset
|
287 |
entry = extensions.wrapcommand(table, cmd, wrapfn) |
14426
1df64ccef23e
record: add qrefresh -i/--interactive
Idan Kamara <idankk86@gmail.com>
parents:
14425
diff
changeset
|
288 |
entry[1].append(('i', 'interactive', None, msg)) |