2007-08-01 03:28:05 +04:00
|
|
|
# record.py
|
|
|
|
#
|
|
|
|
# Copyright 2007 Bryan O'Sullivan <bos@serpentine.com>
|
|
|
|
#
|
2009-04-26 03:08:54 +04:00
|
|
|
# This software may be used and distributed according to the terms of the
|
2010-01-20 07:20:08 +03:00
|
|
|
# GNU General Public License version 2 or any later version.
|
2007-08-01 03:28:05 +04:00
|
|
|
|
2009-06-24 15:42:02 +04:00
|
|
|
'''commands to interactively select changes for commit/qrefresh'''
|
2007-08-01 03:28:05 +04:00
|
|
|
|
2013-12-01 19:50:30 +04:00
|
|
|
from mercurial.i18n import _
|
2015-03-11 03:14:33 +03:00
|
|
|
from mercurial import cmdutil, commands, extensions
|
2007-08-01 03:28:05 +04:00
|
|
|
from mercurial import util
|
|
|
|
|
2011-05-22 17:10:03 +04:00
|
|
|
cmdtable = {}
|
|
|
|
command = cmdutil.command(cmdtable)
|
2012-05-15 23:37:49 +04:00
|
|
|
testedwith = 'internal'
|
2011-05-22 17:10:03 +04:00
|
|
|
|
2007-08-01 03:28:05 +04:00
|
|
|
|
2011-05-22 17:10:03 +04:00
|
|
|
@command("record",
|
2011-06-10 12:58:10 +04:00
|
|
|
# same options as commit + white space diff options
|
2015-03-12 01:22:04 +03:00
|
|
|
[c for c in commands.table['^commit|ci'][1][:]
|
|
|
|
if c[1] != "interactive"] + commands.diffwsopts,
|
2011-05-22 17:10:03 +04:00
|
|
|
_('hg record [OPTION]... [FILE]...'))
|
2007-08-01 03:28:05 +04:00
|
|
|
def record(ui, repo, *pats, **opts):
|
2007-08-10 04:29:16 +04:00
|
|
|
'''interactively select changes to commit
|
|
|
|
|
2010-04-22 12:24:49 +04:00
|
|
|
If a list of files is omitted, all changes reported by :hg:`status`
|
2009-07-26 04:00:58 +04:00
|
|
|
will be candidates for recording.
|
2007-08-10 04:29:16 +04:00
|
|
|
|
2010-04-22 12:24:49 +04:00
|
|
|
See :hg:`help dates` for a list of formats valid for -d/--date.
|
2008-02-22 23:18:48 +03:00
|
|
|
|
2009-07-26 04:00:58 +04:00
|
|
|
You will be prompted for whether to record changes to each
|
|
|
|
modified file, and for files with multiple changes, for each
|
|
|
|
change to use. For each query, the following responses are
|
|
|
|
possible::
|
2007-08-10 04:29:16 +04:00
|
|
|
|
2009-07-17 01:25:26 +04:00
|
|
|
y - record this change
|
|
|
|
n - skip this change
|
record: allow splitting of hunks by manually editing patches
It is possible that unrelated changes in a file are on sequential lines. The
current record extension does not allow these to be committed independently.
An example use case for this is in software development for deeply embedded
real-time systems. In these environments, it is not always possible to use a
debugger (due to time-constraints) and hence inline UART-based printing is
often used. When fixing a bug in a module, it is often convenient to add a
large number of 'printf's (linked to the UART via a custom fputc) to the module
in order to work out what is going wrong. printf is a very slow function (and
also variadic so somewhat frowned upon by the MISRA standard) and hence it is
highly undesirable to commit these lines to the repository. If only a partial
fix is implemented, however, it is desirable to commit the fix without deleting
all of the printf lines. This is also simplifies removal of the printf lines
as once the final fix is committed, 'hg revert' does the rest. It is likely
that the printf lines will be very near the actual fix, so being able to split
the hunk is very useful in this case.
There were two alternatives I considered for the user interface. One was to
manually edit the patch, the other to allow a hunk to be split into individual
lines for consideration. The latter option would require a significant
refactor of the record module and is less flexible. While the former is
potentially more complicated to use, this is a feature that is likely to only
be used in certain exceptional cases (such as the use case proposed above) and
hence I felt that the complexity would not be a considerable issue.
I've also written a follow-up patch that refactors the 'prompt' code to base
everything on the choices variable. This tidies up and clarifies the code a
bit (removes constructs like 'if ret == 7' and removes the 'e' option from the
file scope options as it's not relevant there. It's not really a necessity, so
I've excluded it from this submission for now, but I can send it separately if
there's a desire and it's on bitbucket (see below) in the meantime.
Possible future improvements include:
* Tidying up the 'prompt' code to base everything on the choices variable.
This would allow entries to be removed from the prompt as currently 'e' is
offered even for entire file patches, which is currently unsupported.
* Allowing the entire file (or even multi-file) patch to be edited manually:
this would require quite a large refactor without much benefit, so I decided
to exclude it from the initial submission.
* Allow the option to retry if a patch fails to apply (this is what Git does).
This would require quite a bit of refactoring given the current 'hg record'
implementation, so it's debatable whether it's worth it.
Output is similar to existing record user interface except that an additional
option ('e') exists to allow manual editing of the patch. This opens the
user's configured editor with the patch. A comment is added to the bottom of
the patch explaining what to do (based on Git's one).
A large proportion of the changeset is test-case changes to update the options
reported by record (Ynesfdaq? instead of Ynsfdaq?). Functional changes are in
record.py and there are some new test cases in test-record.t.
2012-03-31 01:08:46 +04:00
|
|
|
e - edit this change manually
|
2007-08-10 04:29:16 +04:00
|
|
|
|
2009-07-17 01:25:26 +04:00
|
|
|
s - skip remaining changes to this file
|
|
|
|
f - record remaining changes to this file
|
2007-08-10 04:29:16 +04:00
|
|
|
|
2009-07-17 01:25:26 +04:00
|
|
|
d - done, skip remaining changes and files
|
|
|
|
a - record all changes to all remaining files
|
|
|
|
q - quit, recording no changes
|
2007-08-10 04:29:16 +04:00
|
|
|
|
2010-05-31 12:13:15 +04:00
|
|
|
? - display help
|
|
|
|
|
|
|
|
This command is not available when committing a merge.'''
|
2007-08-01 03:28:05 +04:00
|
|
|
|
2015-03-12 01:54:11 +03:00
|
|
|
opts["interactive"] = True
|
|
|
|
commands.commit(ui, repo, *pats, **opts)
|
hg qrecord -- like record, but for mq
I'm a former Darcs user, and I've discovered that it is very convenient to
actually perform development using MQ first, and only when the patches are
'ready' move them to project's history in stone.
Usually I work on some topic, temporarily forgetting about any version control,
and just do coding, experimenting, debugging, etc.
After some time, I approach a moment, where my work should actually go to
patches/commits, and here is the problem::
As it is now, there is no way to put part of the changes into one patch,
and another part of the changes into second patch.
This works, but only when changes are touching separate files, and for
semantically different changes touching the same file(s) there is now
pretty way to put them into separate patches.
For some time, I've tolerated the pain to run vim patches/... and move hunks
between files by hand, but I think this affects my productivity badly.
So, here is the first step towards untiing the problem:
Let's use 'hg qrecord' for mq, like we use 'hg record' for usual commits!
2008-01-10 12:07:18 +03:00
|
|
|
|
2011-10-02 00:47:03 +04:00
|
|
|
def qrefresh(origfn, ui, repo, *pats, **opts):
|
|
|
|
if not opts['interactive']:
|
|
|
|
return origfn(ui, repo, *pats, **opts)
|
|
|
|
|
2011-05-24 20:17:19 +04:00
|
|
|
mq = extensions.find('mq')
|
|
|
|
|
|
|
|
def committomq(ui, repo, *pats, **opts):
|
|
|
|
# At this point the working copy contains only changes that
|
|
|
|
# were accepted. All other changes were reverted.
|
|
|
|
# We can't pass *pats here since qrefresh will undo all other
|
|
|
|
# changed files in the patch that aren't in pats.
|
|
|
|
mq.refresh(ui, repo, **opts)
|
|
|
|
|
|
|
|
# backup all changed files
|
2015-03-12 02:39:38 +03:00
|
|
|
cmdutil.dorecord(ui, repo, committomq, 'qrefresh', True,
|
|
|
|
cmdutil.recordfilter, *pats, **opts)
|
hg qrecord -- like record, but for mq
I'm a former Darcs user, and I've discovered that it is very convenient to
actually perform development using MQ first, and only when the patches are
'ready' move them to project's history in stone.
Usually I work on some topic, temporarily forgetting about any version control,
and just do coding, experimenting, debugging, etc.
After some time, I approach a moment, where my work should actually go to
patches/commits, and here is the problem::
As it is now, there is no way to put part of the changes into one patch,
and another part of the changes into second patch.
This works, but only when changes are touching separate files, and for
semantically different changes touching the same file(s) there is now
pretty way to put them into separate patches.
For some time, I've tolerated the pain to run vim patches/... and move hunks
between files by hand, but I think this affects my productivity badly.
So, here is the first step towards untiing the problem:
Let's use 'hg qrecord' for mq, like we use 'hg record' for usual commits!
2008-01-10 12:07:18 +03:00
|
|
|
|
2014-05-05 09:35:37 +04:00
|
|
|
# This command registration is replaced during uisetup().
|
2014-05-05 09:36:07 +04:00
|
|
|
@command('qrecord',
|
|
|
|
[],
|
|
|
|
_('hg qrecord [OPTION]... PATCH [FILE]...'),
|
|
|
|
inferrepo=True)
|
2008-01-23 21:49:39 +03:00
|
|
|
def qrecord(ui, repo, patch, *pats, **opts):
|
|
|
|
'''interactively record a new patch
|
hg qrecord -- like record, but for mq
I'm a former Darcs user, and I've discovered that it is very convenient to
actually perform development using MQ first, and only when the patches are
'ready' move them to project's history in stone.
Usually I work on some topic, temporarily forgetting about any version control,
and just do coding, experimenting, debugging, etc.
After some time, I approach a moment, where my work should actually go to
patches/commits, and here is the problem::
As it is now, there is no way to put part of the changes into one patch,
and another part of the changes into second patch.
This works, but only when changes are touching separate files, and for
semantically different changes touching the same file(s) there is now
pretty way to put them into separate patches.
For some time, I've tolerated the pain to run vim patches/... and move hunks
between files by hand, but I think this affects my productivity badly.
So, here is the first step towards untiing the problem:
Let's use 'hg qrecord' for mq, like we use 'hg record' for usual commits!
2008-01-10 12:07:18 +03:00
|
|
|
|
2010-04-22 12:24:49 +04:00
|
|
|
See :hg:`help qnew` & :hg:`help record` for more information and
|
2009-07-26 04:00:58 +04:00
|
|
|
usage.
|
hg qrecord -- like record, but for mq
I'm a former Darcs user, and I've discovered that it is very convenient to
actually perform development using MQ first, and only when the patches are
'ready' move them to project's history in stone.
Usually I work on some topic, temporarily forgetting about any version control,
and just do coding, experimenting, debugging, etc.
After some time, I approach a moment, where my work should actually go to
patches/commits, and here is the problem::
As it is now, there is no way to put part of the changes into one patch,
and another part of the changes into second patch.
This works, but only when changes are touching separate files, and for
semantically different changes touching the same file(s) there is now
pretty way to put them into separate patches.
For some time, I've tolerated the pain to run vim patches/... and move hunks
between files by hand, but I think this affects my productivity badly.
So, here is the first step towards untiing the problem:
Let's use 'hg qrecord' for mq, like we use 'hg record' for usual commits!
2008-01-10 12:07:18 +03:00
|
|
|
'''
|
|
|
|
|
|
|
|
try:
|
|
|
|
mq = extensions.find('mq')
|
|
|
|
except KeyError:
|
|
|
|
raise util.Abort(_("'mq' extension not loaded"))
|
|
|
|
|
2011-05-24 20:17:02 +04:00
|
|
|
repo.mq.checkpatchname(patch)
|
|
|
|
|
2010-02-05 20:46:22 +03:00
|
|
|
def committomq(ui, repo, *pats, **opts):
|
2011-05-24 20:17:02 +04:00
|
|
|
opts['checkname'] = False
|
2008-01-23 21:49:39 +03:00
|
|
|
mq.new(ui, repo, patch, *pats, **opts)
|
hg qrecord -- like record, but for mq
I'm a former Darcs user, and I've discovered that it is very convenient to
actually perform development using MQ first, and only when the patches are
'ready' move them to project's history in stone.
Usually I work on some topic, temporarily forgetting about any version control,
and just do coding, experimenting, debugging, etc.
After some time, I approach a moment, where my work should actually go to
patches/commits, and here is the problem::
As it is now, there is no way to put part of the changes into one patch,
and another part of the changes into second patch.
This works, but only when changes are touching separate files, and for
semantically different changes touching the same file(s) there is now
pretty way to put them into separate patches.
For some time, I've tolerated the pain to run vim patches/... and move hunks
between files by hand, but I think this affects my productivity badly.
So, here is the first step towards untiing the problem:
Let's use 'hg qrecord' for mq, like we use 'hg record' for usual commits!
2008-01-10 12:07:18 +03:00
|
|
|
|
2015-03-12 02:39:38 +03:00
|
|
|
cmdutil.dorecord(ui, repo, committomq, 'qnew', False,
|
|
|
|
cmdutil.recordfilter, *pats, **opts)
|
record: refactor record into generic record driver
rationale
---------
I'd like to make MQ version of record -- qrecord.
>From the first glance it seemed to be easy -- the task in essence would be to
change call to cmdutil.commit() to something like mq.qrefresh().
As it turned out queue.refresh() and cmdutil.commit() have different semantics
-- cmdutil.commit() first scans for changes and then delegate the actual commit
to lowlevel func. On the other hand queue.refresh() do it all in once, and I am
a bit scary to change it.
Maybe the right way would be to first refactor queue.refresh() to use
cmdutil.commit() machinery, and then trivially adjust record, but I feel I'm
not competent for the task right now.
Instead, I propose we refactor record to be some sort of high-level driver, or
like a high-level decorator one can say, which will first interactively filter
changes, and then delegate commit job to high-level commiter, e.g. 'commit' or
'qrefresh'
So, this patch does just that -- refactor record to be generic driver, and
update 'hg record' code to use the driver.
'hg qrecord' will follow.
2008-01-10 12:07:13 +03:00
|
|
|
|
2011-10-02 00:47:03 +04:00
|
|
|
def qnew(origfn, ui, repo, patch, *args, **opts):
|
|
|
|
if opts['interactive']:
|
|
|
|
return qrecord(ui, repo, patch, *args, **opts)
|
|
|
|
return origfn(ui, repo, patch, *args, **opts)
|
|
|
|
|
2007-08-01 03:28:05 +04:00
|
|
|
|
2009-11-05 03:10:43 +03:00
|
|
|
def uisetup(ui):
|
hg qrecord -- like record, but for mq
I'm a former Darcs user, and I've discovered that it is very convenient to
actually perform development using MQ first, and only when the patches are
'ready' move them to project's history in stone.
Usually I work on some topic, temporarily forgetting about any version control,
and just do coding, experimenting, debugging, etc.
After some time, I approach a moment, where my work should actually go to
patches/commits, and here is the problem::
As it is now, there is no way to put part of the changes into one patch,
and another part of the changes into second patch.
This works, but only when changes are touching separate files, and for
semantically different changes touching the same file(s) there is now
pretty way to put them into separate patches.
For some time, I've tolerated the pain to run vim patches/... and move hunks
between files by hand, but I think this affects my productivity badly.
So, here is the first step towards untiing the problem:
Let's use 'hg qrecord' for mq, like we use 'hg record' for usual commits!
2008-01-10 12:07:18 +03:00
|
|
|
try:
|
|
|
|
mq = extensions.find('mq')
|
|
|
|
except KeyError:
|
|
|
|
return
|
|
|
|
|
2011-05-22 17:10:03 +04:00
|
|
|
cmdtable["qrecord"] = \
|
2011-05-24 20:17:22 +04:00
|
|
|
(qrecord,
|
|
|
|
# same options as qnew, but copy them so we don't get
|
2011-06-10 12:58:10 +04:00
|
|
|
# -i/--interactive for qrecord and add white space diff options
|
2014-01-16 23:57:52 +04:00
|
|
|
mq.cmdtable['^qnew'][1][:] + commands.diffwsopts,
|
2011-05-22 17:10:03 +04:00
|
|
|
_('hg qrecord [OPTION]... PATCH [FILE]...'))
|
2011-05-24 20:17:19 +04:00
|
|
|
|
2011-10-02 00:47:03 +04:00
|
|
|
_wrapcmd('qnew', mq.cmdtable, qnew, _("interactively record a new patch"))
|
2011-05-24 20:17:19 +04:00
|
|
|
_wrapcmd('qrefresh', mq.cmdtable, qrefresh,
|
|
|
|
_("interactively select changes to refresh"))
|
|
|
|
|
|
|
|
def _wrapcmd(cmd, table, wrapfn, msg):
|
2011-10-02 00:47:03 +04:00
|
|
|
entry = extensions.wrapcommand(table, cmd, wrapfn)
|
2011-05-24 20:17:19 +04:00
|
|
|
entry[1].append(('i', 'interactive', None, msg))
|