2006-08-19 08:18:01 +04:00
|
|
|
# cmdutil.py - help for command processing in mercurial
|
2006-08-13 03:13:27 +04:00
|
|
|
#
|
2007-06-19 10:51:34 +04:00
|
|
|
# Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
|
2006-08-13 03:13:27 +04:00
|
|
|
#
|
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.
|
2006-08-13 03:13:27 +04:00
|
|
|
|
2016-02-28 10:57:07 +03:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
import errno
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import tempfile
|
|
|
|
|
|
|
|
from .i18n import _
|
|
|
|
from .node import (
|
|
|
|
bin,
|
|
|
|
hex,
|
|
|
|
nullid,
|
|
|
|
nullrev,
|
|
|
|
short,
|
|
|
|
)
|
|
|
|
|
|
|
|
from . import (
|
|
|
|
bookmarks,
|
|
|
|
changelog,
|
|
|
|
copies,
|
|
|
|
crecord as crecordmod,
|
|
|
|
encoding,
|
|
|
|
error,
|
|
|
|
formatter,
|
|
|
|
graphmod,
|
|
|
|
lock as lockmod,
|
|
|
|
match as matchmod,
|
|
|
|
obsolete,
|
|
|
|
patch,
|
|
|
|
pathutil,
|
|
|
|
phases,
|
|
|
|
repair,
|
|
|
|
revlog,
|
|
|
|
revset,
|
|
|
|
scmutil,
|
|
|
|
templatekw,
|
|
|
|
templater,
|
|
|
|
util,
|
|
|
|
)
|
2016-04-10 23:55:37 +03:00
|
|
|
stringio = util.stringio
|
2006-08-13 03:13:27 +04:00
|
|
|
|
2015-05-22 00:28:02 +03:00
|
|
|
def ishunk(x):
|
|
|
|
hunkclasses = (crecordmod.uihunk, patch.recordhunk)
|
|
|
|
return isinstance(x, hunkclasses)
|
|
|
|
|
2015-05-22 00:32:14 +03:00
|
|
|
def newandmodified(chunks, originalchunks):
|
|
|
|
newlyaddedandmodifiedfiles = set()
|
|
|
|
for chunk in chunks:
|
|
|
|
if ishunk(chunk) and chunk.header.isnewfile() and chunk not in \
|
|
|
|
originalchunks:
|
|
|
|
newlyaddedandmodifiedfiles.add(chunk.header.filename())
|
|
|
|
return newlyaddedandmodifiedfiles
|
|
|
|
|
2010-02-08 12:23:44 +03:00
|
|
|
def parsealiases(cmd):
|
|
|
|
return cmd.lstrip("^").split("|")
|
|
|
|
|
2015-03-17 01:30:33 +03:00
|
|
|
def setupwrapcolorwrite(ui):
|
|
|
|
# wrap ui.write so diff output can be labeled/colorized
|
|
|
|
def wrapwrite(orig, *args, **kw):
|
|
|
|
label = kw.pop('label', '')
|
|
|
|
for chunk, l in patch.difflabel(lambda: args):
|
|
|
|
orig(chunk, label=label + l)
|
|
|
|
|
|
|
|
oldwrite = ui.write
|
|
|
|
def wrap(*args, **kwargs):
|
|
|
|
return wrapwrite(oldwrite, *args, **kwargs)
|
|
|
|
setattr(ui, 'write', wrap)
|
|
|
|
return oldwrite
|
|
|
|
|
2015-05-28 01:49:24 +03:00
|
|
|
def filterchunks(ui, originalhunks, usecurses, testfile, operation=None):
|
2015-03-13 00:24:48 +03:00
|
|
|
if usecurses:
|
|
|
|
if testfile:
|
|
|
|
recordfn = crecordmod.testdecorator(testfile,
|
|
|
|
crecordmod.testchunkselector)
|
|
|
|
else:
|
|
|
|
recordfn = crecordmod.chunkselector
|
|
|
|
|
2015-05-28 01:49:24 +03:00
|
|
|
return crecordmod.filterpatch(ui, originalhunks, recordfn, operation)
|
2015-03-13 00:24:48 +03:00
|
|
|
|
|
|
|
else:
|
2015-05-28 01:49:24 +03:00
|
|
|
return patch.filterpatch(ui, originalhunks, operation)
|
2015-03-12 02:39:38 +03:00
|
|
|
|
2015-05-28 01:49:24 +03:00
|
|
|
def recordfilter(ui, originalhunks, operation=None):
|
|
|
|
""" Prompts the user to filter the originalhunks and return a list of
|
|
|
|
selected hunks.
|
|
|
|
*operation* is used for ui purposes to indicate the user
|
2015-10-17 01:58:46 +03:00
|
|
|
what kind of filtering they are doing: reverting, committing, shelving, etc.
|
2015-05-29 02:41:47 +03:00
|
|
|
*operation* has to be a translated string.
|
2015-05-28 01:49:24 +03:00
|
|
|
"""
|
2015-12-16 03:01:45 +03:00
|
|
|
usecurses = crecordmod.checkcurses(ui)
|
2015-03-17 01:35:50 +03:00
|
|
|
testfile = ui.config('experimental', 'crecordtest', None)
|
2015-03-17 01:37:00 +03:00
|
|
|
oldwrite = setupwrapcolorwrite(ui)
|
|
|
|
try:
|
2015-12-01 03:35:21 +03:00
|
|
|
newchunks, newopts = filterchunks(ui, originalhunks, usecurses,
|
|
|
|
testfile, operation)
|
2015-03-17 01:37:00 +03:00
|
|
|
finally:
|
|
|
|
ui.write = oldwrite
|
2015-12-01 03:35:21 +03:00
|
|
|
return newchunks, newopts
|
2015-03-17 01:35:50 +03:00
|
|
|
|
2015-03-12 02:39:38 +03:00
|
|
|
def dorecord(ui, repo, commitfunc, cmdsuggest, backupall,
|
|
|
|
filterfn, *pats, **opts):
|
2016-02-28 10:57:07 +03:00
|
|
|
from . import merge as mergemod
|
2015-03-11 03:14:33 +03:00
|
|
|
if not ui.interactive():
|
2015-07-14 21:43:16 +03:00
|
|
|
if cmdsuggest:
|
|
|
|
msg = _('running non-interactively, use %s instead') % cmdsuggest
|
|
|
|
else:
|
|
|
|
msg = _('running non-interactively')
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(msg)
|
2015-03-11 03:14:33 +03:00
|
|
|
|
|
|
|
# make sure username is set before going interactive
|
|
|
|
if not opts.get('user'):
|
|
|
|
ui.username() # raise exception, username not provided
|
|
|
|
|
|
|
|
def recordfunc(ui, repo, message, match, opts):
|
|
|
|
"""This is generic record driver.
|
|
|
|
|
|
|
|
Its job is to interactively filter local changes, and
|
|
|
|
accordingly prepare working directory into a state in which the
|
|
|
|
job can be delegated to a non-interactive commit command such as
|
|
|
|
'commit' or 'qrefresh'.
|
|
|
|
|
|
|
|
After the actual job is done by non-interactive command, the
|
|
|
|
working directory is restored to its original state.
|
|
|
|
|
|
|
|
In the end we'll record interesting changes, and everything else
|
|
|
|
will be left in place, so the user can continue working.
|
|
|
|
"""
|
|
|
|
|
|
|
|
checkunfinished(repo, commit=True)
|
2016-04-06 21:19:36 +03:00
|
|
|
wctx = repo[None]
|
|
|
|
merge = len(wctx.parents()) > 1
|
2015-03-11 03:14:33 +03:00
|
|
|
if merge:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('cannot partially commit a merge '
|
2015-03-11 03:14:33 +03:00
|
|
|
'(use "hg commit" instead)'))
|
|
|
|
|
2016-04-06 21:19:36 +03:00
|
|
|
def fail(f, msg):
|
|
|
|
raise error.Abort('%s: %s' % (f, msg))
|
|
|
|
|
|
|
|
force = opts.get('force')
|
|
|
|
if not force:
|
|
|
|
vdirs = []
|
|
|
|
match.explicitdir = vdirs.append
|
|
|
|
match.bad = fail
|
|
|
|
|
2015-03-11 03:14:33 +03:00
|
|
|
status = repo.status(match=match)
|
2016-04-06 21:19:36 +03:00
|
|
|
if not force:
|
|
|
|
repo.checkcommitpatterns(wctx, vdirs, match, status, fail)
|
2015-03-11 03:14:33 +03:00
|
|
|
diffopts = patch.difffeatureopts(ui, opts=opts, whitespace=True)
|
|
|
|
diffopts.nodates = True
|
|
|
|
diffopts.git = True
|
2015-12-17 17:38:22 +03:00
|
|
|
diffopts.showfunc = True
|
2015-12-31 11:16:59 +03:00
|
|
|
originaldiff = patch.diff(repo, changes=status, opts=diffopts)
|
2015-03-13 03:51:37 +03:00
|
|
|
originalchunks = patch.parsepatch(originaldiff)
|
2015-03-11 03:14:33 +03:00
|
|
|
|
2016-03-18 23:14:57 +03:00
|
|
|
# 1. filter patch, since we are intending to apply subset of it
|
2015-03-11 03:14:33 +03:00
|
|
|
try:
|
2015-12-01 03:35:21 +03:00
|
|
|
chunks, newopts = filterfn(ui, originalchunks)
|
2015-06-24 08:20:08 +03:00
|
|
|
except patch.PatchError as err:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('error parsing patch: %s') % err)
|
2015-12-01 03:35:21 +03:00
|
|
|
opts.update(newopts)
|
2015-03-11 03:14:33 +03:00
|
|
|
|
2015-04-24 00:27:26 +03:00
|
|
|
# We need to keep a backup of files that have been newly added and
|
|
|
|
# modified during the recording process because there is a previous
|
|
|
|
# version without the edit in the workdir
|
2015-05-22 00:32:14 +03:00
|
|
|
newlyaddedandmodifiedfiles = newandmodified(chunks, originalchunks)
|
2015-03-11 03:14:33 +03:00
|
|
|
contenders = set()
|
|
|
|
for h in chunks:
|
|
|
|
try:
|
|
|
|
contenders.update(set(h.files()))
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
changed = status.modified + status.added + status.removed
|
|
|
|
newfiles = [f for f in changed if f in contenders]
|
|
|
|
if not newfiles:
|
|
|
|
ui.status(_('no changes to record\n'))
|
|
|
|
return 0
|
|
|
|
|
|
|
|
modified = set(status.modified)
|
|
|
|
|
|
|
|
# 2. backup changed files, so we can restore them in the end
|
|
|
|
|
|
|
|
if backupall:
|
|
|
|
tobackup = changed
|
|
|
|
else:
|
2015-04-24 00:27:26 +03:00
|
|
|
tobackup = [f for f in newfiles if f in modified or f in \
|
|
|
|
newlyaddedandmodifiedfiles]
|
2015-03-11 03:14:33 +03:00
|
|
|
backups = {}
|
|
|
|
if tobackup:
|
|
|
|
backupdir = repo.join('record-backups')
|
|
|
|
try:
|
|
|
|
os.mkdir(backupdir)
|
2015-06-24 08:20:08 +03:00
|
|
|
except OSError as err:
|
2015-03-11 03:14:33 +03:00
|
|
|
if err.errno != errno.EEXIST:
|
|
|
|
raise
|
|
|
|
try:
|
|
|
|
# backup continues
|
|
|
|
for f in tobackup:
|
|
|
|
fd, tmpname = tempfile.mkstemp(prefix=f.replace('/', '_')+'.',
|
|
|
|
dir=backupdir)
|
|
|
|
os.close(fd)
|
|
|
|
ui.debug('backup %r as %r\n' % (f, tmpname))
|
2015-12-12 21:58:05 +03:00
|
|
|
util.copyfile(repo.wjoin(f), tmpname, copystat=True)
|
2015-03-11 03:14:33 +03:00
|
|
|
backups[f] = tmpname
|
|
|
|
|
2016-04-10 23:55:37 +03:00
|
|
|
fp = stringio()
|
2015-03-11 03:14:33 +03:00
|
|
|
for c in chunks:
|
|
|
|
fname = c.filename()
|
2015-04-22 23:56:30 +03:00
|
|
|
if fname in backups:
|
2015-03-11 03:14:33 +03:00
|
|
|
c.write(fp)
|
|
|
|
dopatch = fp.tell()
|
|
|
|
fp.seek(0)
|
|
|
|
|
2016-03-21 04:08:17 +03:00
|
|
|
# 2.5 optionally review / modify patch in text editor
|
|
|
|
if opts.get('review', False):
|
|
|
|
patchtext = (crecordmod.diffhelptext
|
|
|
|
+ crecordmod.patchhelptext
|
|
|
|
+ fp.read())
|
|
|
|
reviewedpatch = ui.edit(patchtext, "",
|
|
|
|
extra={"suffix": ".diff"})
|
|
|
|
fp.truncate(0)
|
|
|
|
fp.write(reviewedpatch)
|
|
|
|
fp.seek(0)
|
|
|
|
|
2015-04-28 00:02:49 +03:00
|
|
|
[os.unlink(repo.wjoin(c)) for c in newlyaddedandmodifiedfiles]
|
2015-03-11 03:14:33 +03:00
|
|
|
# 3a. apply filtered patch to clean repo (clean)
|
|
|
|
if backups:
|
|
|
|
# Equivalent to hg.revert
|
2015-12-15 02:54:03 +03:00
|
|
|
m = scmutil.matchfiles(repo, backups.keys())
|
2015-03-11 03:14:33 +03:00
|
|
|
mergemod.update(repo, repo.dirstate.p1(),
|
2015-12-15 02:54:03 +03:00
|
|
|
False, True, matcher=m)
|
2015-03-11 03:14:33 +03:00
|
|
|
|
|
|
|
# 3b. (apply)
|
|
|
|
if dopatch:
|
|
|
|
try:
|
|
|
|
ui.debug('applying patch\n')
|
|
|
|
ui.debug(fp.getvalue())
|
|
|
|
patch.internalpatch(ui, repo, fp, 1, eolmode=None)
|
2015-06-24 08:20:08 +03:00
|
|
|
except patch.PatchError as err:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(str(err))
|
2015-03-11 03:14:33 +03:00
|
|
|
del fp
|
|
|
|
|
|
|
|
# 4. We prepared working directory according to filtered
|
|
|
|
# patch. Now is the time to delegate the job to
|
|
|
|
# commit/qrefresh or the like!
|
|
|
|
|
|
|
|
# Make all of the pathnames absolute.
|
|
|
|
newfiles = [repo.wjoin(nf) for nf in newfiles]
|
2015-03-26 01:51:57 +03:00
|
|
|
return commitfunc(ui, repo, *newfiles, **opts)
|
2015-03-11 03:14:33 +03:00
|
|
|
finally:
|
|
|
|
# 5. finally restore backed-up files
|
|
|
|
try:
|
cmdutil: apply dirstate.normallookup on (maybe partially) committed files
To detect change of a file without redundant comparison of file
content, dirstate recognizes a file as certainly clean, if:
(1) it is already known as "normal",
(2) dirstate entry for it has valid (= not "-1") timestamp, and
(3) mode, size and timestamp of it on the filesystem are as same as
ones expected in dirstate
This works as expected in many cases, but doesn't in the corner case
that changing a file keeps mode, size and timestamp of it on the
filesystem.
The timetable below shows steps in one of typical such situations:
---- ----------------------------------- ----------------
timestamp of "f"
----------------
dirstate file-
time action mem file system
---- ----------------------------------- ---- ----- -----
N *** ***
- change "f" N
- execute 'hg commit -i'
- backup "f" with timestamp N
- revert "f" by 'merge.update()' N
with 'partially'
- apply selected hunks N
by 'patch.patch()'
- 'repo.commit()'
- 'dirstate.normal("f")' N
N+1
- 'dirstate.write()' N N
- restore "f" N+1
- restore timestamp of "f" N
- 'hg status' shows "f" as "clean" N N N
---- ----------------------------------- ---- ----- -----
The most important point is that 'dirstate.write()' is executed at N+1
or later. This causes writing dirstate timestamp N of "f" out
successfully. If it is executed at N, 'parsers.pack_dirstate()'
replaces timestamp N with "-1" before actual writing dirstate out.
This issue can occur when 'hg commit -i' satisfies conditions below:
- the file is committed partially, and
- mode and size of the file aren't changed before and after committing
The root cause of this issue is that (maybe partially changed) files
are restored with original timestamp but dirstate isn't updated for
them.
To detect changes of files correctly, this patch applies
'dirstate.normallookup()' on restored files. Status check is needed
before 'dirstate.normallookup()', because status other than "n(ormal)"
should be kept at failure of committing.
This patch doesn't examine whether each files are committed fully or
partially, because interactive hunk selection makes it difficult.
After this change, timetable is changed as below:
---- ----------------------------------- ----------------
timestamp of "f"
----------------
dirstate file-
time action mem file system
---- ----------------------------------- ---- ----- -----
N *** ***
- change "f" N
- execute 'hg commit -i'
- backup "f" with timestamp N
- revert "f" by 'merge.update()' N
with 'partially'
- apply selected hunks N
by 'patch.internalpatch()'
- 'repo.commit()'
- 'dirstate.normal("f")' N
N+1
- 'dirstate.write()' N N
- restore "f" N+1
- restore timestamp of "f" N
----------------------------------- ---- ----- -----
- normallookup("f") -1
- release wlock
- 'dirstate.write()' -1 -1 N
----------------------------------- ---- ----- -----
- 'hg status' shows "f" as "clean" -1 -1 N
---- ----------------------------------- ---- ----- -----
To reproduce this issue in tests certainly, this patch emulates some
timing critical actions as below:
- change "f" at N
'touch -t 200001010000' before command invocation changes mtime of
"f" to "2000-01-01 00:00" (= N).
- apply selected hunks at N
'patch.internalpatch()' with 'fakepatchtime.py' explicitly changes
mtime of patched files to "2000-01-01 00:00" (= N).
- 'dirstate.write()' at N+1 (or "not at N")
'pack_dirstate()' uses actual timestamp at runtime as "now", and
it should be different from the "2000-01-01 00:00" of "f".
BTW, in 'test-commit-interactive.t', files are sometimes treated as
modified , even though they are just committed fully via 'hg commit
-i' and 'hg diff' shows nothing for them.
Enabling win32text causes EOL style mismatching below:
- files are changed in LF style EOL
=> files restored after committing uses LF style EOL (1)
- 'merge.update()' reverts files in CRLF style EOL
- 'patch.internalpatch()' changes files in CRLF style EOL
=> 'dirstate.normal()' via 'repo.commit()' uses the size of files
in CRLF style EOL (2)
Therefore, fully committed files are treated as "modified", because
'lstat()' returns size of (1) restored files in LF style EOL, but
dirstate expects size of (2) committed files in CRLF style EOL.
After this patch, 'dirstate.normallookup()' on committed files forces
subsequent 'hg status' to examine changes exactly, and fully committed
files are treated as clean as expected.
This is reason why this patch also does:
- add some 'hg status' checking status of fully committed files
- clear win32text configuration before size/timestamp sensitive examination
2015-07-08 11:07:45 +03:00
|
|
|
dirstate = repo.dirstate
|
2015-03-11 03:14:33 +03:00
|
|
|
for realname, tmpname in backups.iteritems():
|
|
|
|
ui.debug('restoring %r to %r\n' % (tmpname, realname))
|
cmdutil: apply dirstate.normallookup on (maybe partially) committed files
To detect change of a file without redundant comparison of file
content, dirstate recognizes a file as certainly clean, if:
(1) it is already known as "normal",
(2) dirstate entry for it has valid (= not "-1") timestamp, and
(3) mode, size and timestamp of it on the filesystem are as same as
ones expected in dirstate
This works as expected in many cases, but doesn't in the corner case
that changing a file keeps mode, size and timestamp of it on the
filesystem.
The timetable below shows steps in one of typical such situations:
---- ----------------------------------- ----------------
timestamp of "f"
----------------
dirstate file-
time action mem file system
---- ----------------------------------- ---- ----- -----
N *** ***
- change "f" N
- execute 'hg commit -i'
- backup "f" with timestamp N
- revert "f" by 'merge.update()' N
with 'partially'
- apply selected hunks N
by 'patch.patch()'
- 'repo.commit()'
- 'dirstate.normal("f")' N
N+1
- 'dirstate.write()' N N
- restore "f" N+1
- restore timestamp of "f" N
- 'hg status' shows "f" as "clean" N N N
---- ----------------------------------- ---- ----- -----
The most important point is that 'dirstate.write()' is executed at N+1
or later. This causes writing dirstate timestamp N of "f" out
successfully. If it is executed at N, 'parsers.pack_dirstate()'
replaces timestamp N with "-1" before actual writing dirstate out.
This issue can occur when 'hg commit -i' satisfies conditions below:
- the file is committed partially, and
- mode and size of the file aren't changed before and after committing
The root cause of this issue is that (maybe partially changed) files
are restored with original timestamp but dirstate isn't updated for
them.
To detect changes of files correctly, this patch applies
'dirstate.normallookup()' on restored files. Status check is needed
before 'dirstate.normallookup()', because status other than "n(ormal)"
should be kept at failure of committing.
This patch doesn't examine whether each files are committed fully or
partially, because interactive hunk selection makes it difficult.
After this change, timetable is changed as below:
---- ----------------------------------- ----------------
timestamp of "f"
----------------
dirstate file-
time action mem file system
---- ----------------------------------- ---- ----- -----
N *** ***
- change "f" N
- execute 'hg commit -i'
- backup "f" with timestamp N
- revert "f" by 'merge.update()' N
with 'partially'
- apply selected hunks N
by 'patch.internalpatch()'
- 'repo.commit()'
- 'dirstate.normal("f")' N
N+1
- 'dirstate.write()' N N
- restore "f" N+1
- restore timestamp of "f" N
----------------------------------- ---- ----- -----
- normallookup("f") -1
- release wlock
- 'dirstate.write()' -1 -1 N
----------------------------------- ---- ----- -----
- 'hg status' shows "f" as "clean" -1 -1 N
---- ----------------------------------- ---- ----- -----
To reproduce this issue in tests certainly, this patch emulates some
timing critical actions as below:
- change "f" at N
'touch -t 200001010000' before command invocation changes mtime of
"f" to "2000-01-01 00:00" (= N).
- apply selected hunks at N
'patch.internalpatch()' with 'fakepatchtime.py' explicitly changes
mtime of patched files to "2000-01-01 00:00" (= N).
- 'dirstate.write()' at N+1 (or "not at N")
'pack_dirstate()' uses actual timestamp at runtime as "now", and
it should be different from the "2000-01-01 00:00" of "f".
BTW, in 'test-commit-interactive.t', files are sometimes treated as
modified , even though they are just committed fully via 'hg commit
-i' and 'hg diff' shows nothing for them.
Enabling win32text causes EOL style mismatching below:
- files are changed in LF style EOL
=> files restored after committing uses LF style EOL (1)
- 'merge.update()' reverts files in CRLF style EOL
- 'patch.internalpatch()' changes files in CRLF style EOL
=> 'dirstate.normal()' via 'repo.commit()' uses the size of files
in CRLF style EOL (2)
Therefore, fully committed files are treated as "modified", because
'lstat()' returns size of (1) restored files in LF style EOL, but
dirstate expects size of (2) committed files in CRLF style EOL.
After this patch, 'dirstate.normallookup()' on committed files forces
subsequent 'hg status' to examine changes exactly, and fully committed
files are treated as clean as expected.
This is reason why this patch also does:
- add some 'hg status' checking status of fully committed files
- clear win32text configuration before size/timestamp sensitive examination
2015-07-08 11:07:45 +03:00
|
|
|
|
|
|
|
if dirstate[realname] == 'n':
|
|
|
|
# without normallookup, restoring timestamp
|
|
|
|
# may cause partially committed files
|
|
|
|
# to be treated as unmodified
|
|
|
|
dirstate.normallookup(realname)
|
|
|
|
|
2015-12-12 21:58:05 +03:00
|
|
|
# copystat=True here and above are a hack to trick any
|
|
|
|
# editors that have f open that we haven't modified them.
|
2015-03-11 03:14:33 +03:00
|
|
|
#
|
2015-12-12 21:58:05 +03:00
|
|
|
# Also note that this racy as an editor could notice the
|
|
|
|
# file's mtime before we've finished writing it.
|
|
|
|
util.copyfile(tmpname, repo.wjoin(realname), copystat=True)
|
2015-03-11 03:14:33 +03:00
|
|
|
os.unlink(tmpname)
|
|
|
|
if tobackup:
|
|
|
|
os.rmdir(backupdir)
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
2015-07-08 11:01:09 +03:00
|
|
|
def recordinwlock(ui, repo, message, match, opts):
|
2016-01-16 00:14:45 +03:00
|
|
|
with repo.wlock():
|
2015-07-08 11:01:09 +03:00
|
|
|
return recordfunc(ui, repo, message, match, opts)
|
|
|
|
|
|
|
|
return commit(ui, repo, recordinwlock, pats, opts)
|
2015-03-11 03:14:33 +03:00
|
|
|
|
2008-10-23 02:34:08 +04:00
|
|
|
def findpossible(cmd, table, strict=False):
|
2007-06-12 06:09:24 +04:00
|
|
|
"""
|
|
|
|
Return cmd -> (aliases, command table entry)
|
|
|
|
for each matching command.
|
|
|
|
Return debug commands (or their aliases) only if no normal command matches.
|
|
|
|
"""
|
|
|
|
choice = {}
|
|
|
|
debugchoice = {}
|
2011-12-02 01:51:36 +04:00
|
|
|
|
|
|
|
if cmd in table:
|
|
|
|
# short-circuit exact matches, "log" alias beats "^log|history"
|
|
|
|
keys = [cmd]
|
|
|
|
else:
|
|
|
|
keys = table.keys()
|
|
|
|
|
2015-02-10 23:59:12 +03:00
|
|
|
allcmds = []
|
2011-12-02 01:51:36 +04:00
|
|
|
for e in keys:
|
2010-02-08 12:23:44 +03:00
|
|
|
aliases = parsealiases(e)
|
2015-02-10 23:59:12 +03:00
|
|
|
allcmds.extend(aliases)
|
2007-06-12 06:09:24 +04:00
|
|
|
found = None
|
|
|
|
if cmd in aliases:
|
|
|
|
found = cmd
|
2008-10-23 02:34:08 +04:00
|
|
|
elif not strict:
|
2007-06-12 06:09:24 +04:00
|
|
|
for a in aliases:
|
|
|
|
if a.startswith(cmd):
|
|
|
|
found = a
|
|
|
|
break
|
|
|
|
if found is not None:
|
|
|
|
if aliases[0].startswith("debug") or found.startswith("debug"):
|
2007-08-16 01:55:13 +04:00
|
|
|
debugchoice[found] = (aliases, table[e])
|
2007-06-12 06:09:24 +04:00
|
|
|
else:
|
2007-08-16 01:55:13 +04:00
|
|
|
choice[found] = (aliases, table[e])
|
2007-06-12 06:09:24 +04:00
|
|
|
|
|
|
|
if not choice and debugchoice:
|
|
|
|
choice = debugchoice
|
|
|
|
|
2015-02-10 23:59:12 +03:00
|
|
|
return choice, allcmds
|
2007-06-12 06:09:24 +04:00
|
|
|
|
2008-10-23 02:34:08 +04:00
|
|
|
def findcmd(cmd, table, strict=True):
|
2007-06-12 06:09:24 +04:00
|
|
|
"""Return (aliases, command table entry) for command string."""
|
2015-02-10 23:59:12 +03:00
|
|
|
choice, allcmds = findpossible(cmd, table, strict)
|
2007-06-12 06:09:24 +04:00
|
|
|
|
2008-01-20 16:39:25 +03:00
|
|
|
if cmd in choice:
|
2007-06-12 06:09:24 +04:00
|
|
|
return choice[cmd]
|
|
|
|
|
|
|
|
if len(choice) > 1:
|
|
|
|
clist = choice.keys()
|
|
|
|
clist.sort()
|
2009-01-12 20:39:38 +03:00
|
|
|
raise error.AmbiguousCommand(cmd, clist)
|
2007-06-12 06:09:24 +04:00
|
|
|
|
|
|
|
if choice:
|
|
|
|
return choice.values()[0]
|
|
|
|
|
2015-02-10 23:59:12 +03:00
|
|
|
raise error.UnknownCommand(cmd, allcmds)
|
2007-06-12 06:09:24 +04:00
|
|
|
|
2010-02-08 12:50:00 +03:00
|
|
|
def findrepo(p):
|
|
|
|
while not os.path.isdir(os.path.join(p, ".hg")):
|
|
|
|
oldp, p = p, os.path.dirname(p)
|
|
|
|
if p == oldp:
|
|
|
|
return None
|
|
|
|
|
|
|
|
return p
|
|
|
|
|
2015-03-25 07:55:35 +03:00
|
|
|
def bailifchanged(repo, merge=True):
|
|
|
|
if merge and repo.dirstate.p2() != nullid:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('outstanding uncommitted merge'))
|
2007-06-12 06:09:24 +04:00
|
|
|
modified, added, removed, deleted = repo.status()[:4]
|
|
|
|
if modified or added or removed or deleted:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('uncommitted changes'))
|
2011-10-12 05:18:15 +04:00
|
|
|
ctx = repo[None]
|
2012-12-12 05:38:14 +04:00
|
|
|
for s in sorted(ctx.substate):
|
2015-03-25 07:55:35 +03:00
|
|
|
ctx.sub(s).bailifchanged()
|
2007-06-12 06:09:24 +04:00
|
|
|
|
2011-06-08 15:54:52 +04:00
|
|
|
def logmessage(ui, opts):
|
2007-06-12 06:09:24 +04:00
|
|
|
""" get the log message according to -m and -l option """
|
2009-01-19 13:38:54 +03:00
|
|
|
message = opts.get('message')
|
|
|
|
logfile = opts.get('logfile')
|
2007-06-12 06:09:24 +04:00
|
|
|
|
|
|
|
if message and logfile:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('options --message and --logfile are mutually '
|
2007-06-12 06:09:24 +04:00
|
|
|
'exclusive'))
|
|
|
|
if not message and logfile:
|
|
|
|
try:
|
|
|
|
if logfile == '-':
|
2011-06-08 15:54:52 +04:00
|
|
|
message = ui.fin.read()
|
2007-06-12 06:09:24 +04:00
|
|
|
else:
|
2011-05-07 23:12:33 +04:00
|
|
|
message = '\n'.join(util.readfile(logfile).splitlines())
|
2015-06-24 08:20:08 +03:00
|
|
|
except IOError as inst:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_("can't read commit message '%s': %s") %
|
2007-06-12 06:09:24 +04:00
|
|
|
(logfile, inst.strerror))
|
|
|
|
return message
|
|
|
|
|
2015-01-18 04:38:57 +03:00
|
|
|
def mergeeditform(ctxorbool, baseformname):
|
|
|
|
"""return appropriate editform name (referencing a committemplate)
|
2014-08-16 05:43:59 +04:00
|
|
|
|
2015-01-18 04:38:57 +03:00
|
|
|
'ctxorbool' is either a ctx to be committed, or a bool indicating whether
|
2014-08-16 05:43:59 +04:00
|
|
|
merging is committed.
|
|
|
|
|
2015-01-18 04:38:57 +03:00
|
|
|
This returns baseformname with '.merge' appended if it is a merge,
|
|
|
|
otherwise '.normal' is appended.
|
2014-08-16 05:43:59 +04:00
|
|
|
"""
|
|
|
|
if isinstance(ctxorbool, bool):
|
|
|
|
if ctxorbool:
|
2015-01-18 04:38:57 +03:00
|
|
|
return baseformname + ".merge"
|
2014-08-16 05:43:59 +04:00
|
|
|
elif 1 < len(ctxorbool.parents()):
|
2015-01-18 04:38:57 +03:00
|
|
|
return baseformname + ".merge"
|
2014-08-16 05:43:59 +04:00
|
|
|
|
2015-01-18 04:38:57 +03:00
|
|
|
return baseformname + ".normal"
|
2014-08-16 05:43:59 +04:00
|
|
|
|
2014-08-02 16:46:26 +04:00
|
|
|
def getcommiteditor(edit=False, finishdesc=None, extramsg=None,
|
|
|
|
editform='', **opts):
|
2014-05-10 19:49:36 +04:00
|
|
|
"""get appropriate commit message editor according to '--edit' option
|
|
|
|
|
|
|
|
'finishdesc' is a function to be called with edited commit message
|
|
|
|
(= 'description' of the new changeset) just after editing, but
|
|
|
|
before checking empty-ness. It should return actual text to be
|
|
|
|
stored into history. This allows to change description before
|
|
|
|
storing.
|
|
|
|
|
|
|
|
'extramsg' is a extra message to be shown in the editor instead of
|
|
|
|
'Leave message empty to abort commit' line. 'HG: ' prefix and EOL
|
|
|
|
is automatically added.
|
|
|
|
|
2014-08-02 16:46:26 +04:00
|
|
|
'editform' is a dot-separated list of names, to distinguish
|
|
|
|
the purpose of commit text editing.
|
|
|
|
|
2014-05-10 19:49:36 +04:00
|
|
|
'getcommiteditor' returns 'commitforceeditor' regardless of
|
|
|
|
'edit', if one of 'finishdesc' or 'extramsg' is specified, because
|
|
|
|
they are specific for usage in MQ.
|
|
|
|
"""
|
|
|
|
if edit or finishdesc or extramsg:
|
|
|
|
return lambda r, c, s: commitforceeditor(r, c, s,
|
|
|
|
finishdesc=finishdesc,
|
2014-08-02 16:46:26 +04:00
|
|
|
extramsg=extramsg,
|
|
|
|
editform=editform)
|
|
|
|
elif editform:
|
|
|
|
return lambda r, c, s: commiteditor(r, c, s, editform=editform)
|
2014-05-10 19:49:35 +04:00
|
|
|
else:
|
|
|
|
return commiteditor
|
|
|
|
|
2008-02-29 03:51:23 +03:00
|
|
|
def loglimit(opts):
|
|
|
|
"""get the log limit according to option -l/--limit"""
|
|
|
|
limit = opts.get('limit')
|
|
|
|
if limit:
|
|
|
|
try:
|
|
|
|
limit = int(limit)
|
|
|
|
except ValueError:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('limit must be a positive integer'))
|
2010-01-25 09:05:27 +03:00
|
|
|
if limit <= 0:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('limit must be positive'))
|
2008-02-29 03:51:23 +03:00
|
|
|
else:
|
2009-12-13 18:32:29 +03:00
|
|
|
limit = None
|
2008-02-29 03:51:23 +03:00
|
|
|
return limit
|
|
|
|
|
2011-07-30 14:08:45 +04:00
|
|
|
def makefilename(repo, pat, node, desc=None,
|
2006-08-13 03:13:27 +04:00
|
|
|
total=None, seqno=None, revwidth=None, pathname=None):
|
|
|
|
node_expander = {
|
|
|
|
'H': lambda: hex(node),
|
|
|
|
'R': lambda: str(repo.changelog.rev(node)),
|
|
|
|
'h': lambda: short(node),
|
2011-07-30 14:08:45 +04:00
|
|
|
'm': lambda: re.sub('[^\w]', '_', str(desc))
|
2006-08-13 03:13:27 +04:00
|
|
|
}
|
|
|
|
expander = {
|
|
|
|
'%': lambda: '%',
|
|
|
|
'b': lambda: os.path.basename(repo.root),
|
|
|
|
}
|
|
|
|
|
|
|
|
try:
|
|
|
|
if node:
|
|
|
|
expander.update(node_expander)
|
2007-07-12 02:56:16 +04:00
|
|
|
if node:
|
2006-08-13 03:13:27 +04:00
|
|
|
expander['r'] = (lambda:
|
2007-07-12 02:56:16 +04:00
|
|
|
str(repo.changelog.rev(node)).zfill(revwidth or 0))
|
2006-08-13 03:13:27 +04:00
|
|
|
if total is not None:
|
|
|
|
expander['N'] = lambda: str(total)
|
|
|
|
if seqno is not None:
|
|
|
|
expander['n'] = lambda: str(seqno)
|
|
|
|
if total is not None and seqno is not None:
|
2006-11-17 10:06:54 +03:00
|
|
|
expander['n'] = lambda: str(seqno).zfill(len(str(total)))
|
2006-08-13 03:13:27 +04:00
|
|
|
if pathname is not None:
|
|
|
|
expander['s'] = lambda: os.path.basename(pathname)
|
|
|
|
expander['d'] = lambda: os.path.dirname(pathname) or '.'
|
|
|
|
expander['p'] = lambda: pathname
|
|
|
|
|
|
|
|
newname = []
|
|
|
|
patlen = len(pat)
|
|
|
|
i = 0
|
|
|
|
while i < patlen:
|
|
|
|
c = pat[i]
|
|
|
|
if c == '%':
|
|
|
|
i += 1
|
|
|
|
c = pat[i]
|
|
|
|
c = expander[c]()
|
|
|
|
newname.append(c)
|
|
|
|
i += 1
|
|
|
|
return ''.join(newname)
|
2015-06-24 08:20:08 +03:00
|
|
|
except KeyError as inst:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_("invalid format spec '%%%s' in output filename") %
|
2006-09-08 11:36:18 +04:00
|
|
|
inst.args[0])
|
2006-08-13 03:13:27 +04:00
|
|
|
|
2015-12-13 14:01:11 +03:00
|
|
|
class _unclosablefile(object):
|
|
|
|
def __init__(self, fp):
|
|
|
|
self._fp = fp
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
return iter(self._fp)
|
|
|
|
|
|
|
|
def __getattr__(self, attr):
|
|
|
|
return getattr(self._fp, attr)
|
|
|
|
|
2011-07-30 14:08:45 +04:00
|
|
|
def makefileobj(repo, pat, node=None, desc=None, total=None,
|
2013-10-22 18:38:58 +04:00
|
|
|
seqno=None, revwidth=None, mode='wb', modemap=None,
|
2013-02-10 01:38:57 +04:00
|
|
|
pathname=None):
|
2008-11-06 13:17:38 +03:00
|
|
|
|
2011-02-24 01:30:48 +03:00
|
|
|
writable = mode not in ('r', 'rb')
|
2008-11-06 13:17:38 +03:00
|
|
|
|
2006-08-13 03:13:27 +04:00
|
|
|
if not pat or pat == '-':
|
2015-03-14 00:00:06 +03:00
|
|
|
if writable:
|
|
|
|
fp = repo.ui.fout
|
|
|
|
else:
|
|
|
|
fp = repo.ui.fin
|
2015-12-13 14:07:19 +03:00
|
|
|
return _unclosablefile(fp)
|
2011-07-26 00:32:42 +04:00
|
|
|
if util.safehasattr(pat, 'write') and writable:
|
2006-08-13 03:13:27 +04:00
|
|
|
return pat
|
2011-07-26 00:32:42 +04:00
|
|
|
if util.safehasattr(pat, 'read') and 'r' in mode:
|
2006-08-13 03:13:27 +04:00
|
|
|
return pat
|
2013-02-10 01:38:57 +04:00
|
|
|
fn = makefilename(repo, pat, node, desc, total, seqno, revwidth, pathname)
|
2013-10-22 18:38:58 +04:00
|
|
|
if modemap is not None:
|
|
|
|
mode = modemap.get(fn, mode)
|
|
|
|
if mode == 'wb':
|
|
|
|
modemap[fn] = 'ab'
|
2013-02-10 01:38:57 +04:00
|
|
|
return open(fn, mode)
|
2006-08-14 03:11:22 +04:00
|
|
|
|
2011-05-14 02:30:32 +04:00
|
|
|
def openrevlog(repo, cmd, file_, opts):
|
|
|
|
"""opens the changelog, manifest, a filelog or a given revlog"""
|
|
|
|
cl = opts['changelog']
|
|
|
|
mf = opts['manifest']
|
2015-04-13 09:51:06 +03:00
|
|
|
dir = opts['dir']
|
2011-05-14 02:30:32 +04:00
|
|
|
msg = None
|
|
|
|
if cl and mf:
|
|
|
|
msg = _('cannot specify --changelog and --manifest at the same time')
|
2015-04-13 09:51:06 +03:00
|
|
|
elif cl and dir:
|
|
|
|
msg = _('cannot specify --changelog and --dir at the same time')
|
2011-05-14 02:30:32 +04:00
|
|
|
elif cl or mf:
|
|
|
|
if file_:
|
|
|
|
msg = _('cannot specify filename with --changelog or --manifest')
|
|
|
|
elif not repo:
|
2015-04-13 09:51:06 +03:00
|
|
|
msg = _('cannot specify --changelog or --manifest or --dir '
|
2011-05-14 02:30:32 +04:00
|
|
|
'without a repository')
|
|
|
|
if msg:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(msg)
|
2011-05-14 02:30:32 +04:00
|
|
|
|
|
|
|
r = None
|
|
|
|
if repo:
|
|
|
|
if cl:
|
2014-04-15 07:27:31 +04:00
|
|
|
r = repo.unfiltered().changelog
|
2015-04-13 09:51:06 +03:00
|
|
|
elif dir:
|
|
|
|
if 'treemanifest' not in repo.requirements:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_("--dir can only be used on repos with "
|
2015-04-13 09:51:06 +03:00
|
|
|
"treemanifest enabled"))
|
|
|
|
dirlog = repo.dirlog(file_)
|
|
|
|
if len(dirlog):
|
|
|
|
r = dirlog
|
2011-05-14 02:30:32 +04:00
|
|
|
elif mf:
|
|
|
|
r = repo.manifest
|
|
|
|
elif file_:
|
|
|
|
filelog = repo.file(file_)
|
|
|
|
if len(filelog):
|
|
|
|
r = filelog
|
|
|
|
if not r:
|
|
|
|
if not file_:
|
|
|
|
raise error.CommandError(cmd, _('invalid arguments'))
|
|
|
|
if not os.path.isfile(file_):
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_("revlog '%s' not found") % file_)
|
2011-05-14 02:30:32 +04:00
|
|
|
r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False),
|
|
|
|
file_[:-2] + ".i")
|
|
|
|
return r
|
|
|
|
|
2007-12-07 11:29:55 +03:00
|
|
|
def copy(ui, repo, pats, opts, rename=False):
|
2007-12-03 03:11:59 +03:00
|
|
|
# called with the repo lock held
|
|
|
|
#
|
|
|
|
# hgsep => pathname that uses "/" to separate directories
|
|
|
|
# ossep => pathname that uses os.sep to separate directories
|
|
|
|
cwd = repo.getcwd()
|
|
|
|
targets = {}
|
2007-12-07 11:01:10 +03:00
|
|
|
after = opts.get("after")
|
|
|
|
dryrun = opts.get("dry_run")
|
2010-06-07 22:03:32 +04:00
|
|
|
wctx = repo[None]
|
2007-12-03 03:11:59 +03:00
|
|
|
|
2007-12-06 23:58:57 +03:00
|
|
|
def walkpat(pat):
|
|
|
|
srcs = []
|
2015-03-14 00:00:06 +03:00
|
|
|
if after:
|
|
|
|
badstates = '?'
|
|
|
|
else:
|
|
|
|
badstates = '?r'
|
2011-06-19 01:52:51 +04:00
|
|
|
m = scmutil.match(repo[None], [pat], opts, globbed=True)
|
2008-05-12 20:37:08 +04:00
|
|
|
for abs in repo.walk(m):
|
2007-12-06 23:58:57 +03:00
|
|
|
state = repo.dirstate[abs]
|
2008-05-12 20:37:08 +04:00
|
|
|
rel = m.rel(abs)
|
|
|
|
exact = m.exact(abs)
|
2010-05-26 18:16:47 +04:00
|
|
|
if state in badstates:
|
2007-12-06 23:58:57 +03:00
|
|
|
if exact and state == '?':
|
|
|
|
ui.warn(_('%s: not copying - file is not managed\n') % rel)
|
|
|
|
if exact and state == 'r':
|
|
|
|
ui.warn(_('%s: not copying - file has been marked for'
|
|
|
|
' remove\n') % rel)
|
|
|
|
continue
|
|
|
|
# abs: hgsep
|
|
|
|
# rel: ossep
|
|
|
|
srcs.append((abs, rel, exact))
|
|
|
|
return srcs
|
2007-12-03 03:11:59 +03:00
|
|
|
|
|
|
|
# abssrc: hgsep
|
|
|
|
# relsrc: ossep
|
|
|
|
# otarget: ossep
|
2007-12-06 23:58:57 +03:00
|
|
|
def copyfile(abssrc, relsrc, otarget, exact):
|
2013-11-07 03:19:04 +04:00
|
|
|
abstarget = pathutil.canonpath(repo.root, cwd, otarget)
|
2012-04-28 22:29:21 +04:00
|
|
|
if '/' in abstarget:
|
|
|
|
# We cannot normalize abstarget itself, this would prevent
|
|
|
|
# case only renames, like a => A.
|
|
|
|
abspath, absname = abstarget.rsplit('/', 1)
|
|
|
|
abstarget = repo.dirstate.normalize(abspath) + '/' + absname
|
2007-12-03 03:11:59 +03:00
|
|
|
reltarget = repo.pathto(abstarget, cwd)
|
|
|
|
target = repo.wjoin(abstarget)
|
2007-12-07 11:01:10 +03:00
|
|
|
src = repo.wjoin(abssrc)
|
2007-12-07 11:01:13 +03:00
|
|
|
state = repo.dirstate[abstarget]
|
2007-12-07 11:01:10 +03:00
|
|
|
|
2011-04-19 14:42:53 +04:00
|
|
|
scmutil.checkportable(ui, abstarget)
|
2011-04-15 18:15:32 +04:00
|
|
|
|
2007-12-07 11:01:10 +03:00
|
|
|
# check for collisions
|
|
|
|
prevsrc = targets.get(abstarget)
|
2007-12-03 03:11:59 +03:00
|
|
|
if prevsrc is not None:
|
|
|
|
ui.warn(_('%s: not overwriting - %s collides with %s\n') %
|
|
|
|
(reltarget, repo.pathto(abssrc, cwd),
|
|
|
|
repo.pathto(prevsrc, cwd)))
|
|
|
|
return
|
2007-12-07 11:01:10 +03:00
|
|
|
|
|
|
|
# check for overwrites
|
2010-09-20 23:46:39 +04:00
|
|
|
exists = os.path.lexists(target)
|
2012-03-23 20:47:27 +04:00
|
|
|
samefile = False
|
|
|
|
if exists and abssrc != abstarget:
|
|
|
|
if (repo.dirstate.normalize(abssrc) ==
|
|
|
|
repo.dirstate.normalize(abstarget)):
|
|
|
|
if not rename:
|
|
|
|
ui.warn(_("%s: can't copy - same file\n") % reltarget)
|
|
|
|
return
|
|
|
|
exists = False
|
|
|
|
samefile = True
|
|
|
|
|
2009-04-22 03:39:47 +04:00
|
|
|
if not after and exists or after and state in 'mn':
|
2007-12-03 03:11:59 +03:00
|
|
|
if not opts['force']:
|
|
|
|
ui.warn(_('%s: not overwriting - file exists\n') %
|
|
|
|
reltarget)
|
|
|
|
return
|
2007-12-07 11:01:10 +03:00
|
|
|
|
|
|
|
if after:
|
2007-12-07 11:01:13 +03:00
|
|
|
if not exists:
|
2010-05-02 02:39:40 +04:00
|
|
|
if rename:
|
|
|
|
ui.warn(_('%s: not recording move - %s does not exist\n') %
|
|
|
|
(relsrc, reltarget))
|
|
|
|
else:
|
|
|
|
ui.warn(_('%s: not recording copy - %s does not exist\n') %
|
|
|
|
(relsrc, reltarget))
|
2007-12-03 03:11:59 +03:00
|
|
|
return
|
2007-12-07 11:01:13 +03:00
|
|
|
elif not dryrun:
|
2007-12-03 03:11:59 +03:00
|
|
|
try:
|
2007-12-07 11:01:13 +03:00
|
|
|
if exists:
|
|
|
|
os.unlink(target)
|
|
|
|
targetdir = os.path.dirname(target) or '.'
|
|
|
|
if not os.path.isdir(targetdir):
|
|
|
|
os.makedirs(targetdir)
|
2012-03-23 20:47:27 +04:00
|
|
|
if samefile:
|
|
|
|
tmp = target + "~hgrename"
|
|
|
|
os.rename(src, tmp)
|
|
|
|
os.rename(tmp, target)
|
|
|
|
else:
|
|
|
|
util.copyfile(src, target)
|
2011-06-02 02:33:33 +04:00
|
|
|
srcexists = True
|
2015-06-24 08:20:08 +03:00
|
|
|
except IOError as inst:
|
2007-12-03 03:11:59 +03:00
|
|
|
if inst.errno == errno.ENOENT:
|
2015-03-17 16:47:08 +03:00
|
|
|
ui.warn(_('%s: deleted in working directory\n') % relsrc)
|
2011-06-02 02:33:33 +04:00
|
|
|
srcexists = False
|
2007-12-03 03:11:59 +03:00
|
|
|
else:
|
|
|
|
ui.warn(_('%s: cannot copy - %s\n') %
|
|
|
|
(relsrc, inst.strerror))
|
2007-12-07 00:15:47 +03:00
|
|
|
return True # report a failure
|
2007-12-07 11:01:10 +03:00
|
|
|
|
2007-12-03 03:11:59 +03:00
|
|
|
if ui.verbose or not exact:
|
2009-03-27 19:35:00 +03:00
|
|
|
if rename:
|
|
|
|
ui.status(_('moving %s to %s\n') % (relsrc, reltarget))
|
|
|
|
else:
|
|
|
|
ui.status(_('copying %s to %s\n') % (relsrc, reltarget))
|
2007-12-07 11:01:13 +03:00
|
|
|
|
2007-12-03 03:11:59 +03:00
|
|
|
targets[abstarget] = abssrc
|
2007-12-07 11:01:10 +03:00
|
|
|
|
|
|
|
# fix up dirstate
|
2011-05-13 23:48:48 +04:00
|
|
|
scmutil.dirstatecopy(ui, repo, wctx, abssrc, abstarget,
|
|
|
|
dryrun=dryrun, cwd=cwd)
|
2007-12-07 11:29:55 +03:00
|
|
|
if rename and not dryrun:
|
2012-03-23 20:47:27 +04:00
|
|
|
if not after and srcexists and not samefile:
|
2011-06-02 02:33:33 +04:00
|
|
|
util.unlinkpath(repo.wjoin(abssrc))
|
|
|
|
wctx.forget([abssrc])
|
2007-12-03 03:11:59 +03:00
|
|
|
|
|
|
|
# pat: ossep
|
|
|
|
# dest ossep
|
|
|
|
# srcs: list of (hgsep, hgsep, ossep, bool)
|
|
|
|
# return: function that takes hgsep and returns ossep
|
|
|
|
def targetpathfn(pat, dest, srcs):
|
|
|
|
if os.path.isdir(pat):
|
2013-11-07 03:19:04 +04:00
|
|
|
abspfx = pathutil.canonpath(repo.root, cwd, pat)
|
2007-12-03 03:11:59 +03:00
|
|
|
abspfx = util.localpath(abspfx)
|
|
|
|
if destdirexists:
|
|
|
|
striplen = len(os.path.split(abspfx)[0])
|
|
|
|
else:
|
|
|
|
striplen = len(abspfx)
|
|
|
|
if striplen:
|
|
|
|
striplen += len(os.sep)
|
|
|
|
res = lambda p: os.path.join(dest, util.localpath(p)[striplen:])
|
|
|
|
elif destdirexists:
|
|
|
|
res = lambda p: os.path.join(dest,
|
|
|
|
os.path.basename(util.localpath(p)))
|
|
|
|
else:
|
|
|
|
res = lambda p: dest
|
|
|
|
return res
|
|
|
|
|
|
|
|
# pat: ossep
|
|
|
|
# dest ossep
|
|
|
|
# srcs: list of (hgsep, hgsep, ossep, bool)
|
|
|
|
# return: function that takes hgsep and returns ossep
|
|
|
|
def targetpathafterfn(pat, dest, srcs):
|
2010-08-30 16:38:24 +04:00
|
|
|
if matchmod.patkind(pat):
|
2007-12-03 03:11:59 +03:00
|
|
|
# a mercurial pattern
|
|
|
|
res = lambda p: os.path.join(dest,
|
|
|
|
os.path.basename(util.localpath(p)))
|
|
|
|
else:
|
2013-11-07 03:19:04 +04:00
|
|
|
abspfx = pathutil.canonpath(repo.root, cwd, pat)
|
2007-12-03 03:11:59 +03:00
|
|
|
if len(abspfx) < len(srcs[0][0]):
|
|
|
|
# A directory. Either the target path contains the last
|
|
|
|
# component of the source path or it does not.
|
|
|
|
def evalpath(striplen):
|
|
|
|
score = 0
|
|
|
|
for s in srcs:
|
|
|
|
t = os.path.join(dest, util.localpath(s[0])[striplen:])
|
2010-09-21 00:41:10 +04:00
|
|
|
if os.path.lexists(t):
|
2007-12-03 03:11:59 +03:00
|
|
|
score += 1
|
|
|
|
return score
|
|
|
|
|
|
|
|
abspfx = util.localpath(abspfx)
|
|
|
|
striplen = len(abspfx)
|
|
|
|
if striplen:
|
|
|
|
striplen += len(os.sep)
|
|
|
|
if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])):
|
|
|
|
score = evalpath(striplen)
|
|
|
|
striplen1 = len(os.path.split(abspfx)[0])
|
|
|
|
if striplen1:
|
|
|
|
striplen1 += len(os.sep)
|
|
|
|
if evalpath(striplen1) > score:
|
|
|
|
striplen = striplen1
|
|
|
|
res = lambda p: os.path.join(dest,
|
|
|
|
util.localpath(p)[striplen:])
|
|
|
|
else:
|
|
|
|
# a file
|
|
|
|
if destdirexists:
|
|
|
|
res = lambda p: os.path.join(dest,
|
|
|
|
os.path.basename(util.localpath(p)))
|
|
|
|
else:
|
|
|
|
res = lambda p: dest
|
|
|
|
return res
|
|
|
|
|
2011-05-13 23:48:48 +04:00
|
|
|
pats = scmutil.expandpats(pats)
|
2007-12-03 03:11:59 +03:00
|
|
|
if not pats:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('no source or destination specified'))
|
2007-12-03 03:11:59 +03:00
|
|
|
if len(pats) == 1:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('no destination specified'))
|
2007-12-03 03:11:59 +03:00
|
|
|
dest = pats.pop()
|
2008-03-14 16:32:19 +03:00
|
|
|
destdirexists = os.path.isdir(dest) and not os.path.islink(dest)
|
2007-12-03 03:11:59 +03:00
|
|
|
if not destdirexists:
|
2010-08-30 16:38:24 +04:00
|
|
|
if len(pats) > 1 or matchmod.patkind(pats[0]):
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('with multiple sources, destination must be an '
|
2007-12-03 03:11:59 +03:00
|
|
|
'existing directory'))
|
2008-01-09 15:30:35 +03:00
|
|
|
if util.endswithsep(dest):
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('destination %s is not a directory') % dest)
|
2007-12-07 11:01:10 +03:00
|
|
|
|
|
|
|
tfn = targetpathfn
|
|
|
|
if after:
|
2007-12-03 03:11:59 +03:00
|
|
|
tfn = targetpathafterfn
|
|
|
|
copylist = []
|
|
|
|
for pat in pats:
|
2007-12-06 23:58:57 +03:00
|
|
|
srcs = walkpat(pat)
|
2007-12-03 03:11:59 +03:00
|
|
|
if not srcs:
|
|
|
|
continue
|
|
|
|
copylist.append((tfn(pat, dest, srcs), srcs))
|
|
|
|
if not copylist:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('no files to copy'))
|
2007-12-03 03:11:59 +03:00
|
|
|
|
2007-12-07 00:15:47 +03:00
|
|
|
errors = 0
|
2007-12-03 03:11:59 +03:00
|
|
|
for targetpath, srcs in copylist:
|
2007-12-06 23:58:57 +03:00
|
|
|
for abssrc, relsrc, exact in srcs:
|
2007-12-07 00:15:47 +03:00
|
|
|
if copyfile(abssrc, relsrc, targetpath(abssrc), exact):
|
|
|
|
errors += 1
|
2007-12-03 03:11:59 +03:00
|
|
|
|
|
|
|
if errors:
|
|
|
|
ui.warn(_('(consider using --after)\n'))
|
2007-12-07 11:03:42 +03:00
|
|
|
|
2010-05-16 02:48:49 +04:00
|
|
|
return errors != 0
|
2007-12-03 03:11:59 +03:00
|
|
|
|
2009-08-16 06:30:24 +04:00
|
|
|
def service(opts, parentfn=None, initfn=None, runfn=None, logfile=None,
|
2009-12-01 05:28:31 +03:00
|
|
|
runargs=None, appendpid=False):
|
2007-04-28 08:30:55 +04:00
|
|
|
'''Run a command as a service.'''
|
|
|
|
|
2013-10-03 02:17:50 +04:00
|
|
|
def writepid(pid):
|
|
|
|
if opts['pid_file']:
|
2015-03-14 00:00:06 +03:00
|
|
|
if appendpid:
|
|
|
|
mode = 'a'
|
|
|
|
else:
|
|
|
|
mode = 'w'
|
2013-10-03 02:17:50 +04:00
|
|
|
fp = open(opts['pid_file'], mode)
|
|
|
|
fp.write(str(pid) + '\n')
|
|
|
|
fp.close()
|
|
|
|
|
2016-02-22 19:59:08 +03:00
|
|
|
if opts['daemon'] and not opts['daemon_postexec']:
|
2010-01-06 23:11:58 +03:00
|
|
|
# Signal child process startup with file removal
|
|
|
|
lockfd, lockpath = tempfile.mkstemp(prefix='hg-service-')
|
2010-01-25 09:05:27 +03:00
|
|
|
os.close(lockfd)
|
2010-01-06 23:11:58 +03:00
|
|
|
try:
|
|
|
|
if not runargs:
|
2010-01-06 23:11:58 +03:00
|
|
|
runargs = util.hgcmd() + sys.argv[1:]
|
2016-02-22 20:30:02 +03:00
|
|
|
runargs.append('--daemon-postexec=unlink:%s' % lockpath)
|
2010-01-06 23:11:58 +03:00
|
|
|
# Don't pass --cwd to the child process, because we've already
|
|
|
|
# changed directory.
|
2010-01-25 09:05:27 +03:00
|
|
|
for i in xrange(1, len(runargs)):
|
2010-01-06 23:11:58 +03:00
|
|
|
if runargs[i].startswith('--cwd='):
|
|
|
|
del runargs[i]
|
|
|
|
break
|
|
|
|
elif runargs[i].startswith('--cwd'):
|
2010-01-25 09:05:27 +03:00
|
|
|
del runargs[i:i + 2]
|
2010-01-06 23:11:58 +03:00
|
|
|
break
|
2010-02-06 18:50:00 +03:00
|
|
|
def condfn():
|
|
|
|
return not os.path.exists(lockpath)
|
|
|
|
pid = util.rundetached(runargs, condfn)
|
|
|
|
if pid < 0:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('child process failed to start'))
|
2013-10-03 02:20:49 +04:00
|
|
|
writepid(pid)
|
2010-01-06 23:11:58 +03:00
|
|
|
finally:
|
|
|
|
try:
|
|
|
|
os.unlink(lockpath)
|
2015-06-24 08:20:08 +03:00
|
|
|
except OSError as e:
|
2010-01-06 23:11:58 +03:00
|
|
|
if e.errno != errno.ENOENT:
|
|
|
|
raise
|
2007-04-28 08:30:55 +04:00
|
|
|
if parentfn:
|
|
|
|
return parentfn(pid)
|
|
|
|
else:
|
2009-11-17 09:00:00 +03:00
|
|
|
return
|
2007-04-28 08:30:55 +04:00
|
|
|
|
|
|
|
if initfn:
|
|
|
|
initfn()
|
|
|
|
|
2013-10-03 02:20:49 +04:00
|
|
|
if not opts['daemon']:
|
2016-02-03 12:11:22 +03:00
|
|
|
writepid(util.getpid())
|
2007-04-28 08:30:55 +04:00
|
|
|
|
2016-02-22 19:59:08 +03:00
|
|
|
if opts['daemon_postexec']:
|
2007-04-28 08:30:55 +04:00
|
|
|
try:
|
|
|
|
os.setsid()
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
2016-03-09 05:07:40 +03:00
|
|
|
for inst in opts['daemon_postexec']:
|
|
|
|
if inst.startswith('unlink:'):
|
|
|
|
lockpath = inst[7:]
|
|
|
|
os.unlink(lockpath)
|
2016-03-09 04:17:02 +03:00
|
|
|
elif inst.startswith('chdir:'):
|
|
|
|
os.chdir(inst[6:])
|
2016-03-09 05:07:40 +03:00
|
|
|
elif inst != 'none':
|
|
|
|
raise error.Abort(_('invalid value for --daemon-postexec: %s')
|
|
|
|
% inst)
|
2010-01-10 20:13:34 +03:00
|
|
|
util.hidewindow()
|
2007-04-28 08:30:55 +04:00
|
|
|
sys.stdout.flush()
|
|
|
|
sys.stderr.flush()
|
2009-05-25 13:14:32 +04:00
|
|
|
|
2012-08-04 09:14:40 +04:00
|
|
|
nullfd = os.open(os.devnull, os.O_RDWR)
|
2009-05-25 13:14:32 +04:00
|
|
|
logfilefd = nullfd
|
|
|
|
if logfile:
|
|
|
|
logfilefd = os.open(logfile, os.O_RDWR | os.O_CREAT | os.O_APPEND)
|
|
|
|
os.dup2(nullfd, 0)
|
|
|
|
os.dup2(logfilefd, 1)
|
|
|
|
os.dup2(logfilefd, 2)
|
|
|
|
if nullfd not in (0, 1, 2):
|
|
|
|
os.close(nullfd)
|
|
|
|
if logfile and logfilefd not in (0, 1, 2):
|
|
|
|
os.close(logfilefd)
|
2007-04-28 08:30:55 +04:00
|
|
|
|
|
|
|
if runfn:
|
|
|
|
return runfn()
|
|
|
|
|
2015-10-06 19:51:24 +03:00
|
|
|
## facility to let extension process additional data into an import patch
|
|
|
|
# list of identifier to be executed in order
|
|
|
|
extrapreimport = [] # run before commit
|
2015-10-07 23:05:25 +03:00
|
|
|
extrapostimport = [] # run after commit
|
2015-10-06 19:51:24 +03:00
|
|
|
# mapping from identifier to actual import function
|
|
|
|
#
|
|
|
|
# 'preimport' are run before the commit is made and are provided the following
|
|
|
|
# arguments:
|
|
|
|
# - repo: the localrepository instance,
|
|
|
|
# - patchdata: data extracted from patch header (cf m.patch.patchheadermap),
|
2015-10-17 01:58:46 +03:00
|
|
|
# - extra: the future extra dictionary of the changeset, please mutate it,
|
2015-10-06 19:51:24 +03:00
|
|
|
# - opts: the import options.
|
|
|
|
# XXX ideally, we would just pass an ctx ready to be computed, that would allow
|
|
|
|
# mutation of in memory commit and more. Feel free to rework the code to get
|
|
|
|
# there.
|
|
|
|
extrapreimportmap = {}
|
2015-10-07 23:05:25 +03:00
|
|
|
# 'postimport' are run after the commit is made and are provided the following
|
|
|
|
# argument:
|
|
|
|
# - ctx: the changectx created by import.
|
|
|
|
extrapostimportmap = {}
|
2015-10-06 19:51:24 +03:00
|
|
|
|
2014-02-12 04:52:36 +04:00
|
|
|
def tryimportone(ui, repo, hunk, parents, opts, msgs, updatefunc):
|
|
|
|
"""Utility function used by commands.import to import a single patch
|
|
|
|
|
|
|
|
This function is explicitly defined here to help the evolve extension to
|
|
|
|
wrap this part of the import logic.
|
|
|
|
|
|
|
|
The API is currently a bit ugly because it a simple code translation from
|
|
|
|
the import command. Feel free to make it better.
|
|
|
|
|
|
|
|
:hunk: a patch (as a binary string)
|
|
|
|
:parents: nodes that will be parent of the created commit
|
|
|
|
:opts: the full dict of option passed to the import command
|
|
|
|
:msgs: list to save commit message to.
|
|
|
|
(used in case we need to save it when failing)
|
|
|
|
:updatefunc: a function that update a repo to a given node
|
|
|
|
updatefunc(<repo>, <node>)
|
|
|
|
"""
|
2015-08-08 10:47:19 +03:00
|
|
|
# avoid cycle context -> subrepo -> cmdutil
|
2016-02-28 10:57:07 +03:00
|
|
|
from . import context
|
2015-10-06 12:01:53 +03:00
|
|
|
extractdata = patch.extract(ui, hunk)
|
|
|
|
tmpname = extractdata.get('filename')
|
|
|
|
message = extractdata.get('message')
|
2015-12-31 00:06:31 +03:00
|
|
|
user = opts.get('user') or extractdata.get('user')
|
|
|
|
date = opts.get('date') or extractdata.get('date')
|
2015-10-06 12:01:53 +03:00
|
|
|
branch = extractdata.get('branch')
|
|
|
|
nodeid = extractdata.get('nodeid')
|
|
|
|
p1 = extractdata.get('p1')
|
|
|
|
p2 = extractdata.get('p2')
|
2014-02-12 04:52:36 +04:00
|
|
|
|
2015-12-31 00:07:51 +03:00
|
|
|
nocommit = opts.get('no_commit')
|
|
|
|
importbranch = opts.get('import_branch')
|
2014-02-12 04:52:36 +04:00
|
|
|
update = not opts.get('bypass')
|
|
|
|
strip = opts["strip"]
|
2015-03-10 04:22:24 +03:00
|
|
|
prefix = opts["prefix"]
|
2014-02-12 04:52:36 +04:00
|
|
|
sim = float(opts.get('similarity') or 0)
|
|
|
|
if not tmpname:
|
2014-05-09 04:08:17 +04:00
|
|
|
return (None, None, False)
|
2014-02-12 04:52:36 +04:00
|
|
|
|
2014-05-09 04:08:17 +04:00
|
|
|
rejects = False
|
|
|
|
|
2014-02-12 04:52:36 +04:00
|
|
|
try:
|
|
|
|
cmdline_message = logmessage(ui, opts)
|
|
|
|
if cmdline_message:
|
|
|
|
# pickup the cmdline msg
|
|
|
|
message = cmdline_message
|
|
|
|
elif message:
|
|
|
|
# pickup the patch msg
|
|
|
|
message = message.strip()
|
|
|
|
else:
|
|
|
|
# launch the editor
|
|
|
|
message = None
|
|
|
|
ui.debug('message:\n%s\n' % message)
|
|
|
|
|
|
|
|
if len(parents) == 1:
|
|
|
|
parents.append(repo[nullid])
|
|
|
|
if opts.get('exact'):
|
|
|
|
if not nodeid or not p1:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('not a Mercurial patch'))
|
2014-02-12 04:52:36 +04:00
|
|
|
p1 = repo[p1]
|
|
|
|
p2 = repo[p2 or nullid]
|
|
|
|
elif p2:
|
|
|
|
try:
|
|
|
|
p1 = repo[p1]
|
|
|
|
p2 = repo[p2]
|
|
|
|
# Without any options, consider p2 only if the
|
|
|
|
# patch is being applied on top of the recorded
|
|
|
|
# first parent.
|
|
|
|
if p1 != parents[0]:
|
|
|
|
p1 = parents[0]
|
|
|
|
p2 = repo[nullid]
|
|
|
|
except error.RepoError:
|
|
|
|
p1, p2 = parents
|
2014-08-27 18:10:06 +04:00
|
|
|
if p2.node() == nullid:
|
|
|
|
ui.warn(_("warning: import the patch as a normal revision\n"
|
|
|
|
"(use --exact to import the patch as a merge)\n"))
|
2014-02-12 04:52:36 +04:00
|
|
|
else:
|
|
|
|
p1, p2 = parents
|
|
|
|
|
|
|
|
n = None
|
|
|
|
if update:
|
|
|
|
if p1 != parents[0]:
|
|
|
|
updatefunc(repo, p1.node())
|
|
|
|
if p2 != parents[1]:
|
|
|
|
repo.setparents(p1.node(), p2.node())
|
|
|
|
|
2015-12-31 00:07:51 +03:00
|
|
|
if opts.get('exact') or importbranch:
|
2014-02-12 04:52:36 +04:00
|
|
|
repo.dirstate.setbranch(branch or 'default')
|
|
|
|
|
2014-05-09 04:08:17 +04:00
|
|
|
partial = opts.get('partial', False)
|
2014-02-12 04:52:36 +04:00
|
|
|
files = set()
|
2014-05-09 04:08:17 +04:00
|
|
|
try:
|
2015-03-10 04:22:24 +03:00
|
|
|
patch.patch(ui, repo, tmpname, strip=strip, prefix=prefix,
|
|
|
|
files=files, eolmode=None, similarity=sim / 100.0)
|
2015-06-24 08:20:08 +03:00
|
|
|
except patch.PatchError as e:
|
2014-05-09 04:08:17 +04:00
|
|
|
if not partial:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(str(e))
|
2014-05-09 04:08:17 +04:00
|
|
|
if partial:
|
|
|
|
rejects = True
|
|
|
|
|
2014-02-12 04:52:36 +04:00
|
|
|
files = list(files)
|
2015-12-31 00:07:51 +03:00
|
|
|
if nocommit:
|
2014-02-12 04:52:36 +04:00
|
|
|
if message:
|
|
|
|
msgs.append(message)
|
|
|
|
else:
|
|
|
|
if opts.get('exact') or p2:
|
|
|
|
# If you got here, you either use --force and know what
|
|
|
|
# you are doing or used --exact or a merge patch while
|
|
|
|
# being updated to its first parent.
|
|
|
|
m = None
|
|
|
|
else:
|
|
|
|
m = scmutil.matchfiles(repo, files or [])
|
2014-08-16 05:43:59 +04:00
|
|
|
editform = mergeeditform(repo[None], 'import.normal')
|
2014-08-23 18:03:50 +04:00
|
|
|
if opts.get('exact'):
|
|
|
|
editor = None
|
|
|
|
else:
|
|
|
|
editor = getcommiteditor(editform=editform, **opts)
|
2015-05-12 06:15:41 +03:00
|
|
|
allowemptyback = repo.ui.backupconfig('ui', 'allowemptycommit')
|
2015-10-06 19:51:24 +03:00
|
|
|
extra = {}
|
|
|
|
for idfunc in extrapreimport:
|
|
|
|
extrapreimportmap[idfunc](repo, extractdata, extra, opts)
|
2015-05-12 06:15:41 +03:00
|
|
|
try:
|
|
|
|
if partial:
|
|
|
|
repo.ui.setconfig('ui', 'allowemptycommit', True)
|
2015-12-31 00:06:31 +03:00
|
|
|
n = repo.commit(message, user,
|
|
|
|
date, match=m,
|
2015-10-06 19:51:24 +03:00
|
|
|
editor=editor, extra=extra)
|
2015-10-07 23:05:25 +03:00
|
|
|
for idfunc in extrapostimport:
|
|
|
|
extrapostimportmap[idfunc](repo[n])
|
2015-05-12 06:15:41 +03:00
|
|
|
finally:
|
|
|
|
repo.ui.restoreconfig(allowemptyback)
|
2014-02-12 04:52:36 +04:00
|
|
|
else:
|
2015-12-31 00:07:51 +03:00
|
|
|
if opts.get('exact') or importbranch:
|
2014-02-12 04:52:36 +04:00
|
|
|
branch = branch or 'default'
|
|
|
|
else:
|
|
|
|
branch = p1.branch()
|
|
|
|
store = patch.filestore()
|
|
|
|
try:
|
|
|
|
files = set()
|
|
|
|
try:
|
2015-03-10 23:06:38 +03:00
|
|
|
patch.patchrepo(ui, repo, p1, store, tmpname, strip, prefix,
|
2014-02-12 04:52:36 +04:00
|
|
|
files, eolmode=None)
|
2015-06-24 08:20:08 +03:00
|
|
|
except patch.PatchError as e:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(str(e))
|
2014-08-23 18:03:50 +04:00
|
|
|
if opts.get('exact'):
|
|
|
|
editor = None
|
|
|
|
else:
|
|
|
|
editor = getcommiteditor(editform='import.bypass')
|
2014-02-12 04:52:36 +04:00
|
|
|
memctx = context.makememctx(repo, (p1.node(), p2.node()),
|
|
|
|
message,
|
2015-12-31 00:06:31 +03:00
|
|
|
user,
|
|
|
|
date,
|
2014-02-12 04:52:36 +04:00
|
|
|
branch, files, store,
|
2014-08-02 16:46:27 +04:00
|
|
|
editor=editor)
|
2014-02-12 04:52:36 +04:00
|
|
|
n = memctx.commit()
|
|
|
|
finally:
|
|
|
|
store.close()
|
2015-12-31 00:07:51 +03:00
|
|
|
if opts.get('exact') and nocommit:
|
2014-09-19 23:51:58 +04:00
|
|
|
# --exact with --no-commit is still useful in that it does merge
|
|
|
|
# and branch bits
|
|
|
|
ui.warn(_("warning: can't check exact import with --no-commit\n"))
|
|
|
|
elif opts.get('exact') and hex(n) != nodeid:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('patch is damaged or loses information'))
|
2015-12-31 00:05:42 +03:00
|
|
|
msg = _('applied to working directory')
|
2014-02-12 04:52:36 +04:00
|
|
|
if n:
|
|
|
|
# i18n: refers to a short changeset id
|
|
|
|
msg = _('created %s') % short(n)
|
2014-05-09 04:08:17 +04:00
|
|
|
return (msg, n, rejects)
|
2014-02-12 04:52:36 +04:00
|
|
|
finally:
|
|
|
|
os.unlink(tmpname)
|
|
|
|
|
2015-10-06 09:17:01 +03:00
|
|
|
# facility to let extensions include additional data in an exported patch
|
|
|
|
# list of identifiers to be executed in order
|
|
|
|
extraexport = []
|
|
|
|
# mapping from identifier to actual export function
|
|
|
|
# function as to return a string to be added to the header or None
|
|
|
|
# it is given two arguments (sequencenumber, changectx)
|
|
|
|
extraexportmap = {}
|
|
|
|
|
2010-03-08 21:43:24 +03:00
|
|
|
def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False,
|
2015-09-10 05:27:48 +03:00
|
|
|
opts=None, match=None):
|
2010-03-08 21:43:24 +03:00
|
|
|
'''export changesets as hg patches.'''
|
|
|
|
|
|
|
|
total = len(revs)
|
|
|
|
revwidth = max([len(str(rev)) for rev in revs])
|
2013-02-10 01:38:57 +04:00
|
|
|
filemode = {}
|
2010-03-08 21:43:24 +03:00
|
|
|
|
|
|
|
def single(rev, seqno, fp):
|
|
|
|
ctx = repo[rev]
|
|
|
|
node = ctx.node()
|
|
|
|
parents = [p.node() for p in ctx.parents() if p]
|
|
|
|
branch = ctx.branch()
|
|
|
|
if switch_parent:
|
|
|
|
parents.reverse()
|
2015-03-14 00:00:06 +03:00
|
|
|
|
|
|
|
if parents:
|
|
|
|
prev = parents[0]
|
|
|
|
else:
|
|
|
|
prev = nullid
|
2010-03-08 21:43:24 +03:00
|
|
|
|
2010-12-24 17:23:01 +03:00
|
|
|
shouldclose = False
|
2012-08-27 20:37:49 +04:00
|
|
|
if not fp and len(template) > 0:
|
2011-07-30 14:08:45 +04:00
|
|
|
desc_lines = ctx.description().rstrip().split('\n')
|
|
|
|
desc = desc_lines[0] #Commit always has a first line.
|
|
|
|
fp = makefileobj(repo, template, node, desc=desc, total=total,
|
2013-02-10 01:38:57 +04:00
|
|
|
seqno=seqno, revwidth=revwidth, mode='wb',
|
|
|
|
modemap=filemode)
|
2015-12-13 13:57:54 +03:00
|
|
|
shouldclose = True
|
2015-12-13 13:47:46 +03:00
|
|
|
if fp and not getattr(fp, 'name', '<unnamed>').startswith('<'):
|
2010-03-08 21:43:24 +03:00
|
|
|
repo.ui.note("%s\n" % fp.name)
|
|
|
|
|
2012-08-27 20:37:49 +04:00
|
|
|
if not fp:
|
|
|
|
write = repo.ui.write
|
|
|
|
else:
|
|
|
|
def write(s, **kw):
|
|
|
|
fp.write(s)
|
|
|
|
|
|
|
|
write("# HG changeset patch\n")
|
|
|
|
write("# User %s\n" % ctx.user())
|
|
|
|
write("# Date %d %d\n" % ctx.date())
|
2013-02-09 01:54:17 +04:00
|
|
|
write("# %s\n" % util.datestr(ctx.date()))
|
2010-08-12 20:00:41 +04:00
|
|
|
if branch and branch != 'default':
|
2012-08-27 20:37:49 +04:00
|
|
|
write("# Branch %s\n" % branch)
|
|
|
|
write("# Node ID %s\n" % hex(node))
|
|
|
|
write("# Parent %s\n" % hex(prev))
|
2010-03-08 21:43:24 +03:00
|
|
|
if len(parents) > 1:
|
2012-08-27 20:37:49 +04:00
|
|
|
write("# Parent %s\n" % hex(parents[1]))
|
2015-10-06 09:17:01 +03:00
|
|
|
|
|
|
|
for headerid in extraexport:
|
|
|
|
header = extraexportmap[headerid](seqno, ctx)
|
|
|
|
if header is not None:
|
|
|
|
write('# %s\n' % header)
|
2012-08-27 20:37:49 +04:00
|
|
|
write(ctx.description().rstrip())
|
|
|
|
write("\n\n")
|
2010-03-08 21:43:24 +03:00
|
|
|
|
2015-09-10 05:27:48 +03:00
|
|
|
for chunk, label in patch.diffui(repo, prev, node, match, opts=opts):
|
2012-08-27 20:37:49 +04:00
|
|
|
write(chunk, label=label)
|
2010-03-08 21:43:24 +03:00
|
|
|
|
2010-12-24 17:23:01 +03:00
|
|
|
if shouldclose:
|
|
|
|
fp.close()
|
2010-12-01 23:46:08 +03:00
|
|
|
|
2010-03-08 21:43:24 +03:00
|
|
|
for seqno, rev in enumerate(revs):
|
|
|
|
single(rev, seqno + 1, fp)
|
|
|
|
|
2010-04-06 19:45:20 +04:00
|
|
|
def diffordiffstat(ui, repo, diffopts, node1, node2, match,
|
2010-09-03 14:58:51 +04:00
|
|
|
changes=None, stat=False, fp=None, prefix='',
|
2015-03-25 21:55:15 +03:00
|
|
|
root='', listsubrepos=False):
|
2010-04-06 19:45:20 +04:00
|
|
|
'''show diff or diffstat.'''
|
|
|
|
if fp is None:
|
|
|
|
write = ui.write
|
|
|
|
else:
|
|
|
|
def write(s, **kw):
|
|
|
|
fp.write(s)
|
|
|
|
|
2015-03-25 21:55:15 +03:00
|
|
|
if root:
|
|
|
|
relroot = pathutil.canonpath(repo.root, repo.getcwd(), root)
|
2015-03-18 01:06:40 +03:00
|
|
|
else:
|
|
|
|
relroot = ''
|
|
|
|
if relroot != '':
|
|
|
|
# XXX relative roots currently don't work if the root is within a
|
|
|
|
# subrepo
|
|
|
|
uirelroot = match.uipath(relroot)
|
|
|
|
relroot += '/'
|
|
|
|
for matchroot in match.files():
|
|
|
|
if not matchroot.startswith(relroot):
|
|
|
|
ui.warn(_('warning: %s not inside relative root %s\n') % (
|
|
|
|
match.uipath(matchroot), uirelroot))
|
|
|
|
|
2010-04-06 19:45:20 +04:00
|
|
|
if stat:
|
2010-08-13 10:29:30 +04:00
|
|
|
diffopts = diffopts.copy(context=0)
|
2010-04-06 19:45:20 +04:00
|
|
|
width = 80
|
|
|
|
if not ui.plain():
|
2010-10-10 19:06:36 +04:00
|
|
|
width = ui.termwidth()
|
2010-09-03 14:58:51 +04:00
|
|
|
chunks = patch.diff(repo, node1, node2, match, changes, diffopts,
|
2015-03-18 01:06:40 +03:00
|
|
|
prefix=prefix, relroot=relroot)
|
2010-04-06 19:45:20 +04:00
|
|
|
for chunk, label in patch.diffstatui(util.iterlines(chunks),
|
|
|
|
width=width,
|
|
|
|
git=diffopts.git):
|
|
|
|
write(chunk, label=label)
|
|
|
|
else:
|
|
|
|
for chunk, label in patch.diffui(repo, node1, node2, match,
|
2015-03-18 01:06:40 +03:00
|
|
|
changes, diffopts, prefix=prefix,
|
|
|
|
relroot=relroot):
|
2010-04-06 19:45:20 +04:00
|
|
|
write(chunk, label=label)
|
|
|
|
|
2010-09-03 14:58:51 +04:00
|
|
|
if listsubrepos:
|
|
|
|
ctx1 = repo[node1]
|
2010-09-07 18:23:55 +04:00
|
|
|
ctx2 = repo[node2]
|
2014-02-04 03:36:00 +04:00
|
|
|
for subpath, sub in scmutil.itersubrepos(ctx1, ctx2):
|
2011-12-16 01:41:03 +04:00
|
|
|
tempnode2 = node2
|
2011-12-14 18:28:00 +04:00
|
|
|
try:
|
|
|
|
if node2 is not None:
|
2011-12-16 01:41:03 +04:00
|
|
|
tempnode2 = ctx2.substate[subpath][1]
|
2011-12-14 18:28:00 +04:00
|
|
|
except KeyError:
|
|
|
|
# A subrepo that existed in node1 was deleted between node1 and
|
|
|
|
# node2 (inclusive). Thus, ctx2's substate won't contain that
|
|
|
|
# subpath. The best we can do is to ignore it.
|
2011-12-16 01:41:03 +04:00
|
|
|
tempnode2 = None
|
2016-02-06 08:09:32 +03:00
|
|
|
submatch = matchmod.subdirmatcher(subpath, match)
|
2012-11-29 19:43:55 +04:00
|
|
|
sub.diff(ui, diffopts, tempnode2, submatch, changes=changes,
|
2010-09-03 14:58:51 +04:00
|
|
|
stat=stat, fp=fp, prefix=prefix)
|
|
|
|
|
2006-12-01 10:28:19 +03:00
|
|
|
class changeset_printer(object):
|
|
|
|
'''show changeset information when templating not requested.'''
|
|
|
|
|
2014-08-31 18:45:50 +04:00
|
|
|
def __init__(self, ui, repo, matchfn, diffopts, buffered):
|
2006-11-13 22:26:57 +03:00
|
|
|
self.ui = ui
|
2006-12-01 10:28:19 +03:00
|
|
|
self.repo = repo
|
|
|
|
self.buffered = buffered
|
2014-08-31 18:45:50 +04:00
|
|
|
self.matchfn = matchfn
|
2009-02-15 00:40:39 +03:00
|
|
|
self.diffopts = diffopts
|
2006-11-13 22:26:57 +03:00
|
|
|
self.header = {}
|
2006-12-01 10:28:19 +03:00
|
|
|
self.hunk = {}
|
2006-11-13 22:26:57 +03:00
|
|
|
self.lastheader = None
|
2009-12-28 19:55:52 +03:00
|
|
|
self.footer = None
|
2006-12-01 10:28:19 +03:00
|
|
|
|
2015-04-12 15:52:02 +03:00
|
|
|
def flush(self, ctx):
|
|
|
|
rev = ctx.rev()
|
2006-11-13 22:26:57 +03:00
|
|
|
if rev in self.header:
|
2006-12-01 10:28:19 +03:00
|
|
|
h = self.header[rev]
|
2006-11-13 22:26:57 +03:00
|
|
|
if h != self.lastheader:
|
|
|
|
self.lastheader = h
|
|
|
|
self.ui.write(h)
|
|
|
|
del self.header[rev]
|
|
|
|
if rev in self.hunk:
|
2006-12-01 10:28:19 +03:00
|
|
|
self.ui.write(self.hunk[rev])
|
2006-11-13 22:26:57 +03:00
|
|
|
del self.hunk[rev]
|
|
|
|
return 1
|
|
|
|
return 0
|
|
|
|
|
2009-12-28 19:55:52 +03:00
|
|
|
def close(self):
|
|
|
|
if self.footer:
|
|
|
|
self.ui.write(self.footer)
|
|
|
|
|
2010-06-29 14:12:34 +04:00
|
|
|
def show(self, ctx, copies=None, matchfn=None, **props):
|
2006-12-01 10:28:19 +03:00
|
|
|
if self.buffered:
|
2015-11-23 01:13:25 +03:00
|
|
|
self.ui.pushbuffer(labeled=True)
|
2010-06-29 14:12:34 +04:00
|
|
|
self._show(ctx, copies, matchfn, props)
|
2015-11-24 22:23:10 +03:00
|
|
|
self.hunk[ctx.rev()] = self.ui.popbuffer()
|
2006-12-01 10:28:19 +03:00
|
|
|
else:
|
2010-06-29 14:12:34 +04:00
|
|
|
self._show(ctx, copies, matchfn, props)
|
2006-11-13 22:26:57 +03:00
|
|
|
|
2010-06-29 14:12:34 +04:00
|
|
|
def _show(self, ctx, copies, matchfn, props):
|
2006-11-13 22:26:57 +03:00
|
|
|
'''show a single changeset or file revision'''
|
2008-11-14 15:59:25 +03:00
|
|
|
changenode = ctx.node()
|
|
|
|
rev = ctx.rev()
|
2015-03-14 14:01:30 +03:00
|
|
|
if self.ui.debugflag:
|
|
|
|
hexfunc = hex
|
|
|
|
else:
|
|
|
|
hexfunc = short
|
2015-07-04 11:19:49 +03:00
|
|
|
# as of now, wctx.node() and wctx.rev() return None, but we want to
|
|
|
|
# show the same values as {node} and {rev} templatekw
|
|
|
|
revnode = (scmutil.intrev(rev), hexfunc(bin(ctx.hex())))
|
2006-11-13 22:26:57 +03:00
|
|
|
|
|
|
|
if self.ui.quiet:
|
2015-03-14 14:01:30 +03:00
|
|
|
self.ui.write("%d:%s\n" % revnode, label='log.node')
|
2006-11-13 22:26:57 +03:00
|
|
|
return
|
|
|
|
|
2009-10-06 02:17:13 +04:00
|
|
|
date = util.datestr(ctx.date())
|
2006-11-13 22:26:57 +03:00
|
|
|
|
2012-10-30 22:59:27 +04:00
|
|
|
# i18n: column positioning for "hg log"
|
2015-03-14 14:01:30 +03:00
|
|
|
self.ui.write(_("changeset: %d:%s\n") % revnode,
|
2012-10-16 22:35:58 +04:00
|
|
|
label='log.changeset changeset.%s' % ctx.phasestr())
|
2006-11-13 22:26:57 +03:00
|
|
|
|
2014-10-17 20:26:37 +04:00
|
|
|
# branches are shown first before any other names due to backwards
|
|
|
|
# compatibility
|
2009-10-24 21:01:40 +04:00
|
|
|
branch = ctx.branch()
|
2007-03-13 21:02:33 +03:00
|
|
|
# don't show the default branch name
|
|
|
|
if branch != 'default':
|
2012-10-30 22:59:27 +04:00
|
|
|
# i18n: column positioning for "hg log"
|
2010-04-03 00:22:07 +04:00
|
|
|
self.ui.write(_("branch: %s\n") % branch,
|
|
|
|
label='log.branch')
|
2014-10-17 20:26:37 +04:00
|
|
|
|
2016-04-14 22:26:18 +03:00
|
|
|
for nsname, ns in self.repo.names.iteritems():
|
2014-10-17 20:26:37 +04:00
|
|
|
# branches has special logic already handled above, so here we just
|
|
|
|
# skip it
|
2016-04-14 22:26:18 +03:00
|
|
|
if nsname == 'branches':
|
2014-10-17 20:26:37 +04:00
|
|
|
continue
|
|
|
|
# we will use the templatename as the color name since those two
|
|
|
|
# should be the same
|
|
|
|
for name in ns.names(self.repo, changenode):
|
2015-01-28 16:22:59 +03:00
|
|
|
self.ui.write(ns.logfmt % name,
|
|
|
|
label='log.%s' % ns.colorname)
|
2014-10-05 00:28:28 +04:00
|
|
|
if self.ui.debugflag:
|
2012-10-30 22:59:27 +04:00
|
|
|
# i18n: column positioning for "hg log"
|
2015-04-25 17:44:53 +03:00
|
|
|
self.ui.write(_("phase: %s\n") % ctx.phasestr(),
|
2012-01-17 23:23:23 +04:00
|
|
|
label='log.phase')
|
2015-09-26 06:29:09 +03:00
|
|
|
for pctx in scmutil.meaningfulparents(self.repo, ctx):
|
2015-03-14 11:19:04 +03:00
|
|
|
label = 'log.parent changeset.%s' % pctx.phasestr()
|
2012-10-30 22:59:27 +04:00
|
|
|
# i18n: column positioning for "hg log"
|
2015-03-14 11:19:04 +03:00
|
|
|
self.ui.write(_("parent: %d:%s\n")
|
|
|
|
% (pctx.rev(), hexfunc(pctx.node())),
|
2014-08-24 02:03:08 +04:00
|
|
|
label=label)
|
2006-11-13 22:26:57 +03:00
|
|
|
|
2015-03-14 11:33:22 +03:00
|
|
|
if self.ui.debugflag and rev is not None:
|
2009-10-06 02:17:13 +04:00
|
|
|
mnode = ctx.manifestnode()
|
2012-10-30 22:59:27 +04:00
|
|
|
# i18n: column positioning for "hg log"
|
2006-11-13 22:26:57 +03:00
|
|
|
self.ui.write(_("manifest: %d:%s\n") %
|
2010-04-03 00:22:07 +04:00
|
|
|
(self.repo.manifest.rev(mnode), hex(mnode)),
|
|
|
|
label='ui.debug log.manifest')
|
2012-10-30 22:59:27 +04:00
|
|
|
# i18n: column positioning for "hg log"
|
2010-04-03 00:22:07 +04:00
|
|
|
self.ui.write(_("user: %s\n") % ctx.user(),
|
|
|
|
label='log.user')
|
2012-10-30 22:59:27 +04:00
|
|
|
# i18n: column positioning for "hg log"
|
2010-04-03 00:22:07 +04:00
|
|
|
self.ui.write(_("date: %s\n") % date,
|
|
|
|
label='log.date')
|
2006-11-13 22:26:57 +03:00
|
|
|
|
|
|
|
if self.ui.debugflag:
|
2015-03-14 11:40:47 +03:00
|
|
|
files = ctx.p1().status(ctx)[:3]
|
2012-10-30 22:59:27 +04:00
|
|
|
for key, value in zip([# i18n: column positioning for "hg log"
|
|
|
|
_("files:"),
|
|
|
|
# i18n: column positioning for "hg log"
|
|
|
|
_("files+:"),
|
|
|
|
# i18n: column positioning for "hg log"
|
|
|
|
_("files-:")], files):
|
2006-11-13 22:26:57 +03:00
|
|
|
if value:
|
2010-04-03 00:22:07 +04:00
|
|
|
self.ui.write("%-12s %s\n" % (key, " ".join(value)),
|
|
|
|
label='ui.debug log.files')
|
2009-10-06 02:17:13 +04:00
|
|
|
elif ctx.files() and self.ui.verbose:
|
2012-10-30 22:59:27 +04:00
|
|
|
# i18n: column positioning for "hg log"
|
2010-04-03 00:22:07 +04:00
|
|
|
self.ui.write(_("files: %s\n") % " ".join(ctx.files()),
|
|
|
|
label='ui.note log.files')
|
2006-11-13 22:26:57 +03:00
|
|
|
if copies and self.ui.verbose:
|
|
|
|
copies = ['%s (%s)' % c for c in copies]
|
2012-10-30 22:59:27 +04:00
|
|
|
# i18n: column positioning for "hg log"
|
2010-04-03 00:22:07 +04:00
|
|
|
self.ui.write(_("copies: %s\n") % ' '.join(copies),
|
|
|
|
label='ui.note log.copies')
|
2006-11-13 22:26:57 +03:00
|
|
|
|
2009-10-24 21:01:40 +04:00
|
|
|
extra = ctx.extra()
|
2006-11-13 22:26:57 +03:00
|
|
|
if extra and self.ui.debugflag:
|
2009-04-27 01:50:44 +04:00
|
|
|
for key, value in sorted(extra.items()):
|
2012-10-30 22:59:27 +04:00
|
|
|
# i18n: column positioning for "hg log"
|
2006-11-13 22:26:57 +03:00
|
|
|
self.ui.write(_("extra: %s=%s\n")
|
2010-04-03 00:22:07 +04:00
|
|
|
% (key, value.encode('string_escape')),
|
|
|
|
label='ui.debug log.extra')
|
2006-11-13 22:26:57 +03:00
|
|
|
|
2009-10-06 02:17:13 +04:00
|
|
|
description = ctx.description().strip()
|
2006-11-13 22:26:57 +03:00
|
|
|
if description:
|
|
|
|
if self.ui.verbose:
|
2010-04-03 00:22:07 +04:00
|
|
|
self.ui.write(_("description:\n"),
|
|
|
|
label='ui.note log.description')
|
|
|
|
self.ui.write(description,
|
|
|
|
label='ui.note log.description')
|
2006-11-13 22:26:57 +03:00
|
|
|
self.ui.write("\n\n")
|
|
|
|
else:
|
2012-10-30 22:59:27 +04:00
|
|
|
# i18n: column positioning for "hg log"
|
2006-11-13 22:26:57 +03:00
|
|
|
self.ui.write(_("summary: %s\n") %
|
2010-04-03 00:22:07 +04:00
|
|
|
description.splitlines()[0],
|
|
|
|
label='log.summary')
|
2006-11-13 22:26:57 +03:00
|
|
|
self.ui.write("\n")
|
|
|
|
|
2015-11-15 04:44:01 +03:00
|
|
|
self.showpatch(ctx, matchfn)
|
2006-11-13 22:26:57 +03:00
|
|
|
|
2015-11-15 04:44:01 +03:00
|
|
|
def showpatch(self, ctx, matchfn):
|
2010-06-29 14:12:34 +04:00
|
|
|
if not matchfn:
|
2014-08-31 18:45:50 +04:00
|
|
|
matchfn = self.matchfn
|
2010-06-29 14:12:34 +04:00
|
|
|
if matchfn:
|
2010-03-31 19:35:12 +04:00
|
|
|
stat = self.diffopts.get('stat')
|
2010-08-13 10:29:30 +04:00
|
|
|
diff = self.diffopts.get('patch')
|
2014-11-22 03:01:55 +03:00
|
|
|
diffopts = patch.diffallopts(self.ui, self.diffopts)
|
2015-11-15 04:44:01 +03:00
|
|
|
node = ctx.node()
|
2016-01-05 03:14:04 +03:00
|
|
|
prev = ctx.p1().node()
|
2010-08-13 10:29:30 +04:00
|
|
|
if stat:
|
|
|
|
diffordiffstat(self.ui, self.repo, diffopts, prev, node,
|
|
|
|
match=matchfn, stat=True)
|
|
|
|
if diff:
|
|
|
|
if stat:
|
|
|
|
self.ui.write("\n")
|
|
|
|
diffordiffstat(self.ui, self.repo, diffopts, prev, node,
|
|
|
|
match=matchfn, stat=False)
|
2006-11-13 22:26:57 +03:00
|
|
|
self.ui.write("\n")
|
|
|
|
|
2014-09-15 22:11:13 +04:00
|
|
|
class jsonchangeset(changeset_printer):
|
|
|
|
'''format changeset information.'''
|
|
|
|
|
|
|
|
def __init__(self, ui, repo, matchfn, diffopts, buffered):
|
|
|
|
changeset_printer.__init__(self, ui, repo, matchfn, diffopts, buffered)
|
|
|
|
self.cache = {}
|
|
|
|
self._first = True
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
if not self._first:
|
|
|
|
self.ui.write("\n]\n")
|
|
|
|
else:
|
|
|
|
self.ui.write("[]\n")
|
|
|
|
|
|
|
|
def _show(self, ctx, copies, matchfn, props):
|
|
|
|
'''show a single changeset or file revision'''
|
|
|
|
rev = ctx.rev()
|
2015-03-14 14:15:40 +03:00
|
|
|
if rev is None:
|
|
|
|
jrev = jnode = 'null'
|
|
|
|
else:
|
|
|
|
jrev = str(rev)
|
|
|
|
jnode = '"%s"' % hex(ctx.node())
|
2014-09-15 22:11:13 +04:00
|
|
|
j = encoding.jsonescape
|
|
|
|
|
|
|
|
if self._first:
|
|
|
|
self.ui.write("[\n {")
|
|
|
|
self._first = False
|
|
|
|
else:
|
|
|
|
self.ui.write(",\n {")
|
|
|
|
|
|
|
|
if self.ui.quiet:
|
2015-03-14 14:15:40 +03:00
|
|
|
self.ui.write('\n "rev": %s' % jrev)
|
|
|
|
self.ui.write(',\n "node": %s' % jnode)
|
2014-09-15 22:11:13 +04:00
|
|
|
self.ui.write('\n }')
|
|
|
|
return
|
|
|
|
|
2015-03-14 14:15:40 +03:00
|
|
|
self.ui.write('\n "rev": %s' % jrev)
|
|
|
|
self.ui.write(',\n "node": %s' % jnode)
|
2014-09-15 22:11:13 +04:00
|
|
|
self.ui.write(',\n "branch": "%s"' % j(ctx.branch()))
|
|
|
|
self.ui.write(',\n "phase": "%s"' % ctx.phasestr())
|
|
|
|
self.ui.write(',\n "user": "%s"' % j(ctx.user()))
|
|
|
|
self.ui.write(',\n "date": [%d, %d]' % ctx.date())
|
|
|
|
self.ui.write(',\n "desc": "%s"' % j(ctx.description()))
|
|
|
|
|
|
|
|
self.ui.write(',\n "bookmarks": [%s]' %
|
|
|
|
", ".join('"%s"' % j(b) for b in ctx.bookmarks()))
|
|
|
|
self.ui.write(',\n "tags": [%s]' %
|
|
|
|
", ".join('"%s"' % j(t) for t in ctx.tags()))
|
|
|
|
self.ui.write(',\n "parents": [%s]' %
|
|
|
|
", ".join('"%s"' % c.hex() for c in ctx.parents()))
|
|
|
|
|
|
|
|
if self.ui.debugflag:
|
2015-03-14 14:16:35 +03:00
|
|
|
if rev is None:
|
|
|
|
jmanifestnode = 'null'
|
|
|
|
else:
|
|
|
|
jmanifestnode = '"%s"' % hex(ctx.manifestnode())
|
|
|
|
self.ui.write(',\n "manifest": %s' % jmanifestnode)
|
2014-09-15 22:11:13 +04:00
|
|
|
|
|
|
|
self.ui.write(',\n "extra": {%s}' %
|
|
|
|
", ".join('"%s": "%s"' % (j(k), j(v))
|
|
|
|
for k, v in ctx.extra().items()))
|
|
|
|
|
2015-01-06 09:18:55 +03:00
|
|
|
files = ctx.p1().status(ctx)
|
2014-09-15 22:11:13 +04:00
|
|
|
self.ui.write(',\n "modified": [%s]' %
|
|
|
|
", ".join('"%s"' % j(f) for f in files[0]))
|
|
|
|
self.ui.write(',\n "added": [%s]' %
|
|
|
|
", ".join('"%s"' % j(f) for f in files[1]))
|
|
|
|
self.ui.write(',\n "removed": [%s]' %
|
|
|
|
", ".join('"%s"' % j(f) for f in files[2]))
|
|
|
|
|
|
|
|
elif self.ui.verbose:
|
|
|
|
self.ui.write(',\n "files": [%s]' %
|
|
|
|
", ".join('"%s"' % j(f) for f in ctx.files()))
|
|
|
|
|
|
|
|
if copies:
|
|
|
|
self.ui.write(',\n "copies": {%s}' %
|
2015-02-02 22:26:47 +03:00
|
|
|
", ".join('"%s": "%s"' % (j(k), j(v))
|
|
|
|
for k, v in copies))
|
2014-09-15 22:11:13 +04:00
|
|
|
|
|
|
|
matchfn = self.matchfn
|
|
|
|
if matchfn:
|
|
|
|
stat = self.diffopts.get('stat')
|
|
|
|
diff = self.diffopts.get('patch')
|
2014-11-19 09:13:05 +03:00
|
|
|
diffopts = patch.difffeatureopts(self.ui, self.diffopts, git=True)
|
2014-09-15 22:11:13 +04:00
|
|
|
node, prev = ctx.node(), ctx.p1().node()
|
|
|
|
if stat:
|
|
|
|
self.ui.pushbuffer()
|
|
|
|
diffordiffstat(self.ui, self.repo, diffopts, prev, node,
|
|
|
|
match=matchfn, stat=True)
|
|
|
|
self.ui.write(',\n "diffstat": "%s"' % j(self.ui.popbuffer()))
|
|
|
|
if diff:
|
|
|
|
self.ui.pushbuffer()
|
|
|
|
diffordiffstat(self.ui, self.repo, diffopts, prev, node,
|
|
|
|
match=matchfn, stat=False)
|
|
|
|
self.ui.write(',\n "diff": "%s"' % j(self.ui.popbuffer()))
|
|
|
|
|
|
|
|
self.ui.write("\n }")
|
2007-07-08 14:52:08 +04:00
|
|
|
|
2006-11-13 22:26:57 +03:00
|
|
|
class changeset_templater(changeset_printer):
|
2006-11-13 22:26:57 +03:00
|
|
|
'''format changeset information.'''
|
|
|
|
|
2014-08-31 18:45:50 +04:00
|
|
|
def __init__(self, ui, repo, matchfn, diffopts, tmpl, mapfile, buffered):
|
|
|
|
changeset_printer.__init__(self, ui, repo, matchfn, diffopts, buffered)
|
2009-05-12 14:04:05 +04:00
|
|
|
formatnode = ui.debugflag and (lambda x: x) or (lambda x: x[:12])
|
2009-12-13 20:06:24 +03:00
|
|
|
defaulttempl = {
|
|
|
|
'parent': '{rev}:{node|formatnode} ',
|
|
|
|
'manifest': '{rev}:{node|formatnode}',
|
|
|
|
'file_copy': '{name} ({source})',
|
|
|
|
'extra': '{key}={value|stringescape}'
|
|
|
|
}
|
|
|
|
# filecopy is preserved for compatibility reasons
|
|
|
|
defaulttempl['filecopy'] = defaulttempl['file_copy']
|
2009-05-12 14:04:05 +04:00
|
|
|
self.t = templater.templater(mapfile, {'formatnode': formatnode},
|
2009-12-13 20:06:24 +03:00
|
|
|
cache=defaulttempl)
|
2014-03-09 02:14:08 +04:00
|
|
|
if tmpl:
|
|
|
|
self.t.cache['changeset'] = tmpl
|
2006-11-13 22:26:57 +03:00
|
|
|
|
2014-03-09 02:14:08 +04:00
|
|
|
self.cache = {}
|
2006-11-13 22:26:57 +03:00
|
|
|
|
2015-08-25 21:38:20 +03:00
|
|
|
# find correct templates for current mode
|
|
|
|
tmplmodes = [
|
|
|
|
(True, None),
|
|
|
|
(self.ui.verbose, 'verbose'),
|
|
|
|
(self.ui.quiet, 'quiet'),
|
|
|
|
(self.ui.debugflag, 'debug'),
|
|
|
|
]
|
|
|
|
|
2015-08-27 00:27:14 +03:00
|
|
|
self._parts = {'header': '', 'footer': '', 'changeset': 'changeset',
|
|
|
|
'docheader': '', 'docfooter': ''}
|
2015-08-25 21:38:20 +03:00
|
|
|
for mode, postfix in tmplmodes:
|
|
|
|
for t in self._parts:
|
|
|
|
cur = t
|
|
|
|
if postfix:
|
|
|
|
cur += "_" + postfix
|
|
|
|
if mode and cur in self.t:
|
|
|
|
self._parts[t] = cur
|
|
|
|
|
2015-08-27 00:27:14 +03:00
|
|
|
if self._parts['docheader']:
|
|
|
|
self.ui.write(templater.stringify(self.t(self._parts['docheader'])))
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
if self._parts['docfooter']:
|
|
|
|
if not self.footer:
|
|
|
|
self.footer = ""
|
|
|
|
self.footer += templater.stringify(self.t(self._parts['docfooter']))
|
|
|
|
return super(changeset_templater, self).close()
|
|
|
|
|
2010-06-29 14:12:34 +04:00
|
|
|
def _show(self, ctx, copies, matchfn, props):
|
2006-11-13 22:26:57 +03:00
|
|
|
'''show a single changeset or file revision'''
|
|
|
|
props = props.copy()
|
2009-12-13 20:06:23 +03:00
|
|
|
props.update(templatekw.keywords)
|
2009-12-13 20:06:23 +03:00
|
|
|
props['templ'] = self.t
|
2009-12-13 20:06:23 +03:00
|
|
|
props['ctx'] = ctx
|
2009-12-13 20:06:23 +03:00
|
|
|
props['repo'] = self.repo
|
2016-03-08 15:08:33 +03:00
|
|
|
props['ui'] = self.repo.ui
|
2009-12-13 20:06:24 +03:00
|
|
|
props['revcache'] = {'copies': copies}
|
2009-12-13 20:06:24 +03:00
|
|
|
props['cache'] = self.cache
|
2006-11-13 22:26:57 +03:00
|
|
|
|
2016-04-03 05:23:31 +03:00
|
|
|
# write header
|
|
|
|
if self._parts['header']:
|
|
|
|
h = templater.stringify(self.t(self._parts['header'], **props))
|
|
|
|
if self.buffered:
|
|
|
|
self.header[ctx.rev()] = h
|
|
|
|
else:
|
|
|
|
if self.lastheader != h:
|
|
|
|
self.lastheader = h
|
|
|
|
self.ui.write(h)
|
|
|
|
|
|
|
|
# write changeset metadata, then patch if requested
|
|
|
|
key = self._parts['changeset']
|
|
|
|
self.ui.write(templater.stringify(self.t(key, **props)))
|
|
|
|
self.showpatch(ctx, matchfn)
|
|
|
|
|
|
|
|
if self._parts['footer']:
|
|
|
|
if not self.footer:
|
|
|
|
self.footer = templater.stringify(
|
|
|
|
self.t(self._parts['footer'], **props))
|
2006-11-13 22:26:57 +03:00
|
|
|
|
2014-03-09 02:01:58 +04:00
|
|
|
def gettemplate(ui, tmpl, style):
|
|
|
|
"""
|
|
|
|
Find the template matching the given template spec or style.
|
2006-11-13 22:26:57 +03:00
|
|
|
"""
|
2009-04-04 19:55:52 +04:00
|
|
|
|
|
|
|
# ui settings
|
2014-09-30 18:15:56 +04:00
|
|
|
if not tmpl and not style: # template are stronger than style
|
2009-04-04 19:55:52 +04:00
|
|
|
tmpl = ui.config('ui', 'logtemplate')
|
|
|
|
if tmpl:
|
2016-03-26 12:12:12 +03:00
|
|
|
return templater.unquotestring(tmpl), None
|
2009-04-04 19:55:52 +04:00
|
|
|
else:
|
2010-01-15 11:50:52 +03:00
|
|
|
style = util.expandpath(ui.config('ui', 'style', ''))
|
2009-04-04 19:55:52 +04:00
|
|
|
|
2014-09-30 18:15:56 +04:00
|
|
|
if not tmpl and style:
|
2009-04-04 19:55:52 +04:00
|
|
|
mapfile = style
|
|
|
|
if not os.path.split(mapfile)[0]:
|
|
|
|
mapname = (templater.templatepath('map-cmdline.' + mapfile)
|
|
|
|
or templater.templatepath(mapfile))
|
2010-01-25 09:05:27 +03:00
|
|
|
if mapname:
|
|
|
|
mapfile = mapname
|
2014-03-09 02:01:58 +04:00
|
|
|
return None, mapfile
|
|
|
|
|
2014-03-09 03:38:50 +04:00
|
|
|
if not tmpl:
|
|
|
|
return None, None
|
|
|
|
|
2015-06-10 22:29:13 +03:00
|
|
|
return formatter.lookuptemplate(ui, 'changeset', tmpl)
|
2014-03-09 02:01:58 +04:00
|
|
|
|
|
|
|
def show_changeset(ui, repo, opts, buffered=False):
|
|
|
|
"""show one changeset using template or regular display.
|
|
|
|
|
|
|
|
Display format will be the first non-empty hit of:
|
|
|
|
1. option 'template'
|
|
|
|
2. option 'style'
|
|
|
|
3. [ui] setting 'logtemplate'
|
|
|
|
4. [ui] setting 'style'
|
|
|
|
If all of these values are either the unset or the empty string,
|
|
|
|
regular display via changeset_printer() is done.
|
|
|
|
"""
|
|
|
|
# options
|
2014-08-31 18:45:50 +04:00
|
|
|
matchfn = None
|
2014-03-09 02:01:58 +04:00
|
|
|
if opts.get('patch') or opts.get('stat'):
|
2014-08-31 18:45:50 +04:00
|
|
|
matchfn = scmutil.matchall(repo)
|
2014-03-09 02:01:58 +04:00
|
|
|
|
2014-09-15 22:11:13 +04:00
|
|
|
if opts.get('template') == 'json':
|
|
|
|
return jsonchangeset(ui, repo, matchfn, opts, buffered)
|
|
|
|
|
2014-03-09 02:01:58 +04:00
|
|
|
tmpl, mapfile = gettemplate(ui, opts.get('template'), opts.get('style'))
|
|
|
|
|
|
|
|
if not tmpl and not mapfile:
|
2014-08-31 18:45:50 +04:00
|
|
|
return changeset_printer(ui, repo, matchfn, opts, buffered)
|
2009-04-04 19:55:52 +04:00
|
|
|
|
2016-03-26 12:01:04 +03:00
|
|
|
return changeset_templater(ui, repo, matchfn, opts, tmpl, mapfile, buffered)
|
2006-11-13 22:26:57 +03:00
|
|
|
|
2016-03-23 20:50:24 +03:00
|
|
|
def showmarker(ui, marker, index=None):
|
2014-02-12 04:30:23 +04:00
|
|
|
"""utility function to display obsolescence marker in a readable way
|
|
|
|
|
|
|
|
To be used by debug function."""
|
2016-03-23 20:50:24 +03:00
|
|
|
if index is not None:
|
|
|
|
ui.write("%i " % index)
|
2014-02-12 04:30:23 +04:00
|
|
|
ui.write(hex(marker.precnode()))
|
|
|
|
for repl in marker.succnodes():
|
|
|
|
ui.write(' ')
|
|
|
|
ui.write(hex(repl))
|
2014-08-15 20:41:30 +04:00
|
|
|
ui.write(' %X ' % marker.flags())
|
2014-08-19 04:17:23 +04:00
|
|
|
parents = marker.parentnodes()
|
|
|
|
if parents is not None:
|
|
|
|
ui.write('{%s} ' % ', '.join(hex(p) for p in parents))
|
2014-08-14 10:42:36 +04:00
|
|
|
ui.write('(%s) ' % util.datestr(marker.date()))
|
2014-02-12 04:30:23 +04:00
|
|
|
ui.write('{%s}' % (', '.join('%r: %r' % t for t in
|
2014-08-14 10:42:36 +04:00
|
|
|
sorted(marker.metadata().items())
|
|
|
|
if t[0] != 'date')))
|
2014-02-12 04:30:23 +04:00
|
|
|
ui.write('\n')
|
|
|
|
|
2006-12-07 02:58:09 +03:00
|
|
|
def finddate(ui, repo, date):
|
|
|
|
"""Find the tipmost changeset that matches the given date spec"""
|
2009-10-30 11:53:39 +03:00
|
|
|
|
2008-01-11 04:36:20 +03:00
|
|
|
df = util.matchdate(date)
|
2011-05-13 23:58:24 +04:00
|
|
|
m = scmutil.matchall(repo)
|
2006-12-07 02:58:09 +03:00
|
|
|
results = {}
|
2009-10-30 01:07:51 +03:00
|
|
|
|
|
|
|
def prep(ctx, fns):
|
|
|
|
d = ctx.date()
|
|
|
|
if df(d[0]):
|
2009-10-30 11:54:39 +03:00
|
|
|
results[ctx.rev()] = d
|
2009-10-30 01:07:51 +03:00
|
|
|
|
2009-10-30 11:53:39 +03:00
|
|
|
for ctx in walkchangerevs(repo, m, {'rev': None}, prep):
|
2009-10-29 06:47:46 +03:00
|
|
|
rev = ctx.rev()
|
2009-10-30 01:07:51 +03:00
|
|
|
if rev in results:
|
2012-06-12 16:18:18 +04:00
|
|
|
ui.status(_("found revision %s from %s\n") %
|
2009-10-30 01:07:51 +03:00
|
|
|
(rev, util.datestr(results[rev])))
|
|
|
|
return str(rev)
|
2006-12-07 02:58:09 +03:00
|
|
|
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_("revision matching date not found"))
|
2006-12-07 02:58:09 +03:00
|
|
|
|
2014-02-14 02:27:12 +04:00
|
|
|
def increasingwindows(windowsize=8, sizelimit=512):
|
|
|
|
while True:
|
|
|
|
yield windowsize
|
|
|
|
if windowsize < sizelimit:
|
|
|
|
windowsize *= 2
|
2012-05-09 00:43:44 +04:00
|
|
|
|
2013-05-31 06:25:55 +04:00
|
|
|
class FileWalkError(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def walkfilerevs(repo, match, follow, revs, fncache):
|
|
|
|
'''Walks the file history for the matched files.
|
|
|
|
|
|
|
|
Returns the changeset revs that are involved in the file history.
|
|
|
|
|
|
|
|
Throws FileWalkError if the file history can't be walked using
|
|
|
|
filelogs alone.
|
|
|
|
'''
|
|
|
|
wanted = set()
|
|
|
|
copies = []
|
|
|
|
minrev, maxrev = min(revs), max(revs)
|
|
|
|
def filerevgen(filelog, last):
|
|
|
|
"""
|
|
|
|
Only files, no patterns. Check the history of each file.
|
|
|
|
|
|
|
|
Examines filelog entries within minrev, maxrev linkrev range
|
|
|
|
Returns an iterator yielding (linkrev, parentlinkrevs, copied)
|
|
|
|
tuples in backwards order
|
|
|
|
"""
|
|
|
|
cl_count = len(repo)
|
|
|
|
revs = []
|
|
|
|
for j in xrange(0, last + 1):
|
|
|
|
linkrev = filelog.linkrev(j)
|
|
|
|
if linkrev < minrev:
|
|
|
|
continue
|
|
|
|
# only yield rev for which we have the changelog, it can
|
|
|
|
# happen while doing "hg log" during a pull or commit
|
|
|
|
if linkrev >= cl_count:
|
|
|
|
break
|
|
|
|
|
|
|
|
parentlinkrevs = []
|
|
|
|
for p in filelog.parentrevs(j):
|
|
|
|
if p != nullrev:
|
|
|
|
parentlinkrevs.append(filelog.linkrev(p))
|
|
|
|
n = filelog.node(j)
|
|
|
|
revs.append((linkrev, parentlinkrevs,
|
|
|
|
follow and filelog.renamed(n)))
|
|
|
|
|
|
|
|
return reversed(revs)
|
|
|
|
def iterfiles():
|
|
|
|
pctx = repo['.']
|
|
|
|
for filename in match.files():
|
|
|
|
if follow:
|
|
|
|
if filename not in pctx:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('cannot follow file not in parent '
|
2013-05-31 06:25:55 +04:00
|
|
|
'revision: "%s"') % filename)
|
|
|
|
yield filename, pctx[filename].filenode()
|
|
|
|
else:
|
|
|
|
yield filename, None
|
|
|
|
for filename_node in copies:
|
|
|
|
yield filename_node
|
|
|
|
|
|
|
|
for file_, node in iterfiles():
|
|
|
|
filelog = repo.file(file_)
|
|
|
|
if not len(filelog):
|
|
|
|
if node is None:
|
|
|
|
# A zero count may be a directory or deleted file, so
|
|
|
|
# try to find matching entries on the slow path.
|
|
|
|
if follow:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(
|
2013-05-31 06:25:55 +04:00
|
|
|
_('cannot follow nonexistent file: "%s"') % file_)
|
|
|
|
raise FileWalkError("Cannot walk via filelog")
|
|
|
|
else:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if node is None:
|
|
|
|
last = len(filelog) - 1
|
|
|
|
else:
|
|
|
|
last = filelog.rev(node)
|
|
|
|
|
|
|
|
# keep track of all ancestors of the file
|
|
|
|
ancestors = set([filelog.linkrev(last)])
|
|
|
|
|
|
|
|
# iterate from latest to oldest revision
|
|
|
|
for rev, flparentlinkrevs, copied in filerevgen(filelog, last):
|
|
|
|
if not follow:
|
|
|
|
if rev > maxrev:
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
# Note that last might not be the first interesting
|
|
|
|
# rev to us:
|
|
|
|
# if the file has been changed after maxrev, we'll
|
|
|
|
# have linkrev(last) > maxrev, and we still need
|
|
|
|
# to explore the file graph
|
|
|
|
if rev not in ancestors:
|
|
|
|
continue
|
|
|
|
# XXX insert 1327 fix here
|
|
|
|
if flparentlinkrevs:
|
|
|
|
ancestors.update(flparentlinkrevs)
|
|
|
|
|
|
|
|
fncache.setdefault(rev, []).append(file_)
|
|
|
|
wanted.add(rev)
|
|
|
|
if copied:
|
|
|
|
copies.append(copied)
|
|
|
|
|
|
|
|
return wanted
|
|
|
|
|
2015-03-19 19:12:21 +03:00
|
|
|
class _followfilter(object):
|
|
|
|
def __init__(self, repo, onlyfirst=False):
|
|
|
|
self.repo = repo
|
|
|
|
self.startrev = nullrev
|
|
|
|
self.roots = set()
|
|
|
|
self.onlyfirst = onlyfirst
|
|
|
|
|
|
|
|
def match(self, rev):
|
|
|
|
def realparents(rev):
|
|
|
|
if self.onlyfirst:
|
|
|
|
return self.repo.changelog.parentrevs(rev)[0:1]
|
|
|
|
else:
|
|
|
|
return filter(lambda x: x != nullrev,
|
|
|
|
self.repo.changelog.parentrevs(rev))
|
|
|
|
|
|
|
|
if self.startrev == nullrev:
|
|
|
|
self.startrev = rev
|
|
|
|
return True
|
|
|
|
|
|
|
|
if rev > self.startrev:
|
|
|
|
# forward: all descendants
|
|
|
|
if not self.roots:
|
|
|
|
self.roots.add(self.startrev)
|
|
|
|
for parent in realparents(rev):
|
|
|
|
if parent in self.roots:
|
|
|
|
self.roots.add(rev)
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
# backwards: all parents
|
|
|
|
if not self.roots:
|
|
|
|
self.roots.update(realparents(self.startrev))
|
|
|
|
if rev in self.roots:
|
|
|
|
self.roots.remove(rev)
|
|
|
|
self.roots.update(realparents(rev))
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
2009-10-30 03:03:16 +03:00
|
|
|
def walkchangerevs(repo, match, opts, prepare):
|
2009-02-28 14:38:45 +03:00
|
|
|
'''Iterate over files and the revs in which they changed.
|
2006-11-16 00:51:58 +03:00
|
|
|
|
|
|
|
Callers most commonly need to iterate backwards over the history
|
2009-02-28 14:38:45 +03:00
|
|
|
in which they are interested. Doing so has awful (quadratic-looking)
|
2006-11-16 00:51:58 +03:00
|
|
|
performance, so we use iterators in a "windowed" way.
|
|
|
|
|
|
|
|
We walk a window of revisions in the desired order. Within the
|
|
|
|
window, we first walk forwards to gather data, then in the desired
|
|
|
|
order (usually backwards) to display it.
|
|
|
|
|
2009-10-30 01:07:51 +03:00
|
|
|
This function returns an iterator yielding contexts. Before
|
|
|
|
yielding each context, the iterator will first call the prepare
|
|
|
|
function on each context in the window in forward order.'''
|
2006-11-16 00:51:58 +03:00
|
|
|
|
|
|
|
follow = opts.get('follow') or opts.get('follow_first')
|
2015-02-05 18:22:20 +03:00
|
|
|
revs = _logrevs(repo, opts)
|
2010-06-04 03:00:15 +04:00
|
|
|
if not revs:
|
|
|
|
return []
|
2009-04-22 02:57:28 +04:00
|
|
|
wanted = set()
|
2015-05-19 21:34:50 +03:00
|
|
|
slowpath = match.anypats() or ((match.isexact() or match.prefix()) and
|
|
|
|
opts.get('removed'))
|
2006-11-16 00:51:58 +03:00
|
|
|
fncache = {}
|
2012-02-11 02:52:32 +04:00
|
|
|
change = repo.changectx
|
2006-11-16 00:51:58 +03:00
|
|
|
|
2010-07-20 09:32:33 +04:00
|
|
|
# First step is to fill wanted, the set of revisions that we want to yield.
|
|
|
|
# When it does not induce extra cost, we also fill fncache for revisions in
|
|
|
|
# wanted: a cache of filenames that were changed (ctx.files()) and that
|
|
|
|
# match the file filtering conditions.
|
|
|
|
|
2014-10-29 08:32:18 +03:00
|
|
|
if match.always():
|
2006-11-16 00:51:58 +03:00
|
|
|
# No files, no patterns. Display all revs.
|
2014-02-14 02:27:12 +04:00
|
|
|
wanted = revs
|
2015-05-22 00:20:24 +03:00
|
|
|
elif not slowpath:
|
2010-07-20 09:32:33 +04:00
|
|
|
# We only have to read through the filelog to find wanted revisions
|
|
|
|
|
2013-05-31 06:25:55 +04:00
|
|
|
try:
|
|
|
|
wanted = walkfilerevs(repo, match, follow, revs, fncache)
|
|
|
|
except FileWalkError:
|
|
|
|
slowpath = True
|
2010-08-15 18:17:53 +04:00
|
|
|
|
2013-05-31 06:25:55 +04:00
|
|
|
# We decided to fall back to the slowpath because at least one
|
|
|
|
# of the paths was not a file. Check to see if at least one of them
|
|
|
|
# existed in history, otherwise simply return
|
2012-09-14 10:50:45 +04:00
|
|
|
for path in match.files():
|
|
|
|
if path == '.' or path in repo.store:
|
|
|
|
break
|
2013-01-15 04:05:12 +04:00
|
|
|
else:
|
|
|
|
return []
|
2012-09-14 10:50:45 +04:00
|
|
|
|
2006-11-16 00:51:58 +03:00
|
|
|
if slowpath:
|
2010-07-20 09:32:33 +04:00
|
|
|
# We have to read the changelog to match filenames against
|
|
|
|
# changed files
|
|
|
|
|
2006-11-16 00:51:58 +03:00
|
|
|
if follow:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('can only follow copies/renames for explicit '
|
2009-06-09 17:25:17 +04:00
|
|
|
'filenames'))
|
2006-11-16 00:51:58 +03:00
|
|
|
|
|
|
|
# The slow path checks files modified in every changeset.
|
2013-09-11 06:49:34 +04:00
|
|
|
# This is really slow on large repos, so compute the set lazily.
|
|
|
|
class lazywantedset(object):
|
|
|
|
def __init__(self):
|
|
|
|
self.set = set()
|
|
|
|
self.revs = set(revs)
|
|
|
|
|
|
|
|
# No need to worry about locality here because it will be accessed
|
|
|
|
# in the same order as the increasing window below.
|
|
|
|
def __contains__(self, value):
|
|
|
|
if value in self.set:
|
|
|
|
return True
|
|
|
|
elif not value in self.revs:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
self.revs.discard(value)
|
|
|
|
ctx = change(value)
|
|
|
|
matches = filter(match, ctx.files())
|
|
|
|
if matches:
|
|
|
|
fncache[value] = matches
|
|
|
|
self.set.add(value)
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def discard(self, value):
|
|
|
|
self.revs.discard(value)
|
|
|
|
self.set.discard(value)
|
|
|
|
|
|
|
|
wanted = lazywantedset()
|
2006-11-16 00:51:58 +03:00
|
|
|
|
|
|
|
# it might be worthwhile to do this in the iterator if the rev range
|
|
|
|
# is descending and the prune args are all within that range
|
|
|
|
for rev in opts.get('prune', ()):
|
2012-04-08 21:38:24 +04:00
|
|
|
rev = repo[rev].rev()
|
2015-03-19 19:12:21 +03:00
|
|
|
ff = _followfilter(repo)
|
2006-11-16 00:51:58 +03:00
|
|
|
stop = min(revs[0], revs[-1])
|
2010-01-25 09:05:27 +03:00
|
|
|
for x in xrange(rev, stop - 1, -1):
|
2009-04-22 02:57:28 +04:00
|
|
|
if ff.match(x):
|
2014-02-14 02:27:12 +04:00
|
|
|
wanted = wanted - [x]
|
2013-02-20 23:31:38 +04:00
|
|
|
|
2010-07-20 09:32:33 +04:00
|
|
|
# Now that wanted is correctly initialized, we can iterate over the
|
|
|
|
# revision range, yielding only revisions in wanted.
|
2006-11-16 00:51:58 +03:00
|
|
|
def iterate():
|
2015-05-19 21:34:50 +03:00
|
|
|
if follow and match.always():
|
2015-03-19 19:12:21 +03:00
|
|
|
ff = _followfilter(repo, onlyfirst=opts.get('follow_first'))
|
2006-11-16 00:51:58 +03:00
|
|
|
def want(rev):
|
2009-04-22 19:15:59 +04:00
|
|
|
return ff.match(rev) and rev in wanted
|
2006-11-16 00:51:58 +03:00
|
|
|
else:
|
|
|
|
def want(rev):
|
|
|
|
return rev in wanted
|
|
|
|
|
2014-02-14 02:27:12 +04:00
|
|
|
it = iter(revs)
|
|
|
|
stopiteration = False
|
|
|
|
for windowsize in increasingwindows():
|
|
|
|
nrevs = []
|
|
|
|
for i in xrange(windowsize):
|
2015-05-18 04:11:02 +03:00
|
|
|
rev = next(it, None)
|
|
|
|
if rev is None:
|
2014-02-14 02:27:12 +04:00
|
|
|
stopiteration = True
|
|
|
|
break
|
2015-05-18 04:11:02 +03:00
|
|
|
elif want(rev):
|
|
|
|
nrevs.append(rev)
|
2009-04-27 01:50:44 +04:00
|
|
|
for rev in sorted(nrevs):
|
2006-11-16 00:51:58 +03:00
|
|
|
fns = fncache.get(rev)
|
2009-10-26 02:43:59 +03:00
|
|
|
ctx = change(rev)
|
2006-11-16 00:51:58 +03:00
|
|
|
if not fns:
|
|
|
|
def fns_generator():
|
2009-10-26 02:43:59 +03:00
|
|
|
for f in ctx.files():
|
2009-10-26 02:43:56 +03:00
|
|
|
if match(f):
|
2006-11-16 00:51:58 +03:00
|
|
|
yield f
|
|
|
|
fns = fns_generator()
|
2009-10-30 01:07:51 +03:00
|
|
|
prepare(ctx, fns)
|
2006-11-16 00:51:58 +03:00
|
|
|
for rev in nrevs:
|
2009-10-30 01:07:51 +03:00
|
|
|
yield change(rev)
|
2014-02-14 02:27:12 +04:00
|
|
|
|
|
|
|
if stopiteration:
|
|
|
|
break
|
|
|
|
|
2009-10-26 02:43:56 +03:00
|
|
|
return iterate()
|
2007-08-01 03:28:05 +04:00
|
|
|
|
2014-08-14 02:15:13 +04:00
|
|
|
def _makefollowlogfilematcher(repo, files, followfirst):
|
2012-07-14 20:55:21 +04:00
|
|
|
# When displaying a revision with --patch --follow FILE, we have
|
|
|
|
# to know which file of the revision must be diffed. With
|
|
|
|
# --follow, we want the names of the ancestors of FILE in the
|
|
|
|
# revision, stored in "fcache". "fcache" is populated by
|
|
|
|
# reproducing the graph traversal already done by --follow revset
|
|
|
|
# and relating linkrevs to file names (which is not "correct" but
|
|
|
|
# good enough).
|
|
|
|
fcache = {}
|
|
|
|
fcacheready = [False]
|
|
|
|
pctx = repo['.']
|
|
|
|
|
|
|
|
def populate():
|
2014-07-12 13:23:17 +04:00
|
|
|
for fn in files:
|
2012-07-14 20:55:21 +04:00
|
|
|
for i in ((pctx[fn],), pctx[fn].ancestors(followfirst=followfirst)):
|
|
|
|
for c in i:
|
|
|
|
fcache.setdefault(c.linkrev(), set()).add(c.path())
|
|
|
|
|
|
|
|
def filematcher(rev):
|
|
|
|
if not fcacheready[0]:
|
|
|
|
# Lazy initialization
|
|
|
|
fcacheready[0] = True
|
|
|
|
populate()
|
2014-07-13 05:31:18 +04:00
|
|
|
return scmutil.matchfiles(repo, fcache.get(rev, []))
|
2012-07-14 20:55:21 +04:00
|
|
|
|
|
|
|
return filematcher
|
|
|
|
|
2014-08-14 02:17:03 +04:00
|
|
|
def _makenofollowlogfilematcher(repo, pats, opts):
|
|
|
|
'''hook for extensions to override the filematcher for non-follow cases'''
|
|
|
|
return None
|
|
|
|
|
2014-02-25 22:40:04 +04:00
|
|
|
def _makelogrevset(repo, pats, opts, revs):
|
2012-07-14 20:55:21 +04:00
|
|
|
"""Return (expr, filematcher) where expr is a revset string built
|
|
|
|
from log options and file patterns or None. If --stat or --patch
|
|
|
|
are not passed filematcher is None. Otherwise it is a callable
|
|
|
|
taking a revision number and returning a match objects filtering
|
|
|
|
the files to be detailed when displaying the revision.
|
|
|
|
"""
|
|
|
|
opt2revset = {
|
|
|
|
'no_merges': ('not merge()', None),
|
|
|
|
'only_merges': ('merge()', None),
|
|
|
|
'_ancestors': ('ancestors(%(val)s)', None),
|
|
|
|
'_fancestors': ('_firstancestors(%(val)s)', None),
|
|
|
|
'_descendants': ('descendants(%(val)s)', None),
|
|
|
|
'_fdescendants': ('_firstdescendants(%(val)s)', None),
|
|
|
|
'_matchfiles': ('_matchfiles(%(val)s)', None),
|
|
|
|
'date': ('date(%(val)r)', None),
|
|
|
|
'branch': ('branch(%(val)r)', ' or '),
|
|
|
|
'_patslog': ('filelog(%(val)r)', ' or '),
|
|
|
|
'_patsfollow': ('follow(%(val)r)', ' or '),
|
|
|
|
'_patsfollowfirst': ('_followfirst(%(val)r)', ' or '),
|
|
|
|
'keyword': ('keyword(%(val)r)', ' or '),
|
|
|
|
'prune': ('not (%(val)r or ancestors(%(val)r))', ' and '),
|
|
|
|
'user': ('user(%(val)r)', ' or '),
|
|
|
|
}
|
|
|
|
|
|
|
|
opts = dict(opts)
|
|
|
|
# follow or not follow?
|
|
|
|
follow = opts.get('follow') or opts.get('follow_first')
|
2015-03-14 00:00:06 +03:00
|
|
|
if opts.get('follow_first'):
|
|
|
|
followfirst = 1
|
|
|
|
else:
|
|
|
|
followfirst = 0
|
2015-08-28 17:53:55 +03:00
|
|
|
# --follow with FILE behavior depends on revs...
|
2014-03-14 22:35:17 +04:00
|
|
|
it = iter(revs)
|
|
|
|
startrev = it.next()
|
2015-05-18 20:17:08 +03:00
|
|
|
followdescendants = startrev < next(it, startrev)
|
2012-07-14 20:55:21 +04:00
|
|
|
|
|
|
|
# branch and only_branch are really aliases and must be handled at
|
|
|
|
# the same time
|
|
|
|
opts['branch'] = opts.get('branch', []) + opts.get('only_branch', [])
|
|
|
|
opts['branch'] = [repo.lookupbranch(b) for b in opts['branch']]
|
|
|
|
# pats/include/exclude are passed to match.match() directly in
|
2012-08-16 00:38:42 +04:00
|
|
|
# _matchfiles() revset but walkchangerevs() builds its matcher with
|
2012-07-14 20:55:21 +04:00
|
|
|
# scmutil.match(). The difference is input pats are globbed on
|
|
|
|
# platforms without shell expansion (windows).
|
2015-03-19 07:44:25 +03:00
|
|
|
wctx = repo[None]
|
|
|
|
match, pats = scmutil.matchandpats(wctx, pats, opts)
|
2015-05-19 21:35:43 +03:00
|
|
|
slowpath = match.anypats() or ((match.isexact() or match.prefix()) and
|
|
|
|
opts.get('removed'))
|
2012-07-14 20:55:21 +04:00
|
|
|
if not slowpath:
|
|
|
|
for f in match.files():
|
2015-03-19 07:44:25 +03:00
|
|
|
if follow and f not in wctx:
|
2014-07-23 09:40:16 +04:00
|
|
|
# If the file exists, it may be a directory, so let it
|
|
|
|
# take the slow path.
|
|
|
|
if os.path.exists(repo.wjoin(f)):
|
|
|
|
slowpath = True
|
|
|
|
continue
|
|
|
|
else:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('cannot follow file not in parent '
|
2014-07-23 09:40:16 +04:00
|
|
|
'revision: "%s"') % f)
|
2012-07-14 20:55:21 +04:00
|
|
|
filelog = repo.file(f)
|
2013-05-31 05:47:16 +04:00
|
|
|
if not filelog:
|
2012-07-14 20:55:21 +04:00
|
|
|
# A zero count may be a directory or deleted file, so
|
|
|
|
# try to find matching entries on the slow path.
|
|
|
|
if follow:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(
|
2012-07-14 20:55:21 +04:00
|
|
|
_('cannot follow nonexistent file: "%s"') % f)
|
|
|
|
slowpath = True
|
2012-09-14 10:50:45 +04:00
|
|
|
|
|
|
|
# We decided to fall back to the slowpath because at least one
|
|
|
|
# of the paths was not a file. Check to see if at least one of them
|
|
|
|
# existed in history - in that case, we'll continue down the
|
|
|
|
# slowpath; otherwise, we can turn off the slowpath
|
|
|
|
if slowpath:
|
|
|
|
for path in match.files():
|
|
|
|
if path == '.' or path in repo.store:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
slowpath = False
|
|
|
|
|
2014-12-06 01:27:32 +03:00
|
|
|
fpats = ('_patsfollow', '_patsfollowfirst')
|
|
|
|
fnopats = (('_ancestors', '_fancestors'),
|
|
|
|
('_descendants', '_fdescendants'))
|
2012-07-14 20:55:21 +04:00
|
|
|
if slowpath:
|
|
|
|
# See walkchangerevs() slow path.
|
|
|
|
#
|
|
|
|
# pats/include/exclude cannot be represented as separate
|
|
|
|
# revset expressions as their filtering logic applies at file
|
|
|
|
# level. For instance "-I a -X a" matches a revision touching
|
|
|
|
# "a" and "b" while "file(a) and not file(b)" does
|
|
|
|
# not. Besides, filesets are evaluated against the working
|
|
|
|
# directory.
|
|
|
|
matchargs = ['r:', 'd:relpath']
|
|
|
|
for p in pats:
|
|
|
|
matchargs.append('p:' + p)
|
|
|
|
for p in opts.get('include', []):
|
|
|
|
matchargs.append('i:' + p)
|
|
|
|
for p in opts.get('exclude', []):
|
|
|
|
matchargs.append('x:' + p)
|
|
|
|
matchargs = ','.join(('%r' % p) for p in matchargs)
|
|
|
|
opts['_matchfiles'] = matchargs
|
2014-12-06 01:27:32 +03:00
|
|
|
if follow:
|
|
|
|
opts[fnopats[0][followfirst]] = '.'
|
2012-07-14 20:55:21 +04:00
|
|
|
else:
|
|
|
|
if follow:
|
|
|
|
if pats:
|
2012-08-16 00:38:42 +04:00
|
|
|
# follow() revset interprets its file argument as a
|
2012-07-14 20:55:21 +04:00
|
|
|
# manifest entry, so use match.files(), not pats.
|
|
|
|
opts[fpats[followfirst]] = list(match.files())
|
|
|
|
else:
|
2015-01-10 07:14:00 +03:00
|
|
|
op = fnopats[followdescendants][followfirst]
|
|
|
|
opts[op] = 'rev(%d)' % startrev
|
2012-07-14 20:55:21 +04:00
|
|
|
else:
|
|
|
|
opts['_patslog'] = list(pats)
|
|
|
|
|
|
|
|
filematcher = None
|
|
|
|
if opts.get('patch') or opts.get('stat'):
|
2014-07-23 09:40:16 +04:00
|
|
|
# When following files, track renames via a special matcher.
|
|
|
|
# If we're forced to take the slowpath it means we're following
|
|
|
|
# at least one pattern/directory, so don't bother with rename tracking.
|
|
|
|
if follow and not match.always() and not slowpath:
|
2014-04-18 00:47:38 +04:00
|
|
|
# _makefollowlogfilematcher expects its files argument to be
|
|
|
|
# relative to the repo root, so use match.files(), not pats.
|
2014-08-14 02:15:13 +04:00
|
|
|
filematcher = _makefollowlogfilematcher(repo, match.files(),
|
|
|
|
followfirst)
|
2012-07-14 20:55:21 +04:00
|
|
|
else:
|
2014-08-14 02:17:03 +04:00
|
|
|
filematcher = _makenofollowlogfilematcher(repo, pats, opts)
|
|
|
|
if filematcher is None:
|
|
|
|
filematcher = lambda rev: match
|
2012-07-14 20:55:21 +04:00
|
|
|
|
|
|
|
expr = []
|
2014-12-09 02:41:54 +03:00
|
|
|
for op, val in sorted(opts.iteritems()):
|
2012-07-14 20:55:21 +04:00
|
|
|
if not val:
|
|
|
|
continue
|
|
|
|
if op not in opt2revset:
|
|
|
|
continue
|
|
|
|
revop, andor = opt2revset[op]
|
|
|
|
if '%(val)' not in revop:
|
|
|
|
expr.append(revop)
|
|
|
|
else:
|
|
|
|
if not isinstance(val, list):
|
|
|
|
e = revop % {'val': val}
|
|
|
|
else:
|
|
|
|
e = '(' + andor.join((revop % {'val': v}) for v in val) + ')'
|
|
|
|
expr.append(e)
|
|
|
|
|
|
|
|
if expr:
|
|
|
|
expr = '(' + ' and '.join(expr) + ')'
|
|
|
|
else:
|
|
|
|
expr = None
|
|
|
|
return expr, filematcher
|
|
|
|
|
2015-02-05 18:15:35 +03:00
|
|
|
def _logrevs(repo, opts):
|
2015-08-28 17:53:55 +03:00
|
|
|
# Default --rev value depends on --follow but --follow behavior
|
2015-02-05 18:15:35 +03:00
|
|
|
# depends on revisions resolved from --rev...
|
|
|
|
follow = opts.get('follow') or opts.get('follow_first')
|
|
|
|
if opts.get('rev'):
|
|
|
|
revs = scmutil.revrange(repo, opts['rev'])
|
2015-02-06 15:53:39 +03:00
|
|
|
elif follow and repo.dirstate.p1() == nullid:
|
|
|
|
revs = revset.baseset()
|
2015-02-05 18:15:35 +03:00
|
|
|
elif follow:
|
|
|
|
revs = repo.revs('reverse(:.)')
|
|
|
|
else:
|
|
|
|
revs = revset.spanset(repo)
|
|
|
|
revs.reverse()
|
|
|
|
return revs
|
|
|
|
|
2012-07-14 20:55:21 +04:00
|
|
|
def getgraphlogrevs(repo, pats, opts):
|
|
|
|
"""Return (revs, expr, filematcher) where revs is an iterable of
|
|
|
|
revision numbers, expr is a revset string built from log options
|
|
|
|
and file patterns or None, and used to filter 'revs'. If --stat or
|
|
|
|
--patch are not passed filematcher is None. Otherwise it is a
|
|
|
|
callable taking a revision number and returning a match objects
|
|
|
|
filtering the files to be detailed when displaying the revision.
|
|
|
|
"""
|
2012-12-29 04:25:12 +04:00
|
|
|
limit = loglimit(opts)
|
2015-02-05 18:15:35 +03:00
|
|
|
revs = _logrevs(repo, opts)
|
2012-07-14 20:55:21 +04:00
|
|
|
if not revs:
|
2014-03-15 00:26:40 +04:00
|
|
|
return revset.baseset(), None, None
|
2014-02-25 22:40:04 +04:00
|
|
|
expr, filematcher = _makelogrevset(repo, pats, opts, revs)
|
2015-02-05 17:49:18 +03:00
|
|
|
if opts.get('rev'):
|
|
|
|
# User-specified revs might be unsorted, but don't sort before
|
|
|
|
# _makelogrevset because it might depend on the order of revs
|
2012-12-29 02:46:58 +04:00
|
|
|
revs.sort(reverse=True)
|
2012-07-14 20:55:21 +04:00
|
|
|
if expr:
|
2012-12-29 04:25:00 +04:00
|
|
|
# Revset matchers often operate faster on revisions in changelog
|
|
|
|
# order, because most filters deal with the changelog.
|
|
|
|
revs.reverse()
|
2012-07-14 20:55:21 +04:00
|
|
|
matcher = revset.match(repo.ui, expr)
|
2012-12-29 04:25:00 +04:00
|
|
|
# Revset matches can reorder revisions. "A or B" typically returns
|
|
|
|
# returns the revision matching A then the revision matching B. Sort
|
|
|
|
# again to fix that.
|
|
|
|
revs = matcher(repo, revs)
|
|
|
|
revs.sort(reverse=True)
|
2013-01-07 22:24:36 +04:00
|
|
|
if limit is not None:
|
2014-10-07 11:20:00 +04:00
|
|
|
limitedrevs = []
|
2014-03-14 19:43:52 +04:00
|
|
|
for idx, rev in enumerate(revs):
|
|
|
|
if idx >= limit:
|
|
|
|
break
|
|
|
|
limitedrevs.append(rev)
|
2014-10-07 11:20:00 +04:00
|
|
|
revs = revset.baseset(limitedrevs)
|
2012-12-29 04:25:12 +04:00
|
|
|
|
2012-07-14 20:55:21 +04:00
|
|
|
return revs, expr, filematcher
|
|
|
|
|
2014-03-01 03:10:56 +04:00
|
|
|
def getlogrevs(repo, pats, opts):
|
|
|
|
"""Return (revs, expr, filematcher) where revs is an iterable of
|
|
|
|
revision numbers, expr is a revset string built from log options
|
|
|
|
and file patterns or None, and used to filter 'revs'. If --stat or
|
|
|
|
--patch are not passed filematcher is None. Otherwise it is a
|
|
|
|
callable taking a revision number and returning a match objects
|
|
|
|
filtering the files to be detailed when displaying the revision.
|
|
|
|
"""
|
|
|
|
limit = loglimit(opts)
|
2015-02-05 18:15:35 +03:00
|
|
|
revs = _logrevs(repo, opts)
|
2014-03-01 03:10:56 +04:00
|
|
|
if not revs:
|
|
|
|
return revset.baseset([]), None, None
|
|
|
|
expr, filematcher = _makelogrevset(repo, pats, opts, revs)
|
|
|
|
if expr:
|
|
|
|
# Revset matchers often operate faster on revisions in changelog
|
|
|
|
# order, because most filters deal with the changelog.
|
|
|
|
if not opts.get('rev'):
|
|
|
|
revs.reverse()
|
|
|
|
matcher = revset.match(repo.ui, expr)
|
|
|
|
# Revset matches can reorder revisions. "A or B" typically returns
|
|
|
|
# returns the revision matching A then the revision matching B. Sort
|
|
|
|
# again to fix that.
|
2016-02-15 16:46:07 +03:00
|
|
|
fixopts = ['branch', 'only_branch', 'keyword', 'user']
|
|
|
|
oldrevs = revs
|
2014-03-01 03:10:56 +04:00
|
|
|
revs = matcher(repo, revs)
|
|
|
|
if not opts.get('rev'):
|
|
|
|
revs.sort(reverse=True)
|
2016-02-15 16:46:07 +03:00
|
|
|
elif len(pats) > 1 or any(len(opts.get(op, [])) > 1 for op in fixopts):
|
|
|
|
# XXX "A or B" is known to change the order; fix it by filtering
|
|
|
|
# matched set again (issue5100)
|
|
|
|
revs = oldrevs & revs
|
2014-03-01 03:10:56 +04:00
|
|
|
if limit is not None:
|
2014-10-07 11:04:16 +04:00
|
|
|
limitedrevs = []
|
2015-05-18 20:18:00 +03:00
|
|
|
for idx, r in enumerate(revs):
|
|
|
|
if limit <= idx:
|
2014-03-01 03:10:56 +04:00
|
|
|
break
|
2015-05-18 20:18:00 +03:00
|
|
|
limitedrevs.append(r)
|
2014-10-07 11:04:16 +04:00
|
|
|
revs = revset.baseset(limitedrevs)
|
2014-03-01 03:10:56 +04:00
|
|
|
|
|
|
|
return revs, expr, filematcher
|
|
|
|
|
2015-11-14 11:25:43 +03:00
|
|
|
def _graphnodeformatter(ui, displayer):
|
|
|
|
spec = ui.config('ui', 'graphnodetemplate')
|
|
|
|
if not spec:
|
|
|
|
return templatekw.showgraphnode # fast path for "{graphnode}"
|
|
|
|
|
|
|
|
templ = formatter.gettemplater(ui, 'graphnode', spec)
|
|
|
|
cache = {}
|
|
|
|
if isinstance(displayer, changeset_templater):
|
|
|
|
cache = displayer.cache # reuse cache of slow templates
|
|
|
|
props = templatekw.keywords.copy()
|
|
|
|
props['templ'] = templ
|
|
|
|
props['cache'] = cache
|
|
|
|
def formatnode(repo, ctx):
|
|
|
|
props['ctx'] = ctx
|
|
|
|
props['repo'] = repo
|
2016-03-09 17:57:15 +03:00
|
|
|
props['ui'] = repo.ui
|
2015-11-14 11:25:43 +03:00
|
|
|
props['revcache'] = {}
|
|
|
|
return templater.stringify(templ('graphnode', **props))
|
|
|
|
return formatnode
|
|
|
|
|
2015-11-14 10:45:15 +03:00
|
|
|
def displaygraph(ui, repo, dag, displayer, edgefn, getrenamed=None,
|
2012-07-14 20:55:21 +04:00
|
|
|
filematcher=None):
|
2015-11-14 11:25:43 +03:00
|
|
|
formatnode = _graphnodeformatter(ui, displayer)
|
2016-03-04 17:44:32 +03:00
|
|
|
state = graphmod.asciistate()
|
2016-03-20 02:46:15 +03:00
|
|
|
styles = state['styles']
|
|
|
|
edgetypes = {
|
|
|
|
'parent': graphmod.PARENT,
|
|
|
|
'grandparent': graphmod.GRANDPARENT,
|
|
|
|
'missing': graphmod.MISSINGPARENT
|
|
|
|
}
|
|
|
|
for name, key in edgetypes.items():
|
2016-03-24 10:09:58 +03:00
|
|
|
# experimental config: experimental.graphstyle.*
|
|
|
|
styles[key] = ui.config('experimental', 'graphstyle.%s' % name,
|
|
|
|
styles[key])
|
2016-03-20 02:37:47 +03:00
|
|
|
if not styles[key]:
|
|
|
|
styles[key] = None
|
2016-04-08 17:42:43 +03:00
|
|
|
|
|
|
|
# experimental config: experimental.graphshorten
|
|
|
|
state['graphshorten'] = ui.configbool('experimental', 'graphshorten')
|
|
|
|
|
2012-07-14 20:55:21 +04:00
|
|
|
for rev, type, ctx, parents in dag:
|
2015-11-14 11:25:43 +03:00
|
|
|
char = formatnode(repo, ctx)
|
2012-07-14 20:55:21 +04:00
|
|
|
copies = None
|
|
|
|
if getrenamed and ctx.rev():
|
|
|
|
copies = []
|
|
|
|
for fn in ctx.files():
|
|
|
|
rename = getrenamed(fn, ctx.rev())
|
|
|
|
if rename:
|
|
|
|
copies.append((fn, rename[0]))
|
|
|
|
revmatchfn = None
|
|
|
|
if filematcher is not None:
|
|
|
|
revmatchfn = filematcher(ctx.rev())
|
|
|
|
displayer.show(ctx, copies=copies, matchfn=revmatchfn)
|
|
|
|
lines = displayer.hunk.pop(rev).split('\n')
|
|
|
|
if not lines[-1]:
|
|
|
|
del lines[-1]
|
2015-04-12 15:52:02 +03:00
|
|
|
displayer.flush(ctx)
|
2016-03-04 17:44:32 +03:00
|
|
|
edges = edgefn(type, char, lines, state, rev, parents)
|
2012-07-14 20:55:21 +04:00
|
|
|
for type, char, lines, coldata in edges:
|
|
|
|
graphmod.ascii(ui, state, type, char, lines, coldata)
|
|
|
|
displayer.close()
|
|
|
|
|
2012-07-14 21:09:22 +04:00
|
|
|
def graphlog(ui, repo, *pats, **opts):
|
|
|
|
# Parameters are identical to log command ones
|
|
|
|
revs, expr, filematcher = getgraphlogrevs(repo, pats, opts)
|
|
|
|
revdag = graphmod.dagwalker(repo, revs)
|
|
|
|
|
|
|
|
getrenamed = None
|
|
|
|
if opts.get('copies'):
|
|
|
|
endrev = None
|
|
|
|
if opts.get('rev'):
|
2014-03-15 00:27:12 +04:00
|
|
|
endrev = scmutil.revrange(repo, opts.get('rev')).max() + 1
|
2012-07-14 21:09:22 +04:00
|
|
|
getrenamed = templatekw.getrenamedfn(repo, endrev=endrev)
|
|
|
|
displayer = show_changeset(ui, repo, opts, buffered=True)
|
2015-11-14 10:45:15 +03:00
|
|
|
displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges, getrenamed,
|
|
|
|
filematcher)
|
2012-07-14 21:09:22 +04:00
|
|
|
|
2012-07-11 20:22:07 +04:00
|
|
|
def checkunsupportedgraphflags(pats, opts):
|
|
|
|
for op in ["newest_first"]:
|
|
|
|
if op in opts and opts[op]:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_("-G/--graph option is incompatible with --%s")
|
2012-07-11 20:22:07 +04:00
|
|
|
% op.replace("_", "-"))
|
|
|
|
|
|
|
|
def graphrevs(repo, nodes, opts):
|
|
|
|
limit = loglimit(opts)
|
|
|
|
nodes.reverse()
|
|
|
|
if limit is not None:
|
|
|
|
nodes = nodes[:limit]
|
|
|
|
return graphmod.nodes(repo, nodes)
|
|
|
|
|
2015-01-13 04:59:17 +03:00
|
|
|
def add(ui, repo, match, prefix, explicitonly, **opts):
|
2010-09-13 15:09:20 +04:00
|
|
|
join = lambda f: os.path.join(prefix, f)
|
2010-09-13 15:09:11 +04:00
|
|
|
bad = []
|
2015-06-05 04:49:50 +03:00
|
|
|
|
|
|
|
badfn = lambda x, y: bad.append(x) or match.bad(x, y)
|
2010-09-13 15:09:11 +04:00
|
|
|
names = []
|
2010-09-13 15:09:20 +04:00
|
|
|
wctx = repo[None]
|
2011-05-01 01:27:00 +04:00
|
|
|
cca = None
|
|
|
|
abort, warn = scmutil.checkportabilityalert(ui)
|
|
|
|
if abort or warn:
|
2012-07-07 00:56:40 +04:00
|
|
|
cca = scmutil.casecollisionauditor(ui, abort, repo.dirstate)
|
2015-06-05 04:49:50 +03:00
|
|
|
|
2015-09-09 19:07:27 +03:00
|
|
|
badmatch = matchmod.badmatch(match, badfn)
|
|
|
|
dirstate = repo.dirstate
|
|
|
|
# We don't want to just call wctx.walk here, since it would return a lot of
|
|
|
|
# clean files, which we aren't interested in and takes time.
|
|
|
|
for f in sorted(dirstate.walk(badmatch, sorted(wctx.substate),
|
|
|
|
True, False, full=False)):
|
2010-09-13 15:09:11 +04:00
|
|
|
exact = match.exact(f)
|
2014-12-04 01:33:29 +03:00
|
|
|
if exact or not explicitonly and f not in wctx and repo.wvfs.lexists(f):
|
2011-05-01 01:27:00 +04:00
|
|
|
if cca:
|
|
|
|
cca(f)
|
2010-09-13 15:09:11 +04:00
|
|
|
names.append(f)
|
|
|
|
if ui.verbose or not exact:
|
2014-11-27 18:16:56 +03:00
|
|
|
ui.status(_('adding %s\n') % match.rel(f))
|
2010-09-13 15:09:20 +04:00
|
|
|
|
2012-12-12 05:38:14 +04:00
|
|
|
for subpath in sorted(wctx.substate):
|
2011-11-02 09:17:11 +04:00
|
|
|
sub = wctx.sub(subpath)
|
|
|
|
try:
|
2016-02-06 08:09:32 +03:00
|
|
|
submatch = matchmod.subdirmatcher(subpath, match)
|
2015-01-13 04:59:17 +03:00
|
|
|
if opts.get('subrepos'):
|
|
|
|
bad.extend(sub.add(ui, submatch, prefix, False, **opts))
|
2011-11-02 09:17:11 +04:00
|
|
|
else:
|
2015-01-13 04:59:17 +03:00
|
|
|
bad.extend(sub.add(ui, submatch, prefix, True, **opts))
|
2011-11-02 09:17:11 +04:00
|
|
|
except error.LookupError:
|
|
|
|
ui.status(_("skipping missing subrepository: %s\n")
|
|
|
|
% join(subpath))
|
2010-09-13 15:09:20 +04:00
|
|
|
|
2015-01-13 04:59:17 +03:00
|
|
|
if not opts.get('dry_run'):
|
2010-09-13 15:09:20 +04:00
|
|
|
rejected = wctx.add(names, prefix)
|
2010-09-13 15:09:11 +04:00
|
|
|
bad.extend(f for f in rejected if f in match.files())
|
|
|
|
return bad
|
|
|
|
|
2012-01-18 04:10:59 +04:00
|
|
|
def forget(ui, repo, match, prefix, explicitonly):
|
|
|
|
join = lambda f: os.path.join(prefix, f)
|
|
|
|
bad = []
|
2015-06-05 04:53:16 +03:00
|
|
|
badfn = lambda x, y: bad.append(x) or match.bad(x, y)
|
2012-01-18 04:10:59 +04:00
|
|
|
wctx = repo[None]
|
|
|
|
forgot = []
|
2015-06-05 04:53:16 +03:00
|
|
|
|
|
|
|
s = repo.status(match=matchmod.badmatch(match, badfn), clean=True)
|
2012-01-18 04:10:59 +04:00
|
|
|
forget = sorted(s[0] + s[1] + s[3] + s[6])
|
|
|
|
if explicitonly:
|
|
|
|
forget = [f for f in forget if match.exact(f)]
|
|
|
|
|
2012-12-12 05:38:14 +04:00
|
|
|
for subpath in sorted(wctx.substate):
|
2012-01-18 04:10:59 +04:00
|
|
|
sub = wctx.sub(subpath)
|
|
|
|
try:
|
2016-02-06 08:09:32 +03:00
|
|
|
submatch = matchmod.subdirmatcher(subpath, match)
|
2014-12-14 03:23:30 +03:00
|
|
|
subbad, subforgot = sub.forget(submatch, prefix)
|
2012-01-18 04:10:59 +04:00
|
|
|
bad.extend([subpath + '/' + f for f in subbad])
|
|
|
|
forgot.extend([subpath + '/' + f for f in subforgot])
|
|
|
|
except error.LookupError:
|
|
|
|
ui.status(_("skipping missing subrepository: %s\n")
|
|
|
|
% join(subpath))
|
|
|
|
|
2012-02-06 09:37:49 +04:00
|
|
|
if not explicitonly:
|
|
|
|
for f in match.files():
|
2014-12-26 05:43:45 +03:00
|
|
|
if f not in repo.dirstate and not repo.wvfs.isdir(f):
|
2012-01-18 04:10:59 +04:00
|
|
|
if f not in forgot:
|
2014-12-26 05:43:45 +03:00
|
|
|
if repo.wvfs.exists(f):
|
2015-04-01 00:42:46 +03:00
|
|
|
# Don't complain if the exact case match wasn't given.
|
|
|
|
# But don't do this until after checking 'forgot', so
|
|
|
|
# that subrepo files aren't normalized, and this op is
|
|
|
|
# purely from data cached by the status walk above.
|
|
|
|
if repo.dirstate.normalize(f) in repo.dirstate:
|
|
|
|
continue
|
2012-01-18 04:10:59 +04:00
|
|
|
ui.warn(_('not removing %s: '
|
|
|
|
'file is already untracked\n')
|
2014-11-27 18:16:56 +03:00
|
|
|
% match.rel(f))
|
2012-01-18 04:10:59 +04:00
|
|
|
bad.append(f)
|
|
|
|
|
|
|
|
for f in forget:
|
|
|
|
if ui.verbose or not match.exact(f):
|
2014-11-27 18:16:56 +03:00
|
|
|
ui.status(_('removing %s\n') % match.rel(f))
|
2012-01-18 04:10:59 +04:00
|
|
|
|
|
|
|
rejected = wctx.forget(forget, prefix)
|
|
|
|
bad.extend(f for f in rejected if f in match.files())
|
2015-01-12 07:25:23 +03:00
|
|
|
forgot.extend(f for f in forget if f not in rejected)
|
2012-01-18 04:10:59 +04:00
|
|
|
return bad, forgot
|
|
|
|
|
2015-03-19 06:03:41 +03:00
|
|
|
def files(ui, ctx, m, fm, fmt, subrepos):
|
2015-03-08 23:50:57 +03:00
|
|
|
rev = ctx.rev()
|
|
|
|
ret = 1
|
2015-03-13 05:55:35 +03:00
|
|
|
ds = ctx.repo().dirstate
|
2015-03-08 23:50:57 +03:00
|
|
|
|
|
|
|
for f in ctx.matches(m):
|
|
|
|
if rev is None and ds[f] == 'r':
|
|
|
|
continue
|
|
|
|
fm.startitem()
|
|
|
|
if ui.verbose:
|
|
|
|
fc = ctx[f]
|
|
|
|
fm.write('size flags', '% 10d % 1s ', fc.size(), fc.flags())
|
|
|
|
fm.data(abspath=f)
|
|
|
|
fm.write('path', fmt, m.rel(f))
|
|
|
|
ret = 0
|
|
|
|
|
2015-05-18 05:42:47 +03:00
|
|
|
for subpath in sorted(ctx.substate):
|
|
|
|
def matchessubrepo(subpath):
|
2016-03-06 22:30:34 +03:00
|
|
|
return (m.exact(subpath)
|
2015-05-18 05:42:47 +03:00
|
|
|
or any(f.startswith(subpath + '/') for f in m.files()))
|
|
|
|
|
|
|
|
if subrepos or matchessubrepo(subpath):
|
2015-03-19 06:03:41 +03:00
|
|
|
sub = ctx.sub(subpath)
|
|
|
|
try:
|
2016-02-06 08:09:32 +03:00
|
|
|
submatch = matchmod.subdirmatcher(subpath, m)
|
2016-03-06 22:30:34 +03:00
|
|
|
recurse = m.exact(subpath) or subrepos
|
|
|
|
if sub.printfiles(ui, submatch, fm, fmt, recurse) == 0:
|
2015-03-19 06:03:41 +03:00
|
|
|
ret = 0
|
|
|
|
except error.LookupError:
|
|
|
|
ui.status(_("skipping missing subrepository: %s\n")
|
|
|
|
% m.abs(subpath))
|
|
|
|
|
2015-03-08 23:50:57 +03:00
|
|
|
return ret
|
|
|
|
|
2016-03-17 21:19:36 +03:00
|
|
|
def remove(ui, repo, m, prefix, after, force, subrepos, warnings=None):
|
2014-11-16 05:36:19 +03:00
|
|
|
join = lambda f: os.path.join(prefix, f)
|
2014-11-09 20:31:34 +03:00
|
|
|
ret = 0
|
|
|
|
s = repo.status(match=m, clean=True)
|
|
|
|
modified, added, deleted, clean = s[0], s[1], s[3], s[6]
|
|
|
|
|
|
|
|
wctx = repo[None]
|
2014-11-16 05:36:19 +03:00
|
|
|
|
2016-03-17 21:19:36 +03:00
|
|
|
if warnings is None:
|
|
|
|
warnings = []
|
|
|
|
warn = True
|
|
|
|
else:
|
|
|
|
warn = False
|
|
|
|
|
2016-03-18 00:03:22 +03:00
|
|
|
subs = sorted(wctx.substate)
|
|
|
|
total = len(subs)
|
|
|
|
count = 0
|
|
|
|
for subpath in subs:
|
2014-11-13 07:15:20 +03:00
|
|
|
def matchessubrepo(matcher, subpath):
|
|
|
|
if matcher.exact(subpath):
|
|
|
|
return True
|
|
|
|
for f in matcher.files():
|
|
|
|
if f.startswith(subpath):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2016-03-18 00:03:22 +03:00
|
|
|
count += 1
|
2014-11-13 07:15:20 +03:00
|
|
|
if subrepos or matchessubrepo(m, subpath):
|
2016-03-18 00:03:22 +03:00
|
|
|
ui.progress(_('searching'), count, total=total, unit=_('subrepos'))
|
|
|
|
|
2014-11-16 05:36:19 +03:00
|
|
|
sub = wctx.sub(subpath)
|
|
|
|
try:
|
2016-02-06 08:09:32 +03:00
|
|
|
submatch = matchmod.subdirmatcher(subpath, m)
|
2016-03-17 21:19:36 +03:00
|
|
|
if sub.removefiles(submatch, prefix, after, force, subrepos,
|
|
|
|
warnings):
|
2014-11-16 05:36:19 +03:00
|
|
|
ret = 1
|
|
|
|
except error.LookupError:
|
2016-03-17 21:19:36 +03:00
|
|
|
warnings.append(_("skipping missing subrepository: %s\n")
|
2014-11-16 05:36:19 +03:00
|
|
|
% join(subpath))
|
2016-03-18 00:03:22 +03:00
|
|
|
ui.progress(_('searching'), None)
|
2014-11-16 05:36:19 +03:00
|
|
|
|
|
|
|
# warn about failure to delete explicit files/dirs
|
2015-04-07 00:36:08 +03:00
|
|
|
deleteddirs = util.dirs(deleted)
|
2016-03-18 00:03:22 +03:00
|
|
|
files = m.files()
|
|
|
|
total = len(files)
|
|
|
|
count = 0
|
|
|
|
for f in files:
|
2014-11-16 05:36:19 +03:00
|
|
|
def insubrepo():
|
|
|
|
for subpath in wctx.substate:
|
|
|
|
if f.startswith(subpath):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2016-03-18 00:03:22 +03:00
|
|
|
count += 1
|
|
|
|
ui.progress(_('deleting'), count, total=total, unit=_('files'))
|
2015-04-21 19:29:59 +03:00
|
|
|
isdir = f in deleteddirs or wctx.hasdir(f)
|
2015-03-06 09:16:28 +03:00
|
|
|
if f in repo.dirstate or isdir or f == '.' or insubrepo():
|
2014-11-09 20:31:34 +03:00
|
|
|
continue
|
2014-11-16 05:36:19 +03:00
|
|
|
|
2014-12-26 05:50:35 +03:00
|
|
|
if repo.wvfs.exists(f):
|
|
|
|
if repo.wvfs.isdir(f):
|
2016-03-17 21:19:36 +03:00
|
|
|
warnings.append(_('not removing %s: no tracked files\n')
|
2014-11-27 18:16:56 +03:00
|
|
|
% m.rel(f))
|
2014-11-09 20:31:34 +03:00
|
|
|
else:
|
2016-03-17 21:19:36 +03:00
|
|
|
warnings.append(_('not removing %s: file is untracked\n')
|
2014-11-27 18:16:56 +03:00
|
|
|
% m.rel(f))
|
2014-11-09 20:31:34 +03:00
|
|
|
# missing files will generate a warning elsewhere
|
|
|
|
ret = 1
|
2016-03-18 00:03:22 +03:00
|
|
|
ui.progress(_('deleting'), None)
|
2014-11-09 20:31:34 +03:00
|
|
|
|
|
|
|
if force:
|
|
|
|
list = modified + deleted + clean + added
|
|
|
|
elif after:
|
|
|
|
list = deleted
|
2016-03-18 00:03:22 +03:00
|
|
|
remaining = modified + added + clean
|
|
|
|
total = len(remaining)
|
|
|
|
count = 0
|
|
|
|
for f in remaining:
|
|
|
|
count += 1
|
|
|
|
ui.progress(_('skipping'), count, total=total, unit=_('files'))
|
|
|
|
warnings.append(_('not removing %s: file still exists\n')
|
|
|
|
% m.rel(f))
|
2014-11-09 20:31:34 +03:00
|
|
|
ret = 1
|
2016-03-18 00:03:22 +03:00
|
|
|
ui.progress(_('skipping'), None)
|
2014-11-09 20:31:34 +03:00
|
|
|
else:
|
|
|
|
list = deleted + clean
|
2016-03-18 00:03:22 +03:00
|
|
|
total = len(modified) + len(added)
|
|
|
|
count = 0
|
2014-11-09 20:31:34 +03:00
|
|
|
for f in modified:
|
2016-03-18 00:03:22 +03:00
|
|
|
count += 1
|
|
|
|
ui.progress(_('skipping'), count, total=total, unit=_('files'))
|
2016-03-17 21:19:36 +03:00
|
|
|
warnings.append(_('not removing %s: file is modified (use -f'
|
2014-11-27 18:16:56 +03:00
|
|
|
' to force removal)\n') % m.rel(f))
|
2014-11-09 20:31:34 +03:00
|
|
|
ret = 1
|
|
|
|
for f in added:
|
2016-03-18 00:03:22 +03:00
|
|
|
count += 1
|
|
|
|
ui.progress(_('skipping'), count, total=total, unit=_('files'))
|
2016-03-17 21:19:36 +03:00
|
|
|
warnings.append(_('not removing %s: file has been marked for add'
|
2014-11-27 18:16:56 +03:00
|
|
|
' (use forget to undo)\n') % m.rel(f))
|
2014-11-09 20:31:34 +03:00
|
|
|
ret = 1
|
2016-03-18 00:03:22 +03:00
|
|
|
ui.progress(_('skipping'), None)
|
2014-11-09 20:31:34 +03:00
|
|
|
|
2016-03-18 00:03:22 +03:00
|
|
|
list = sorted(list)
|
|
|
|
total = len(list)
|
|
|
|
count = 0
|
|
|
|
for f in list:
|
|
|
|
count += 1
|
2014-11-09 20:31:34 +03:00
|
|
|
if ui.verbose or not m.exact(f):
|
2016-03-18 00:03:22 +03:00
|
|
|
ui.progress(_('deleting'), count, total=total, unit=_('files'))
|
2014-11-27 18:16:56 +03:00
|
|
|
ui.status(_('removing %s\n') % m.rel(f))
|
2016-03-18 00:03:22 +03:00
|
|
|
ui.progress(_('deleting'), None)
|
2014-11-09 20:31:34 +03:00
|
|
|
|
2016-01-16 00:14:45 +03:00
|
|
|
with repo.wlock():
|
2014-11-09 20:31:34 +03:00
|
|
|
if not after:
|
|
|
|
for f in list:
|
|
|
|
if f in added:
|
|
|
|
continue # we never unlink added files on remove
|
|
|
|
util.unlinkpath(repo.wjoin(f), ignoremissing=True)
|
|
|
|
repo[None].forget(list)
|
|
|
|
|
2016-03-17 21:19:36 +03:00
|
|
|
if warn:
|
|
|
|
for warning in warnings:
|
|
|
|
ui.warn(warning)
|
|
|
|
|
2014-11-09 20:31:34 +03:00
|
|
|
return ret
|
|
|
|
|
2014-03-15 05:32:05 +04:00
|
|
|
def cat(ui, repo, ctx, matcher, prefix, **opts):
|
2014-03-14 07:45:18 +04:00
|
|
|
err = 1
|
|
|
|
|
|
|
|
def write(path):
|
2014-03-15 05:32:05 +04:00
|
|
|
fp = makefileobj(repo, opts.get('output'), ctx.node(),
|
|
|
|
pathname=os.path.join(prefix, path))
|
2014-03-14 07:45:18 +04:00
|
|
|
data = ctx[path].data()
|
|
|
|
if opts.get('decode'):
|
|
|
|
data = repo.wwritedata(path, data)
|
|
|
|
fp.write(data)
|
|
|
|
fp.close()
|
|
|
|
|
|
|
|
# Automation often uses hg cat on single files, so special case it
|
|
|
|
# for performance to avoid the cost of parsing the manifest.
|
|
|
|
if len(matcher.files()) == 1 and not matcher.anypats():
|
|
|
|
file = matcher.files()[0]
|
|
|
|
mf = repo.manifest
|
2015-04-11 10:01:42 +03:00
|
|
|
mfnode = ctx.manifestnode()
|
2015-04-05 07:16:46 +03:00
|
|
|
if mfnode and mf.find(mfnode, file)[0]:
|
2014-03-14 07:45:18 +04:00
|
|
|
write(file)
|
|
|
|
return 0
|
|
|
|
|
2014-03-15 05:32:05 +04:00
|
|
|
# Don't warn about "missing" files that are really in subrepos
|
|
|
|
def badfn(path, msg):
|
|
|
|
for subpath in ctx.substate:
|
|
|
|
if path.startswith(subpath):
|
|
|
|
return
|
2015-06-05 04:55:56 +03:00
|
|
|
matcher.bad(path, msg)
|
2014-03-15 05:32:05 +04:00
|
|
|
|
2015-06-05 04:55:56 +03:00
|
|
|
for abs in ctx.walk(matchmod.badmatch(matcher, badfn)):
|
2014-03-14 07:45:18 +04:00
|
|
|
write(abs)
|
|
|
|
err = 0
|
2014-03-15 05:32:05 +04:00
|
|
|
|
|
|
|
for subpath in sorted(ctx.substate):
|
|
|
|
sub = ctx.sub(subpath)
|
|
|
|
try:
|
2016-02-06 08:09:32 +03:00
|
|
|
submatch = matchmod.subdirmatcher(subpath, matcher)
|
2014-03-15 05:32:05 +04:00
|
|
|
|
2014-12-13 22:26:38 +03:00
|
|
|
if not sub.cat(submatch, os.path.join(prefix, sub._path),
|
2014-03-15 05:32:05 +04:00
|
|
|
**opts):
|
|
|
|
err = 0
|
|
|
|
except error.RepoLookupError:
|
|
|
|
ui.status(_("skipping missing subrepository: %s\n")
|
|
|
|
% os.path.join(prefix, subpath))
|
|
|
|
|
2014-03-14 07:45:18 +04:00
|
|
|
return err
|
|
|
|
|
2007-08-01 03:28:05 +04:00
|
|
|
def commit(ui, repo, commitfunc, pats, opts):
|
|
|
|
'''commit the specified files or all outstanding changes'''
|
2008-02-17 23:34:28 +03:00
|
|
|
date = opts.get('date')
|
|
|
|
if date:
|
|
|
|
opts['date'] = util.parsedate(date)
|
2011-06-08 15:54:52 +04:00
|
|
|
message = logmessage(ui, opts)
|
2014-11-10 03:57:02 +03:00
|
|
|
matcher = scmutil.match(repo[None], pats, opts)
|
2007-08-01 03:28:05 +04:00
|
|
|
|
2008-01-10 12:07:18 +03:00
|
|
|
# extract addremove carefully -- this function can be called from a command
|
|
|
|
# that doesn't support addremove
|
|
|
|
if opts.get('addremove'):
|
2014-11-25 06:27:49 +03:00
|
|
|
if scmutil.addremove(repo, matcher, "", opts) != 0:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(
|
2014-11-26 23:16:22 +03:00
|
|
|
_("failed to mark all new/missing files as added/removed"))
|
2008-01-10 12:07:18 +03:00
|
|
|
|
2014-11-10 03:57:02 +03:00
|
|
|
return commitfunc(ui, repo, message, matcher, opts)
|
2009-05-14 22:20:40 +04:00
|
|
|
|
2012-04-18 02:20:16 +04:00
|
|
|
def amend(ui, repo, commitfunc, old, extra, pats, opts):
|
2015-08-08 10:47:19 +03:00
|
|
|
# avoid cycle context -> subrepo -> cmdutil
|
2016-02-28 10:57:07 +03:00
|
|
|
from . import context
|
2015-08-08 10:47:19 +03:00
|
|
|
|
2014-10-29 06:05:19 +03:00
|
|
|
# amend will reuse the existing user if not specified, but the obsolete
|
|
|
|
# marker creation requires that the current user's name is specified.
|
2015-03-18 00:52:58 +03:00
|
|
|
if obsolete.isenabled(repo, obsolete.createmarkersopt):
|
2014-10-29 06:05:19 +03:00
|
|
|
ui.username() # raise exception if username not set
|
|
|
|
|
2012-04-18 02:20:16 +04:00
|
|
|
ui.note(_('amending changeset %s\n') % old)
|
|
|
|
base = old.p1()
|
2015-07-01 08:28:40 +03:00
|
|
|
createmarkers = obsolete.isenabled(repo, obsolete.createmarkersopt)
|
2012-04-18 02:20:16 +04:00
|
|
|
|
2015-10-08 21:53:46 +03:00
|
|
|
wlock = lock = newid = None
|
2012-04-18 02:20:16 +04:00
|
|
|
try:
|
2012-08-25 17:37:28 +04:00
|
|
|
wlock = repo.wlock()
|
|
|
|
lock = repo.lock()
|
2016-01-16 00:14:50 +03:00
|
|
|
with repo.transaction('amend') as tr:
|
2012-08-25 18:20:41 +04:00
|
|
|
# See if we got a message from -m or -l, if not, open the editor
|
|
|
|
# with the message of the changeset to amend
|
|
|
|
message = logmessage(ui, opts)
|
2012-10-24 17:37:32 +04:00
|
|
|
# ensure logfile does not conflict with later enforcement of the
|
|
|
|
# message. potential logfile content has been processed by
|
|
|
|
# `logmessage` anyway.
|
|
|
|
opts.pop('logfile')
|
2012-09-11 01:44:24 +04:00
|
|
|
# First, do a regular commit to record all changes in the working
|
|
|
|
# directory (if there are any)
|
|
|
|
ui.callhooks = False
|
2015-11-12 05:18:02 +03:00
|
|
|
activebookmark = repo._bookmarks.active
|
2012-09-11 01:44:24 +04:00
|
|
|
try:
|
2015-11-12 05:18:02 +03:00
|
|
|
repo._bookmarks.active = None
|
2012-08-25 18:20:41 +04:00
|
|
|
opts['message'] = 'temporary amend commit for %s' % old
|
2012-09-11 01:44:24 +04:00
|
|
|
node = commit(ui, repo, commitfunc, pats, opts)
|
|
|
|
finally:
|
2015-11-12 05:18:02 +03:00
|
|
|
repo._bookmarks.active = activebookmark
|
|
|
|
repo._bookmarks.recordchange(tr)
|
2012-09-11 01:44:24 +04:00
|
|
|
ui.callhooks = True
|
|
|
|
ctx = repo[node]
|
|
|
|
|
|
|
|
# Participating changesets:
|
|
|
|
#
|
|
|
|
# node/ctx o - new (intermediate) commit that contains changes
|
|
|
|
# | from working dir to go into amending commit
|
|
|
|
# | (or a workingctx if there were no changes)
|
|
|
|
# |
|
|
|
|
# old o - changeset to amend
|
|
|
|
# |
|
|
|
|
# base o - parent of amending changeset
|
|
|
|
|
|
|
|
# Update extra dict from amended commit (e.g. to preserve graft
|
|
|
|
# source)
|
|
|
|
extra.update(old.extra())
|
|
|
|
|
|
|
|
# Also update it from the intermediate commit or from the wctx
|
|
|
|
extra.update(ctx.extra())
|
|
|
|
|
2013-02-09 01:08:34 +04:00
|
|
|
if len(old.parents()) > 1:
|
|
|
|
# ctx.files() isn't reliable for merges, so fall back to the
|
|
|
|
# slower repo.status() method
|
|
|
|
files = set([fn for st in repo.status(base, old)[:3]
|
|
|
|
for fn in st])
|
|
|
|
else:
|
|
|
|
files = set(old.files())
|
2012-09-11 01:44:24 +04:00
|
|
|
|
|
|
|
# Second, we use either the commit we just did, or if there were no
|
|
|
|
# changes the parent of the working directory as the version of the
|
|
|
|
# files in the final amend commit
|
|
|
|
if node:
|
|
|
|
ui.note(_('copying changeset %s to %s\n') % (ctx, base))
|
|
|
|
|
|
|
|
user = ctx.user()
|
|
|
|
date = ctx.date()
|
|
|
|
# Recompute copies (avoid recording a -> b -> a)
|
|
|
|
copied = copies.pathcopies(base, ctx)
|
2015-03-02 22:01:00 +03:00
|
|
|
if old.p2:
|
|
|
|
copied.update(copies.pathcopies(old.p2(), ctx))
|
2012-09-11 01:44:24 +04:00
|
|
|
|
|
|
|
# Prune files which were reverted by the updates: if old
|
|
|
|
# introduced file X and our intermediate commit, node,
|
|
|
|
# renamed that file, then those two files are the same and
|
|
|
|
# we can discard X from our list of files. Likewise if X
|
|
|
|
# was deleted, it's no longer relevant
|
|
|
|
files.update(ctx.files())
|
|
|
|
|
|
|
|
def samefile(f):
|
|
|
|
if f in ctx.manifest():
|
|
|
|
a = ctx.filectx(f)
|
|
|
|
if f in base.manifest():
|
|
|
|
b = base.filectx(f)
|
|
|
|
return (not a.cmp(b)
|
|
|
|
and a.flags() == b.flags())
|
|
|
|
else:
|
|
|
|
return False
|
2012-04-18 02:20:16 +04:00
|
|
|
else:
|
2012-09-11 01:44:24 +04:00
|
|
|
return f not in base.manifest()
|
|
|
|
files = [f for f in files if not samefile(f)]
|
|
|
|
|
|
|
|
def filectxfn(repo, ctx_, path):
|
|
|
|
try:
|
|
|
|
fctx = ctx[path]
|
|
|
|
flags = fctx.flags()
|
2013-08-16 01:49:27 +04:00
|
|
|
mctx = context.memfilectx(repo,
|
|
|
|
fctx.path(), fctx.data(),
|
2012-09-11 01:44:24 +04:00
|
|
|
islink='l' in flags,
|
|
|
|
isexec='x' in flags,
|
|
|
|
copied=copied.get(path))
|
|
|
|
return mctx
|
|
|
|
except KeyError:
|
2014-08-27 00:03:32 +04:00
|
|
|
return None
|
2012-09-11 01:44:24 +04:00
|
|
|
else:
|
|
|
|
ui.note(_('copying changeset %s to %s\n') % (old, base))
|
|
|
|
|
|
|
|
# Use version of files as in the old cset
|
|
|
|
def filectxfn(repo, ctx_, path):
|
|
|
|
try:
|
|
|
|
return old.filectx(path)
|
|
|
|
except KeyError:
|
2014-08-27 00:03:32 +04:00
|
|
|
return None
|
2012-09-11 01:44:24 +04:00
|
|
|
|
|
|
|
user = opts.get('user') or old.user()
|
|
|
|
date = opts.get('date') or old.date()
|
2014-08-16 05:43:59 +04:00
|
|
|
editform = mergeeditform(old, 'commit.amend')
|
2014-08-02 16:46:27 +04:00
|
|
|
editor = getcommiteditor(editform=editform, **opts)
|
2012-08-25 18:20:41 +04:00
|
|
|
if not message:
|
2014-08-02 16:46:27 +04:00
|
|
|
editor = getcommiteditor(edit=True, editform=editform)
|
2012-08-25 18:20:41 +04:00
|
|
|
message = old.description()
|
2012-09-11 01:44:24 +04:00
|
|
|
|
2012-10-19 00:12:15 +04:00
|
|
|
pureextra = extra.copy()
|
|
|
|
extra['amend_source'] = old.hex()
|
|
|
|
|
2012-09-11 01:44:24 +04:00
|
|
|
new = context.memctx(repo,
|
2013-02-09 01:08:34 +04:00
|
|
|
parents=[base.node(), old.p2().node()],
|
2012-09-11 01:44:24 +04:00
|
|
|
text=message,
|
|
|
|
files=files,
|
|
|
|
filectxfn=filectxfn,
|
|
|
|
user=user,
|
|
|
|
date=date,
|
2014-05-05 16:26:40 +04:00
|
|
|
extra=extra,
|
|
|
|
editor=editor)
|
2012-10-19 00:12:15 +04:00
|
|
|
|
2015-12-31 11:16:59 +03:00
|
|
|
newdesc = changelog.stripdesc(new.description())
|
2012-10-19 00:12:15 +04:00
|
|
|
if ((not node)
|
|
|
|
and newdesc == old.description()
|
|
|
|
and user == old.user()
|
|
|
|
and date == old.date()
|
2016-02-03 19:59:46 +03:00
|
|
|
and pureextra == old.extra()):
|
2012-10-19 00:12:15 +04:00
|
|
|
# nothing changed. continuing here would create a new node
|
|
|
|
# anyway because of the amend_source noise.
|
|
|
|
#
|
|
|
|
# This not what we expect from amend.
|
|
|
|
return old.node()
|
|
|
|
|
2012-09-11 01:44:24 +04:00
|
|
|
ph = repo.ui.config('phases', 'new-commit', phases.draft)
|
|
|
|
try:
|
2014-03-13 14:48:41 +04:00
|
|
|
if opts.get('secret'):
|
|
|
|
commitphase = 'secret'
|
|
|
|
else:
|
|
|
|
commitphase = old.phase()
|
2014-03-19 05:45:14 +04:00
|
|
|
repo.ui.setconfig('phases', 'new-commit', commitphase, 'amend')
|
2012-09-11 01:44:24 +04:00
|
|
|
newid = repo.commitctx(new)
|
|
|
|
finally:
|
2014-03-19 05:45:14 +04:00
|
|
|
repo.ui.setconfig('phases', 'new-commit', ph, 'amend')
|
2012-09-11 01:44:24 +04:00
|
|
|
if newid != old.node():
|
|
|
|
# Reroute the working copy parent to the new changeset
|
|
|
|
repo.setparents(newid, nullid)
|
|
|
|
|
|
|
|
# Move bookmarks from old parent to amend commit
|
|
|
|
bms = repo.nodebookmarks(old.node())
|
|
|
|
if bms:
|
2012-11-08 02:21:39 +04:00
|
|
|
marks = repo._bookmarks
|
2012-09-11 01:44:24 +04:00
|
|
|
for bm in bms:
|
2015-07-01 08:39:28 +03:00
|
|
|
ui.debug('moving bookmarks %r from %s to %s\n' %
|
|
|
|
(marks, old.hex(), hex(newid)))
|
2012-11-08 02:21:39 +04:00
|
|
|
marks[bm] = newid
|
2015-07-01 08:36:49 +03:00
|
|
|
marks.recordchange(tr)
|
2014-09-28 12:09:16 +04:00
|
|
|
#commit the whole amend process
|
|
|
|
if createmarkers:
|
|
|
|
# mark the new changeset as successor of the rewritten one
|
|
|
|
new = repo[newid]
|
|
|
|
obs = [(old, (new,))]
|
|
|
|
if node:
|
|
|
|
obs.append((ctx, ()))
|
|
|
|
|
|
|
|
obsolete.createmarkers(repo, obs)
|
2014-10-15 00:23:52 +04:00
|
|
|
if not createmarkers and newid != old.node():
|
2012-09-11 02:12:07 +04:00
|
|
|
# Strip the intermediate commit (if there was one) and the amended
|
|
|
|
# commit
|
2012-08-25 17:37:28 +04:00
|
|
|
if node:
|
|
|
|
ui.note(_('stripping intermediate changeset %s\n') % ctx)
|
|
|
|
ui.note(_('stripping amended changeset %s\n') % old)
|
|
|
|
repair.strip(ui, repo, old.node(), topic='amend-backup')
|
2012-04-18 02:20:16 +04:00
|
|
|
finally:
|
2015-10-08 21:53:46 +03:00
|
|
|
lockmod.release(lock, wlock)
|
2012-04-18 02:20:16 +04:00
|
|
|
return newid
|
|
|
|
|
2014-08-02 16:46:26 +04:00
|
|
|
def commiteditor(repo, ctx, subs, editform=''):
|
2009-05-14 22:20:40 +04:00
|
|
|
if ctx.description():
|
|
|
|
return ctx.description()
|
2015-10-10 07:44:54 +03:00
|
|
|
return commitforceeditor(repo, ctx, subs, editform=editform,
|
|
|
|
unchangedmessagedetection=True)
|
2009-05-14 22:20:40 +04:00
|
|
|
|
2014-08-02 16:46:26 +04:00
|
|
|
def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None,
|
2015-10-10 07:44:54 +03:00
|
|
|
editform='', unchangedmessagedetection=False):
|
2014-07-19 08:15:28 +04:00
|
|
|
if not extramsg:
|
|
|
|
extramsg = _("Leave message empty to abort commit.")
|
2014-08-02 16:46:27 +04:00
|
|
|
|
|
|
|
forms = [e for e in editform.split('.') if e]
|
|
|
|
forms.insert(0, 'changeset')
|
2015-10-10 07:44:54 +03:00
|
|
|
templatetext = None
|
2014-08-02 16:46:27 +04:00
|
|
|
while forms:
|
|
|
|
tmpl = repo.ui.config('committemplate', '.'.join(forms))
|
|
|
|
if tmpl:
|
2015-10-10 07:44:54 +03:00
|
|
|
templatetext = committext = buildcommittemplate(
|
|
|
|
repo, ctx, subs, extramsg, tmpl)
|
2014-08-02 16:46:27 +04:00
|
|
|
break
|
|
|
|
forms.pop()
|
2014-07-15 18:34:13 +04:00
|
|
|
else:
|
|
|
|
committext = buildcommittext(repo, ctx, subs, extramsg)
|
2014-07-14 19:59:09 +04:00
|
|
|
|
|
|
|
# run editor in the repository root
|
|
|
|
olddir = os.getcwd()
|
|
|
|
os.chdir(repo.root)
|
2015-10-10 07:44:54 +03:00
|
|
|
|
cmdutil: make in-memory changes visible to external editor (issue4378)
Before this patch, external editor process for the commit log can't
view some in-memory changes (especially, of dirstate), because they
aren't written out until the end of transaction (or wlock).
This causes unexpected output of Mercurial commands spawned from that
editor process.
To make in-memory changes visible to external editor process, this
patch does:
- write (or schedule to write) in-memory dirstate changes, and
- set HG_PENDING environment variable, if:
- a transaction is running, and
- there are in-memory changes to be visible
"hg diff" spawned from external editor process for "hg qrefresh"
shows:
- "changes newly imported into the topmost" before ab68b153ce34(*)
- "all changes recorded in the topmost by refreshing" after this patch
(*) ab68b153ce34 changed steps invoking editor process
Even though backward compatibility may be broken, the latter behavior
looks reasonable, because "hg diff" spawned from the editor process
consistently shows "what changes new revision records" regardless of
invocation context.
In fact, issue4378 itself should be resolved by b46029eb5b29, which
made 'repo.transaction()' write in-memory dirstate changes out
explicitly before starting transaction. It also made "hg qrefresh"
imply 'dirstate.write()' before external editor invocation in call
chain below.
- mq.queue.refresh
- strip.strip
- repair.strip
- localrepository.transaction
- dirstate.write
- localrepository.commit
- invoke external editor
Though, this patch has '(issue4378)' in own summary line to indicate
that issues like issue4378 should be fixed by this.
BTW, this patch adds '-m' option to a 'hg ci --amend' execution in
'test-commit-amend.t', to avoid invoking external editor process.
In this case, "unsure" states may be changed to "clean" according to
timestamp or so on. These changes should be written into pending file,
if external editor invocation is required,
Then, writing dirstate changes out breaks stability of test, because
it shows "transaction abort!/rollback completed" occasionally.
Aborting after editor process invocation while commands below may
cause similar instability of tests, too (AFAIK, there is no more such
one, at this revision)
- commit --amend
- without --message/--logfile
- import
- without --message/--logfile,
- without --no-commit,
- without --bypass,
- one of below, and
- patch has no description text, or
- with --edit
- aborting at the 1st patch, which adds or removes file(s)
- if it only changes existing files, status is checked only for
changed files by 'scmutil.matchfiles()', and transition from
"unsure" to "normal" in dirstate doesn't occur (= dirstate
isn't changed, and written out)
- aborting at the 2nd or later patch implies other pending
changes (e.g. changelog), and always causes showing
"transaction abort!/rollback completed"
2015-10-16 19:15:34 +03:00
|
|
|
# make in-memory changes visible to external process
|
|
|
|
tr = repo.currenttransaction()
|
|
|
|
repo.dirstate.write(tr)
|
|
|
|
pending = tr and tr.writepending() and repo.root
|
|
|
|
|
|
|
|
editortext = repo.ui.edit(committext, ctx.user(), ctx.extra(),
|
|
|
|
editform=editform, pending=pending)
|
2015-10-10 07:44:54 +03:00
|
|
|
text = re.sub("(?m)^HG:.*(\n|$)", "", editortext)
|
2014-07-14 19:59:09 +04:00
|
|
|
os.chdir(olddir)
|
|
|
|
|
|
|
|
if finishdesc:
|
|
|
|
text = finishdesc(text)
|
|
|
|
if not text.strip():
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_("empty commit message"))
|
2015-10-10 07:44:54 +03:00
|
|
|
if unchangedmessagedetection and editortext == templatetext:
|
|
|
|
raise error.Abort(_("commit message unchanged"))
|
2014-07-14 19:59:09 +04:00
|
|
|
|
|
|
|
return text
|
|
|
|
|
2014-07-15 18:34:13 +04:00
|
|
|
def buildcommittemplate(repo, ctx, subs, extramsg, tmpl):
|
|
|
|
ui = repo.ui
|
|
|
|
tmpl, mapfile = gettemplate(ui, tmpl, None)
|
|
|
|
|
2016-03-26 12:01:04 +03:00
|
|
|
t = changeset_templater(ui, repo, None, {}, tmpl, mapfile, False)
|
2014-07-15 18:34:13 +04:00
|
|
|
|
2014-08-02 16:46:27 +04:00
|
|
|
for k, v in repo.ui.configitems('committemplate'):
|
|
|
|
if k != 'changeset':
|
|
|
|
t.t.cache[k] = v
|
|
|
|
|
2014-07-15 18:34:13 +04:00
|
|
|
if not extramsg:
|
|
|
|
extramsg = '' # ensure that extramsg is string
|
|
|
|
|
|
|
|
ui.pushbuffer()
|
|
|
|
t.show(ctx, extramsg=extramsg)
|
|
|
|
return ui.popbuffer()
|
|
|
|
|
2015-09-30 19:36:30 +03:00
|
|
|
def hgprefix(msg):
|
|
|
|
return "\n".join(["HG: %s" % a for a in msg.split("\n") if a])
|
|
|
|
|
2014-07-14 19:59:09 +04:00
|
|
|
def buildcommittext(repo, ctx, subs, extramsg):
|
2009-05-14 22:20:40 +04:00
|
|
|
edittext = []
|
2009-06-01 23:51:47 +04:00
|
|
|
modified, added, removed = ctx.modified(), ctx.added(), ctx.removed()
|
2009-05-14 22:20:40 +04:00
|
|
|
if ctx.description():
|
|
|
|
edittext.append(ctx.description())
|
|
|
|
edittext.append("")
|
|
|
|
edittext.append("") # Empty line between message and comments.
|
2015-09-30 19:36:30 +03:00
|
|
|
edittext.append(hgprefix(_("Enter commit message."
|
|
|
|
" Lines beginning with 'HG:' are removed.")))
|
|
|
|
edittext.append(hgprefix(extramsg))
|
2009-05-14 22:20:40 +04:00
|
|
|
edittext.append("HG: --")
|
2015-09-30 19:36:30 +03:00
|
|
|
edittext.append(hgprefix(_("user: %s") % ctx.user()))
|
2009-05-14 22:20:40 +04:00
|
|
|
if ctx.p2():
|
2015-09-30 19:36:30 +03:00
|
|
|
edittext.append(hgprefix(_("branch merge")))
|
2009-05-14 22:20:40 +04:00
|
|
|
if ctx.branch():
|
2015-09-30 19:36:30 +03:00
|
|
|
edittext.append(hgprefix(_("branch '%s'") % ctx.branch()))
|
2015-04-14 22:45:15 +03:00
|
|
|
if bookmarks.isactivewdirparent(repo):
|
2015-09-30 19:36:30 +03:00
|
|
|
edittext.append(hgprefix(_("bookmark '%s'") % repo._activebookmark))
|
|
|
|
edittext.extend([hgprefix(_("subrepo %s") % s) for s in subs])
|
|
|
|
edittext.extend([hgprefix(_("added %s") % f) for f in added])
|
|
|
|
edittext.extend([hgprefix(_("changed %s") % f) for f in modified])
|
|
|
|
edittext.extend([hgprefix(_("removed %s") % f) for f in removed])
|
2009-06-01 23:51:47 +04:00
|
|
|
if not added and not modified and not removed:
|
2015-09-30 19:36:30 +03:00
|
|
|
edittext.append(hgprefix(_("no files changed")))
|
2009-05-14 22:20:40 +04:00
|
|
|
edittext.append("")
|
|
|
|
|
2014-07-14 19:59:09 +04:00
|
|
|
return "\n".join(edittext)
|
2011-05-12 10:14:04 +04:00
|
|
|
|
2015-09-24 11:58:33 +03:00
|
|
|
def commitstatus(repo, node, branch, bheads=None, opts=None):
|
|
|
|
if opts is None:
|
|
|
|
opts = {}
|
2013-02-12 20:32:14 +04:00
|
|
|
ctx = repo[node]
|
|
|
|
parents = ctx.parents()
|
|
|
|
|
|
|
|
if (not opts.get('amend') and bheads and node not in bheads and not
|
|
|
|
[x for x in parents if x.node() in bheads and x.branch() == branch]):
|
|
|
|
repo.ui.status(_('created new head\n'))
|
|
|
|
# The message is not printed for initial roots. For the other
|
|
|
|
# changesets, it is printed in the following situations:
|
|
|
|
#
|
|
|
|
# Par column: for the 2 parents with ...
|
|
|
|
# N: null or no parent
|
|
|
|
# B: parent is on another named branch
|
|
|
|
# C: parent is a regular non head changeset
|
|
|
|
# H: parent was a branch head of the current branch
|
|
|
|
# Msg column: whether we print "created new head" message
|
|
|
|
# In the following, it is assumed that there already exists some
|
|
|
|
# initial branch heads of the current branch, otherwise nothing is
|
|
|
|
# printed anyway.
|
|
|
|
#
|
|
|
|
# Par Msg Comment
|
|
|
|
# N N y additional topo root
|
|
|
|
#
|
|
|
|
# B N y additional branch root
|
|
|
|
# C N y additional topo head
|
|
|
|
# H N n usual case
|
|
|
|
#
|
|
|
|
# B B y weird additional branch root
|
|
|
|
# C B y branch merge
|
|
|
|
# H B n merge with named branch
|
|
|
|
#
|
|
|
|
# C C y additional head from merge
|
|
|
|
# C H n merge with a head
|
|
|
|
#
|
|
|
|
# H H n head merge: head count decreases
|
|
|
|
|
|
|
|
if not opts.get('close_branch'):
|
|
|
|
for r in parents:
|
|
|
|
if r.closesbranch() and r.branch() == branch:
|
|
|
|
repo.ui.status(_('reopening closed branch head %d\n') % r)
|
|
|
|
|
|
|
|
if repo.ui.debugflag:
|
|
|
|
repo.ui.write(_('committed changeset %d:%s\n') % (int(ctx), ctx.hex()))
|
|
|
|
elif repo.ui.verbose:
|
|
|
|
repo.ui.write(_('committed changeset %d:%s\n') % (int(ctx), ctx))
|
|
|
|
|
2016-01-24 07:24:30 +03:00
|
|
|
def postcommitstatus(repo, pats, opts):
|
|
|
|
return repo.status(match=scmutil.match(repo[None], pats, opts))
|
|
|
|
|
2012-03-28 13:42:17 +04:00
|
|
|
def revert(ui, repo, ctx, parents, *pats, **opts):
|
|
|
|
parent, p2 = parents
|
|
|
|
node = ctx.node()
|
|
|
|
|
|
|
|
mf = ctx.manifest()
|
2014-05-14 21:38:05 +04:00
|
|
|
if node == p2:
|
|
|
|
parent = p2
|
2012-03-28 13:42:17 +04:00
|
|
|
|
|
|
|
# need all matching names in dirstate and manifest of target rev,
|
|
|
|
# so have to walk both. do not print errors if files exist in one
|
2015-01-17 08:22:21 +03:00
|
|
|
# but not other. in both cases, filesets should be evaluated against
|
|
|
|
# workingctx to get consistent result (issue4497). this means 'set:**'
|
|
|
|
# cannot be used to select missing files from target rev.
|
2012-03-28 13:42:17 +04:00
|
|
|
|
2014-05-14 03:29:42 +04:00
|
|
|
# `names` is a mapping for all elements in working copy and target revision
|
|
|
|
# The mapping is in the form:
|
|
|
|
# <asb path in repo> -> (<path from CWD>, <exactly specified by matcher?>)
|
2012-03-28 13:42:17 +04:00
|
|
|
names = {}
|
|
|
|
|
2016-01-16 00:14:46 +03:00
|
|
|
with repo.wlock():
|
2014-05-14 03:29:42 +04:00
|
|
|
## filling of the `names` mapping
|
|
|
|
# walk dirstate to fill `names`
|
2012-03-28 13:42:17 +04:00
|
|
|
|
2015-03-26 00:01:14 +03:00
|
|
|
interactive = opts.get('interactive', False)
|
2015-03-24 23:56:51 +03:00
|
|
|
wctx = repo[None]
|
|
|
|
m = scmutil.match(wctx, pats, opts)
|
2015-03-27 21:48:51 +03:00
|
|
|
|
|
|
|
# we'll need this later
|
|
|
|
targetsubs = sorted(s for s in wctx.substate if m(s))
|
|
|
|
|
2015-03-25 01:47:57 +03:00
|
|
|
if not m.always():
|
2015-06-05 05:02:22 +03:00
|
|
|
for abs in repo.walk(matchmod.badmatch(m, lambda x, y: False)):
|
2014-09-20 05:43:53 +04:00
|
|
|
names[abs] = m.rel(abs), m.exact(abs)
|
2012-03-28 13:42:17 +04:00
|
|
|
|
2014-09-20 05:43:53 +04:00
|
|
|
# walk target manifest to fill `names`
|
2012-03-28 13:42:17 +04:00
|
|
|
|
2014-09-20 05:43:53 +04:00
|
|
|
def badfn(path, msg):
|
|
|
|
if path in names:
|
2012-03-28 13:42:17 +04:00
|
|
|
return
|
2014-09-20 05:43:53 +04:00
|
|
|
if path in ctx.substate:
|
|
|
|
return
|
|
|
|
path_ = path + '/'
|
|
|
|
for f in names:
|
|
|
|
if f.startswith(path_):
|
|
|
|
return
|
|
|
|
ui.warn("%s: %s\n" % (m.rel(path), msg))
|
|
|
|
|
2015-06-05 05:02:22 +03:00
|
|
|
for abs in ctx.walk(matchmod.badmatch(m, badfn)):
|
2014-09-20 05:43:53 +04:00
|
|
|
if abs not in names:
|
|
|
|
names[abs] = m.rel(abs), m.exact(abs)
|
|
|
|
|
|
|
|
# Find status of all file in `names`.
|
|
|
|
m = scmutil.matchfiles(repo, names)
|
|
|
|
|
|
|
|
changes = repo.status(node1=node, match=m,
|
|
|
|
unknown=True, ignored=True, clean=True)
|
|
|
|
else:
|
2015-03-25 01:47:57 +03:00
|
|
|
changes = repo.status(node1=node, match=m)
|
2014-09-20 05:43:53 +04:00
|
|
|
for kind in changes:
|
|
|
|
for abs in kind:
|
|
|
|
names[abs] = m.rel(abs), m.exact(abs)
|
2012-03-28 13:42:17 +04:00
|
|
|
|
2014-09-20 05:43:53 +04:00
|
|
|
m = scmutil.matchfiles(repo, names)
|
2014-06-24 18:47:12 +04:00
|
|
|
|
2014-11-20 04:07:27 +03:00
|
|
|
modified = set(changes.modified)
|
|
|
|
added = set(changes.added)
|
|
|
|
removed = set(changes.removed)
|
|
|
|
_deleted = set(changes.deleted)
|
|
|
|
unknown = set(changes.unknown)
|
|
|
|
unknown.update(changes.ignored)
|
|
|
|
clean = set(changes.clean)
|
2014-08-30 04:39:08 +04:00
|
|
|
modadded = set()
|
2014-08-02 05:57:53 +04:00
|
|
|
|
|
|
|
# split between files known in target manifest and the others
|
|
|
|
smf = set(mf)
|
|
|
|
|
|
|
|
# determine the exact nature of the deleted changesets
|
2014-08-30 04:23:25 +04:00
|
|
|
deladded = _deleted - smf
|
|
|
|
deleted = _deleted - deladded
|
2014-06-24 18:47:12 +04:00
|
|
|
|
2015-01-18 04:38:57 +03:00
|
|
|
# We need to account for the state of the file in the dirstate,
|
|
|
|
# even when we revert against something else than parent. This will
|
2014-06-24 18:47:12 +04:00
|
|
|
# slightly alter the behavior of revert (doing back up or not, delete
|
2014-04-18 00:47:38 +04:00
|
|
|
# or just forget etc).
|
2014-06-24 18:47:12 +04:00
|
|
|
if parent == node:
|
|
|
|
dsmodified = modified
|
|
|
|
dsadded = added
|
|
|
|
dsremoved = removed
|
2014-11-26 06:40:54 +03:00
|
|
|
# store all local modifications, useful later for rename detection
|
|
|
|
localchanges = dsmodified | dsadded
|
2014-06-24 18:47:12 +04:00
|
|
|
modified, added, removed = set(), set(), set()
|
|
|
|
else:
|
|
|
|
changes = repo.status(node1=parent, match=m)
|
2014-11-20 04:07:27 +03:00
|
|
|
dsmodified = set(changes.modified)
|
|
|
|
dsadded = set(changes.added)
|
|
|
|
dsremoved = set(changes.removed)
|
2014-11-26 06:40:54 +03:00
|
|
|
# store all local modifications, useful later for rename detection
|
|
|
|
localchanges = dsmodified | dsadded
|
2012-03-28 13:42:17 +04:00
|
|
|
|
2014-06-24 19:53:22 +04:00
|
|
|
# only take into account for removes between wc and target
|
|
|
|
clean |= dsremoved - removed
|
|
|
|
dsremoved &= removed
|
|
|
|
# distinct between dirstate remove and other
|
|
|
|
removed -= dsremoved
|
|
|
|
|
2014-08-30 04:39:08 +04:00
|
|
|
modadded = added & dsmodified
|
|
|
|
added -= modadded
|
|
|
|
|
2014-06-24 20:27:18 +04:00
|
|
|
# tell newly modified apart.
|
|
|
|
dsmodified &= modified
|
|
|
|
dsmodified |= modified & dsadded # dirstate added may needs backup
|
|
|
|
modified -= dsmodified
|
|
|
|
|
2014-08-30 20:20:29 +04:00
|
|
|
# We need to wait for some post-processing to update this set
|
|
|
|
# before making the distinction. The dirstate will be used for
|
|
|
|
# that purpose.
|
2014-08-02 22:32:24 +04:00
|
|
|
dsadded = added
|
|
|
|
|
2014-06-24 20:28:20 +04:00
|
|
|
# in case of merge, files that are actually added can be reported as
|
|
|
|
# modified, we need to post process the result
|
|
|
|
if p2 != nullid:
|
2016-02-23 13:41:47 +03:00
|
|
|
mergeadd = dsmodified - smf
|
2014-06-24 20:28:20 +04:00
|
|
|
dsadded |= mergeadd
|
|
|
|
dsmodified -= mergeadd
|
|
|
|
|
2014-05-14 03:29:42 +04:00
|
|
|
# if f is a rename, update `names` to also revert the source
|
2012-03-28 13:42:17 +04:00
|
|
|
cwd = repo.getcwd()
|
2014-11-26 06:40:54 +03:00
|
|
|
for f in localchanges:
|
2012-03-28 13:42:17 +04:00
|
|
|
src = repo.dirstate.copied(f)
|
2014-06-24 19:59:40 +04:00
|
|
|
# XXX should we check for rename down to target node?
|
2012-03-28 13:42:17 +04:00
|
|
|
if src and src not in names and repo.dirstate[src] == 'r':
|
2014-06-24 18:35:43 +04:00
|
|
|
dsremoved.add(src)
|
2012-03-28 13:42:17 +04:00
|
|
|
names[src] = (repo.pathto(src, cwd), True)
|
|
|
|
|
2014-08-30 20:20:29 +04:00
|
|
|
# distinguish between file to forget and the other
|
|
|
|
added = set()
|
|
|
|
for abs in dsadded:
|
|
|
|
if repo.dirstate[abs] != 'a':
|
|
|
|
added.add(abs)
|
|
|
|
dsadded -= added
|
|
|
|
|
2014-08-30 04:23:25 +04:00
|
|
|
for abs in deladded:
|
|
|
|
if repo.dirstate[abs] == 'a':
|
|
|
|
dsadded.add(abs)
|
|
|
|
deladded -= dsadded
|
|
|
|
|
2014-08-30 04:00:20 +04:00
|
|
|
# For files marked as removed, we check if an unknown file is present at
|
|
|
|
# the same path. If a such file exists it may need to be backed up.
|
|
|
|
# Making the distinction at this stage helps have simpler backup
|
|
|
|
# logic.
|
|
|
|
removunk = set()
|
|
|
|
for abs in removed:
|
|
|
|
target = repo.wjoin(abs)
|
|
|
|
if os.path.lexists(target):
|
|
|
|
removunk.add(abs)
|
|
|
|
removed -= removunk
|
|
|
|
|
|
|
|
dsremovunk = set()
|
|
|
|
for abs in dsremoved:
|
|
|
|
target = repo.wjoin(abs)
|
|
|
|
if os.path.lexists(target):
|
|
|
|
dsremovunk.add(abs)
|
|
|
|
dsremoved -= dsremovunk
|
|
|
|
|
2014-05-14 03:29:42 +04:00
|
|
|
# action to be actually performed by revert
|
|
|
|
# (<list of file>, message>) tuple
|
2014-05-14 03:42:31 +04:00
|
|
|
actions = {'revert': ([], _('reverting %s\n')),
|
|
|
|
'add': ([], _('adding %s\n')),
|
2014-09-01 14:36:48 +04:00
|
|
|
'remove': ([], _('removing %s\n')),
|
2014-08-30 04:25:23 +04:00
|
|
|
'drop': ([], _('removing %s\n')),
|
2014-09-01 14:36:48 +04:00
|
|
|
'forget': ([], _('forgetting %s\n')),
|
2014-08-02 23:45:34 +04:00
|
|
|
'undelete': ([], _('undeleting %s\n')),
|
2014-08-03 00:07:01 +04:00
|
|
|
'noop': (None, _('no changes needed to %s\n')),
|
2014-06-25 03:01:30 +04:00
|
|
|
'unknown': (None, _('file not managed: %s\n')),
|
2014-08-02 23:45:34 +04:00
|
|
|
}
|
2012-03-28 13:42:17 +04:00
|
|
|
|
2014-08-30 04:28:27 +04:00
|
|
|
# "constant" that convey the backup strategy.
|
|
|
|
# All set to `discard` if `no-backup` is set do avoid checking
|
|
|
|
# no_backup lower in the code.
|
2014-08-30 04:30:24 +04:00
|
|
|
# These values are ordered for comparison purposes
|
2014-08-30 04:28:27 +04:00
|
|
|
backup = 2 # unconditionally do backup
|
2014-08-30 04:30:24 +04:00
|
|
|
check = 1 # check if the existing file differs from target
|
2014-08-30 04:28:27 +04:00
|
|
|
discard = 0 # never do backup
|
|
|
|
if opts.get('no_backup'):
|
2014-08-30 04:30:24 +04:00
|
|
|
backup = check = discard
|
2014-06-24 20:54:33 +04:00
|
|
|
|
2014-08-31 15:01:00 +04:00
|
|
|
backupanddel = actions['remove']
|
|
|
|
if not opts.get('no_backup'):
|
|
|
|
backupanddel = actions['drop']
|
|
|
|
|
2012-03-28 13:42:17 +04:00
|
|
|
disptable = (
|
|
|
|
# dispatch table:
|
|
|
|
# file state
|
2014-06-24 18:28:22 +04:00
|
|
|
# action
|
|
|
|
# make backup
|
2014-08-30 03:48:58 +04:00
|
|
|
|
|
|
|
## Sets that results that will change file on disk
|
|
|
|
# Modified compared to target, no local change
|
2014-08-30 18:06:09 +04:00
|
|
|
(modified, actions['revert'], discard),
|
2014-08-30 04:09:53 +04:00
|
|
|
# Modified compared to target, but local file is deleted
|
|
|
|
(deleted, actions['revert'], discard),
|
2014-08-30 03:48:58 +04:00
|
|
|
# Modified compared to target, local change
|
2014-08-30 18:06:09 +04:00
|
|
|
(dsmodified, actions['revert'], backup),
|
2014-08-30 03:48:58 +04:00
|
|
|
# Added since target
|
2014-08-30 20:20:29 +04:00
|
|
|
(added, actions['remove'], discard),
|
|
|
|
# Added in working directory
|
2014-09-01 14:36:48 +04:00
|
|
|
(dsadded, actions['forget'], discard),
|
2014-08-30 04:39:08 +04:00
|
|
|
# Added since target, have local modification
|
2014-08-31 15:01:00 +04:00
|
|
|
(modadded, backupanddel, backup),
|
2014-08-30 04:23:25 +04:00
|
|
|
# Added since target but file is missing in working directory
|
2014-08-30 04:25:23 +04:00
|
|
|
(deladded, actions['drop'], discard),
|
2014-08-30 03:48:58 +04:00
|
|
|
# Removed since target, before working copy parent
|
2014-08-30 04:00:20 +04:00
|
|
|
(removed, actions['add'], discard),
|
|
|
|
# Same as `removed` but an unknown file exists at the same path
|
2014-08-30 04:30:24 +04:00
|
|
|
(removunk, actions['add'], check),
|
2014-08-30 03:48:58 +04:00
|
|
|
# Removed since targe, marked as such in working copy parent
|
2014-08-30 04:00:20 +04:00
|
|
|
(dsremoved, actions['undelete'], discard),
|
|
|
|
# Same as `dsremoved` but an unknown file exists at the same path
|
2014-08-30 04:30:24 +04:00
|
|
|
(dsremovunk, actions['undelete'], check),
|
2014-08-30 03:48:58 +04:00
|
|
|
## the following sets does not result in any file changes
|
|
|
|
# File with no modification
|
2014-08-30 18:06:09 +04:00
|
|
|
(clean, actions['noop'], discard),
|
2014-08-30 03:48:58 +04:00
|
|
|
# Existing file, not tracked anywhere
|
2014-08-30 18:06:09 +04:00
|
|
|
(unknown, actions['unknown'], discard),
|
2012-03-28 13:42:17 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
for abs, (rel, exact) in sorted(names.items()):
|
2014-05-14 03:29:42 +04:00
|
|
|
# target file to be touch on disk (relative to cwd)
|
2012-03-28 13:42:17 +04:00
|
|
|
target = repo.wjoin(abs)
|
2014-06-24 20:39:43 +04:00
|
|
|
# search the entry in the dispatch table.
|
|
|
|
# if the file is in any of these sets, it was touched in the working
|
|
|
|
# directory parent and we are sure it needs to be reverted.
|
2014-06-24 21:04:13 +04:00
|
|
|
for table, (xlist, msg), dobackup in disptable:
|
2014-06-24 20:39:43 +04:00
|
|
|
if abs not in table:
|
|
|
|
continue
|
2014-08-01 22:41:56 +04:00
|
|
|
if xlist is not None:
|
|
|
|
xlist.append(abs)
|
2014-08-30 04:30:24 +04:00
|
|
|
if dobackup and (backup <= dobackup
|
|
|
|
or wctx[abs].cmp(ctx[abs])):
|
2016-01-02 14:02:57 +03:00
|
|
|
bakname = scmutil.origpath(ui, repo, rel)
|
2014-08-30 04:30:24 +04:00
|
|
|
ui.note(_('saving current version of %s as %s\n') %
|
|
|
|
(rel, bakname))
|
|
|
|
if not opts.get('dry_run'):
|
2015-03-26 00:01:14 +03:00
|
|
|
if interactive:
|
|
|
|
util.copyfile(target, bakname)
|
|
|
|
else:
|
|
|
|
util.rename(target, bakname)
|
2014-08-01 22:41:56 +04:00
|
|
|
if ui.verbose or not exact:
|
|
|
|
if not isinstance(msg, basestring):
|
|
|
|
msg = msg(abs)
|
|
|
|
ui.status(msg % rel)
|
|
|
|
elif exact:
|
2014-08-03 00:07:01 +04:00
|
|
|
ui.warn(msg % rel)
|
2012-03-28 13:42:17 +04:00
|
|
|
break
|
2014-05-14 03:29:42 +04:00
|
|
|
|
2012-03-28 13:42:17 +04:00
|
|
|
if not opts.get('dry_run'):
|
2015-01-28 06:52:26 +03:00
|
|
|
needdata = ('revert', 'add', 'undelete')
|
|
|
|
_revertprefetch(repo, ctx, *[actions[name][0] for name in needdata])
|
2015-03-17 02:33:59 +03:00
|
|
|
_performrevert(repo, parents, ctx, actions, interactive)
|
2013-05-03 23:40:17 +04:00
|
|
|
|
2015-02-08 05:47:28 +03:00
|
|
|
if targetsubs:
|
|
|
|
# Revert the subrepos on the revert list
|
|
|
|
for sub in targetsubs:
|
2015-03-26 04:54:47 +03:00
|
|
|
try:
|
2015-03-26 05:20:44 +03:00
|
|
|
wctx.sub(sub).revert(ctx.substate[sub], *pats, **opts)
|
2015-03-26 04:54:47 +03:00
|
|
|
except KeyError:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort("subrepository '%s' does not exist in %s!"
|
2015-03-26 04:54:47 +03:00
|
|
|
% (sub, short(ctx.node())))
|
2012-03-28 13:42:17 +04:00
|
|
|
|
2014-08-30 04:47:59 +04:00
|
|
|
def _revertprefetch(repo, ctx, *files):
|
|
|
|
"""Let extension changing the storage layer prefetch content"""
|
|
|
|
pass
|
|
|
|
|
2015-03-17 02:33:59 +03:00
|
|
|
def _performrevert(repo, parents, ctx, actions, interactive=False):
|
2014-05-14 03:42:31 +04:00
|
|
|
"""function that actually perform all the actions computed for revert
|
2014-02-27 06:56:27 +04:00
|
|
|
|
|
|
|
This is an independent function to let extension to plug in and react to
|
|
|
|
the imminent revert.
|
|
|
|
|
2014-04-13 21:01:00 +04:00
|
|
|
Make sure you have the working directory locked when calling this function.
|
2014-02-27 06:56:27 +04:00
|
|
|
"""
|
|
|
|
parent, p2 = parents
|
|
|
|
node = ctx.node()
|
2016-02-05 17:18:40 +03:00
|
|
|
excluded_files = []
|
|
|
|
matcher_opts = {"exclude": excluded_files}
|
|
|
|
|
2014-02-27 06:56:27 +04:00
|
|
|
def checkout(f):
|
|
|
|
fc = ctx[f]
|
2015-07-08 11:01:09 +03:00
|
|
|
repo.wwrite(f, fc.data(), fc.flags())
|
2014-02-27 06:56:27 +04:00
|
|
|
|
|
|
|
audit_path = pathutil.pathauditor(repo.root)
|
2014-09-01 14:36:48 +04:00
|
|
|
for f in actions['forget'][0]:
|
2016-02-05 17:18:40 +03:00
|
|
|
if interactive:
|
|
|
|
choice = \
|
|
|
|
repo.ui.promptchoice(
|
|
|
|
_("forget added file %s (yn)?$$ &Yes $$ &No")
|
|
|
|
% f)
|
|
|
|
if choice == 0:
|
|
|
|
repo.dirstate.drop(f)
|
|
|
|
else:
|
|
|
|
excluded_files.append(repo.wjoin(f))
|
|
|
|
else:
|
|
|
|
repo.dirstate.drop(f)
|
2014-05-14 03:42:31 +04:00
|
|
|
for f in actions['remove'][0]:
|
2014-02-27 06:56:27 +04:00
|
|
|
audit_path(f)
|
2015-04-26 06:54:31 +03:00
|
|
|
try:
|
|
|
|
util.unlinkpath(repo.wjoin(f))
|
|
|
|
except OSError:
|
|
|
|
pass
|
2014-08-30 04:25:23 +04:00
|
|
|
repo.dirstate.remove(f)
|
|
|
|
for f in actions['drop'][0]:
|
|
|
|
audit_path(f)
|
2014-02-27 06:56:27 +04:00
|
|
|
repo.dirstate.remove(f)
|
|
|
|
|
|
|
|
normal = None
|
|
|
|
if node == parent:
|
|
|
|
# We're reverting to our parent. If possible, we'd like status
|
|
|
|
# to report the file as clean. We have to use normallookup for
|
|
|
|
# merges to avoid losing information about merged/dirty files.
|
|
|
|
if p2 != nullid:
|
|
|
|
normal = repo.dirstate.normallookup
|
|
|
|
else:
|
|
|
|
normal = repo.dirstate.normal
|
2015-03-17 02:33:59 +03:00
|
|
|
|
2015-05-22 00:34:24 +03:00
|
|
|
newlyaddedandmodifiedfiles = set()
|
2015-03-17 02:33:59 +03:00
|
|
|
if interactive:
|
|
|
|
# Prompt the user for changes to revert
|
|
|
|
torevert = [repo.wjoin(f) for f in actions['revert'][0]]
|
2016-02-05 17:18:40 +03:00
|
|
|
m = scmutil.match(ctx, torevert, matcher_opts)
|
2015-05-22 00:25:57 +03:00
|
|
|
diffopts = patch.difffeatureopts(repo.ui, whitespace=True)
|
|
|
|
diffopts.nodates = True
|
|
|
|
diffopts.git = True
|
2015-12-31 11:16:59 +03:00
|
|
|
reversehunks = repo.ui.configbool('experimental',
|
|
|
|
'revertalternateinteractivemode',
|
|
|
|
True)
|
2015-05-29 23:11:52 +03:00
|
|
|
if reversehunks:
|
|
|
|
diff = patch.diff(repo, ctx.node(), None, m, opts=diffopts)
|
|
|
|
else:
|
|
|
|
diff = patch.diff(repo, None, ctx.node(), m, opts=diffopts)
|
2015-03-17 02:33:59 +03:00
|
|
|
originalchunks = patch.parsepatch(diff)
|
2015-05-29 23:11:52 +03:00
|
|
|
|
2015-03-17 02:33:59 +03:00
|
|
|
try:
|
2015-05-29 23:11:52 +03:00
|
|
|
|
2015-12-01 03:35:21 +03:00
|
|
|
chunks, opts = recordfilter(repo.ui, originalchunks)
|
2015-05-29 23:11:52 +03:00
|
|
|
if reversehunks:
|
|
|
|
chunks = patch.reversehunks(chunks)
|
|
|
|
|
2015-06-24 08:20:08 +03:00
|
|
|
except patch.PatchError as err:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('error parsing patch: %s') % err)
|
2015-03-17 02:33:59 +03:00
|
|
|
|
2015-05-22 00:34:24 +03:00
|
|
|
newlyaddedandmodifiedfiles = newandmodified(chunks, originalchunks)
|
2015-03-17 02:33:59 +03:00
|
|
|
# Apply changes
|
2016-04-10 23:55:37 +03:00
|
|
|
fp = stringio()
|
2015-03-17 02:33:59 +03:00
|
|
|
for c in chunks:
|
|
|
|
c.write(fp)
|
|
|
|
dopatch = fp.tell()
|
|
|
|
fp.seek(0)
|
|
|
|
if dopatch:
|
|
|
|
try:
|
|
|
|
patch.internalpatch(repo.ui, repo, fp, 1, eolmode=None)
|
2015-06-24 08:20:08 +03:00
|
|
|
except patch.PatchError as err:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(str(err))
|
2015-03-17 02:33:59 +03:00
|
|
|
del fp
|
|
|
|
else:
|
|
|
|
for f in actions['revert'][0]:
|
2015-07-08 11:01:09 +03:00
|
|
|
checkout(f)
|
2015-03-17 02:33:59 +03:00
|
|
|
if normal:
|
|
|
|
normal(f)
|
2014-02-27 06:56:27 +04:00
|
|
|
|
2014-05-14 03:42:31 +04:00
|
|
|
for f in actions['add'][0]:
|
2015-05-22 00:34:24 +03:00
|
|
|
# Don't checkout modified files, they are already created by the diff
|
|
|
|
if f not in newlyaddedandmodifiedfiles:
|
|
|
|
checkout(f)
|
|
|
|
repo.dirstate.add(f)
|
2014-02-27 06:56:27 +04:00
|
|
|
|
|
|
|
normal = repo.dirstate.normallookup
|
|
|
|
if node == parent and p2 == nullid:
|
|
|
|
normal = repo.dirstate.normal
|
2014-05-14 03:42:31 +04:00
|
|
|
for f in actions['undelete'][0]:
|
2014-02-27 06:56:27 +04:00
|
|
|
checkout(f)
|
|
|
|
normal(f)
|
|
|
|
|
|
|
|
copied = copies.pathcopies(repo[parent], ctx)
|
|
|
|
|
2014-05-14 03:42:31 +04:00
|
|
|
for f in actions['add'][0] + actions['undelete'][0] + actions['revert'][0]:
|
2014-02-27 06:56:27 +04:00
|
|
|
if f in copied:
|
|
|
|
repo.dirstate.copy(copied[f], f)
|
|
|
|
|
2011-05-12 10:14:04 +04:00
|
|
|
def command(table):
|
2014-05-05 05:45:04 +04:00
|
|
|
"""Returns a function object to be used as a decorator for making commands.
|
|
|
|
|
|
|
|
This function receives a command table as its argument. The table should
|
|
|
|
be a dict.
|
|
|
|
|
|
|
|
The returned function can be used as a decorator for adding commands
|
|
|
|
to that command table. This function accepts multiple arguments to define
|
|
|
|
a command.
|
|
|
|
|
|
|
|
The first argument is the command name.
|
|
|
|
|
|
|
|
The options argument is an iterable of tuples defining command arguments.
|
|
|
|
See ``mercurial.fancyopts.fancyopts()`` for the format of each tuple.
|
|
|
|
|
|
|
|
The synopsis argument defines a short, one line summary of how to use the
|
|
|
|
command. This shows up in the help output.
|
2011-05-12 10:14:04 +04:00
|
|
|
|
2014-05-05 07:58:25 +04:00
|
|
|
The norepo argument defines whether the command does not require a
|
|
|
|
local repository. Most commands operate against a repository, thus the
|
|
|
|
default is False.
|
2014-05-05 09:12:34 +04:00
|
|
|
|
|
|
|
The optionalrepo argument defines whether the command optionally requires
|
|
|
|
a local repository.
|
2014-05-05 09:20:00 +04:00
|
|
|
|
|
|
|
The inferrepo argument defines whether to try to find a repository from the
|
|
|
|
command line arguments. If True, arguments will be examined for potential
|
|
|
|
repository locations. See ``findrepo()``. If a repository is found, it
|
|
|
|
will be used.
|
2014-05-05 07:58:25 +04:00
|
|
|
"""
|
2014-05-05 09:20:00 +04:00
|
|
|
def cmd(name, options=(), synopsis=None, norepo=False, optionalrepo=False,
|
|
|
|
inferrepo=False):
|
2011-05-12 10:14:04 +04:00
|
|
|
def decorator(func):
|
2016-01-01 16:16:25 +03:00
|
|
|
func.norepo = norepo
|
|
|
|
func.optionalrepo = optionalrepo
|
|
|
|
func.inferrepo = inferrepo
|
2011-05-12 10:14:04 +04:00
|
|
|
if synopsis:
|
2013-01-04 16:48:07 +04:00
|
|
|
table[name] = func, list(options), synopsis
|
2011-05-12 10:14:04 +04:00
|
|
|
else:
|
2013-01-04 16:48:07 +04:00
|
|
|
table[name] = func, list(options)
|
2011-05-12 10:14:04 +04:00
|
|
|
return func
|
|
|
|
return decorator
|
|
|
|
|
|
|
|
return cmd
|
2013-05-14 22:23:15 +04:00
|
|
|
|
2014-04-15 19:37:24 +04:00
|
|
|
# a list of (ui, repo, otherpeer, opts, missing) functions called by
|
|
|
|
# commands.outgoing. "missing" is "missing" of the result of
|
|
|
|
# "findcommonoutgoing()"
|
|
|
|
outgoinghooks = util.hooks()
|
|
|
|
|
2013-05-14 22:23:15 +04:00
|
|
|
# a list of (ui, repo) functions called by commands.summary
|
|
|
|
summaryhooks = util.hooks()
|
2013-07-25 08:27:30 +04:00
|
|
|
|
2014-04-15 19:37:24 +04:00
|
|
|
# a list of (ui, repo, opts, changes) functions called by commands.summary.
|
|
|
|
#
|
|
|
|
# functions should return tuple of booleans below, if 'changes' is None:
|
|
|
|
# (whether-incomings-are-needed, whether-outgoings-are-needed)
|
|
|
|
#
|
|
|
|
# otherwise, 'changes' is a tuple of tuples below:
|
|
|
|
# - (sourceurl, sourcebranch, sourcepeer, incoming)
|
|
|
|
# - (desturl, destbranch, destpeer, outgoing)
|
|
|
|
summaryremotehooks = util.hooks()
|
|
|
|
|
2013-07-25 08:27:30 +04:00
|
|
|
# A list of state files kept by multistep operations like graft.
|
|
|
|
# Since graft cannot be aborted, it is considered 'clearable' by update.
|
|
|
|
# note: bisect is intentionally excluded
|
2013-07-25 11:17:52 +04:00
|
|
|
# (state file, clearable, allowcommit, error, hint)
|
2013-07-25 08:27:30 +04:00
|
|
|
unfinishedstates = [
|
2013-07-25 11:17:52 +04:00
|
|
|
('graftstate', True, False, _('graft in progress'),
|
2013-07-25 09:33:28 +04:00
|
|
|
_("use 'hg graft --continue' or 'hg update' to abort")),
|
2013-07-25 11:17:52 +04:00
|
|
|
('updatestate', True, False, _('last update was interrupted'),
|
2013-07-25 09:33:28 +04:00
|
|
|
_("use 'hg update' to get a consistent checkout"))
|
2013-07-25 08:27:30 +04:00
|
|
|
]
|
|
|
|
|
2013-07-25 11:17:52 +04:00
|
|
|
def checkunfinished(repo, commit=False):
|
2013-07-25 08:27:30 +04:00
|
|
|
'''Look for an unfinished multistep operation, like graft, and abort
|
|
|
|
if found. It's probably good to check this right before
|
|
|
|
bailifchanged().
|
|
|
|
'''
|
2013-07-25 11:17:52 +04:00
|
|
|
for f, clearable, allowcommit, msg, hint in unfinishedstates:
|
|
|
|
if commit and allowcommit:
|
|
|
|
continue
|
2013-07-25 08:27:30 +04:00
|
|
|
if repo.vfs.exists(f):
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(msg, hint=hint)
|
2013-07-25 08:27:30 +04:00
|
|
|
|
|
|
|
def clearunfinished(repo):
|
|
|
|
'''Check for unfinished operations (as above), and clear the ones
|
|
|
|
that are clearable.
|
|
|
|
'''
|
2013-07-25 11:17:52 +04:00
|
|
|
for f, clearable, allowcommit, msg, hint in unfinishedstates:
|
2013-07-25 08:27:30 +04:00
|
|
|
if not clearable and repo.vfs.exists(f):
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(msg, hint=hint)
|
2013-07-25 11:17:52 +04:00
|
|
|
for f, clearable, allowcommit, msg, hint in unfinishedstates:
|
2013-07-25 08:27:30 +04:00
|
|
|
if clearable and repo.vfs.exists(f):
|
|
|
|
util.unlink(repo.join(f))
|
cmdutil: add class to restore dirstate during unexpected failure
Before this patch, after "dirstate.write()" execution, there was no way to
restore dirstate to the original status before "dirstate.write()".
In some code paths, "dirstate.invalidate()" is used as a kind of "restore
.hg/dirstate to the original status", but it just avoids writing changes in
memory out, and doesn't actually restore the ".hg/dirstate" file.
To fix the issue that the recent (in memory) dirstate isn't visible to external
processes (e.g. "precommit" hooks), "dirstate.write()" should be invoked before
invocation of external processes. But at the same time, ".hg/dirstate" should be
restored to its content before "dirstate.write()" during an unexpected failure
in some cases.
This patch adds the class "dirstateguard" to easily restore ".hg/dirstate"
during unexpected failures. Typical usecase of it is:
# (1) build dirstate up
....
# (2) write dirstate out, and backup ".hg/dirstate"
dsguard = dirstateguard(repo, 'scopename')
try:
# (3) execute somethig to do:
# this may imply making some additional changes on dirstate
....
# (4) unlink backed-up dirstate file at the end of dsguard scope
dsguard.close()
finally:
# (5) if execution is aborted before "dsguard.close()",
# ".hg/dirstate" is restored from the backup
dsguard.release()
For this kind of issue, an "extending transaction" approach (in
https://titanpad.com/mercurial32-sprint) seems to not be suitable, because:
- transaction nesting occurs in some cases (e.g. "shelve => rebase"), and
- "dirstate" may be already modified since the beginning of OUTER
transaction scope, then
- dirstate should be backed up into the file other than
"dirstate.journal" at the beginning of INNER transaction scope, but
- such alternative backup files are useless for transaction itself,
and increases complication of its implementation
"transaction" and "dirstateguard" differ from each other also in "what
it should do for .hg/dirstate" in cases other than success.
============== ======= ======== =============
type success fail "hg rollback"
============== ======= ======== =============
transaction keep keep restore
dirstateguard keep restore (not implied)
============== ======= ======== =============
Some collaboration between transaction and dirstate will probably be introduced
in the future. But this layer is needed in all cases.
2015-05-07 06:07:10 +03:00
|
|
|
|
2015-12-24 22:25:44 +03:00
|
|
|
afterresolvedstates = [
|
2015-12-24 23:46:06 +03:00
|
|
|
('graftstate',
|
|
|
|
_('hg graft --continue')),
|
2015-12-24 22:25:44 +03:00
|
|
|
]
|
|
|
|
|
2016-02-14 19:16:17 +03:00
|
|
|
def howtocontinue(repo):
|
|
|
|
'''Check for an unfinished operation and return the command to finish
|
|
|
|
it.
|
|
|
|
|
|
|
|
afterresolvedstates tupples define a .hg/{file} and the corresponding
|
|
|
|
command needed to finish it.
|
|
|
|
|
|
|
|
Returns a (msg, warning) tuple. 'msg' is a string and 'warning' is
|
|
|
|
a boolean.
|
|
|
|
'''
|
|
|
|
contmsg = _("continue: %s")
|
2015-12-24 22:25:44 +03:00
|
|
|
for f, msg in afterresolvedstates:
|
|
|
|
if repo.vfs.exists(f):
|
2016-02-14 19:16:17 +03:00
|
|
|
return contmsg % msg, True
|
|
|
|
workingctx = repo[None]
|
|
|
|
dirty = any(repo.status()) or any(workingctx.sub(s).dirty()
|
|
|
|
for s in workingctx.substate)
|
|
|
|
if dirty:
|
|
|
|
return contmsg % _("hg commit"), False
|
|
|
|
return None, None
|
|
|
|
|
|
|
|
def checkafterresolved(repo):
|
|
|
|
'''Inform the user about the next action after completing hg resolve
|
|
|
|
|
|
|
|
If there's a matching afterresolvedstates, howtocontinue will yield
|
|
|
|
repo.ui.warn as the reporter.
|
|
|
|
|
|
|
|
Otherwise, it will yield repo.ui.note.
|
|
|
|
'''
|
|
|
|
msg, warning = howtocontinue(repo)
|
|
|
|
if msg is not None:
|
|
|
|
if warning:
|
|
|
|
repo.ui.warn("%s\n" % msg)
|
|
|
|
else:
|
|
|
|
repo.ui.note("%s\n" % msg)
|
|
|
|
|
|
|
|
def wrongtooltocontinue(repo, task):
|
|
|
|
'''Raise an abort suggesting how to properly continue if there is an
|
|
|
|
active task.
|
|
|
|
|
|
|
|
Uses howtocontinue() to find the active task.
|
|
|
|
|
|
|
|
If there's no task (repo.ui.note for 'hg commit'), it does not offer
|
|
|
|
a hint.
|
|
|
|
'''
|
|
|
|
after = howtocontinue(repo)
|
|
|
|
hint = None
|
|
|
|
if after[1]:
|
|
|
|
hint = after[0]
|
|
|
|
raise error.Abort(_('no %s in progress') % task, hint=hint)
|
2015-12-24 22:25:44 +03:00
|
|
|
|
cmdutil: add class to restore dirstate during unexpected failure
Before this patch, after "dirstate.write()" execution, there was no way to
restore dirstate to the original status before "dirstate.write()".
In some code paths, "dirstate.invalidate()" is used as a kind of "restore
.hg/dirstate to the original status", but it just avoids writing changes in
memory out, and doesn't actually restore the ".hg/dirstate" file.
To fix the issue that the recent (in memory) dirstate isn't visible to external
processes (e.g. "precommit" hooks), "dirstate.write()" should be invoked before
invocation of external processes. But at the same time, ".hg/dirstate" should be
restored to its content before "dirstate.write()" during an unexpected failure
in some cases.
This patch adds the class "dirstateguard" to easily restore ".hg/dirstate"
during unexpected failures. Typical usecase of it is:
# (1) build dirstate up
....
# (2) write dirstate out, and backup ".hg/dirstate"
dsguard = dirstateguard(repo, 'scopename')
try:
# (3) execute somethig to do:
# this may imply making some additional changes on dirstate
....
# (4) unlink backed-up dirstate file at the end of dsguard scope
dsguard.close()
finally:
# (5) if execution is aborted before "dsguard.close()",
# ".hg/dirstate" is restored from the backup
dsguard.release()
For this kind of issue, an "extending transaction" approach (in
https://titanpad.com/mercurial32-sprint) seems to not be suitable, because:
- transaction nesting occurs in some cases (e.g. "shelve => rebase"), and
- "dirstate" may be already modified since the beginning of OUTER
transaction scope, then
- dirstate should be backed up into the file other than
"dirstate.journal" at the beginning of INNER transaction scope, but
- such alternative backup files are useless for transaction itself,
and increases complication of its implementation
"transaction" and "dirstateguard" differ from each other also in "what
it should do for .hg/dirstate" in cases other than success.
============== ======= ======== =============
type success fail "hg rollback"
============== ======= ======== =============
transaction keep keep restore
dirstateguard keep restore (not implied)
============== ======= ======== =============
Some collaboration between transaction and dirstate will probably be introduced
in the future. But this layer is needed in all cases.
2015-05-07 06:07:10 +03:00
|
|
|
class dirstateguard(object):
|
|
|
|
'''Restore dirstate at unexpected failure.
|
|
|
|
|
|
|
|
At the construction, this class does:
|
|
|
|
|
|
|
|
- write current ``repo.dirstate`` out, and
|
|
|
|
- save ``.hg/dirstate`` into the backup file
|
|
|
|
|
|
|
|
This restores ``.hg/dirstate`` from backup file, if ``release()``
|
|
|
|
is invoked before ``close()``.
|
|
|
|
|
|
|
|
This just removes the backup file at ``close()`` before ``release()``.
|
|
|
|
'''
|
|
|
|
|
|
|
|
def __init__(self, repo, name):
|
|
|
|
self._repo = repo
|
2015-10-13 20:49:17 +03:00
|
|
|
self._suffix = '.backup.%s.%d' % (name, id(self))
|
2015-10-16 19:15:33 +03:00
|
|
|
repo.dirstate._savebackup(repo.currenttransaction(), self._suffix)
|
cmdutil: add class to restore dirstate during unexpected failure
Before this patch, after "dirstate.write()" execution, there was no way to
restore dirstate to the original status before "dirstate.write()".
In some code paths, "dirstate.invalidate()" is used as a kind of "restore
.hg/dirstate to the original status", but it just avoids writing changes in
memory out, and doesn't actually restore the ".hg/dirstate" file.
To fix the issue that the recent (in memory) dirstate isn't visible to external
processes (e.g. "precommit" hooks), "dirstate.write()" should be invoked before
invocation of external processes. But at the same time, ".hg/dirstate" should be
restored to its content before "dirstate.write()" during an unexpected failure
in some cases.
This patch adds the class "dirstateguard" to easily restore ".hg/dirstate"
during unexpected failures. Typical usecase of it is:
# (1) build dirstate up
....
# (2) write dirstate out, and backup ".hg/dirstate"
dsguard = dirstateguard(repo, 'scopename')
try:
# (3) execute somethig to do:
# this may imply making some additional changes on dirstate
....
# (4) unlink backed-up dirstate file at the end of dsguard scope
dsguard.close()
finally:
# (5) if execution is aborted before "dsguard.close()",
# ".hg/dirstate" is restored from the backup
dsguard.release()
For this kind of issue, an "extending transaction" approach (in
https://titanpad.com/mercurial32-sprint) seems to not be suitable, because:
- transaction nesting occurs in some cases (e.g. "shelve => rebase"), and
- "dirstate" may be already modified since the beginning of OUTER
transaction scope, then
- dirstate should be backed up into the file other than
"dirstate.journal" at the beginning of INNER transaction scope, but
- such alternative backup files are useless for transaction itself,
and increases complication of its implementation
"transaction" and "dirstateguard" differ from each other also in "what
it should do for .hg/dirstate" in cases other than success.
============== ======= ======== =============
type success fail "hg rollback"
============== ======= ======== =============
transaction keep keep restore
dirstateguard keep restore (not implied)
============== ======= ======== =============
Some collaboration between transaction and dirstate will probably be introduced
in the future. But this layer is needed in all cases.
2015-05-07 06:07:10 +03:00
|
|
|
self._active = True
|
|
|
|
self._closed = False
|
|
|
|
|
|
|
|
def __del__(self):
|
|
|
|
if self._active: # still active
|
|
|
|
# this may occur, even if this class is used correctly:
|
|
|
|
# for example, releasing other resources like transaction
|
|
|
|
# may raise exception before ``dirstateguard.release`` in
|
|
|
|
# ``release(tr, ....)``.
|
|
|
|
self._abort()
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
if not self._active: # already inactivated
|
2015-10-13 20:49:17 +03:00
|
|
|
msg = (_("can't close already inactivated backup: dirstate%s")
|
|
|
|
% self._suffix)
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(msg)
|
cmdutil: add class to restore dirstate during unexpected failure
Before this patch, after "dirstate.write()" execution, there was no way to
restore dirstate to the original status before "dirstate.write()".
In some code paths, "dirstate.invalidate()" is used as a kind of "restore
.hg/dirstate to the original status", but it just avoids writing changes in
memory out, and doesn't actually restore the ".hg/dirstate" file.
To fix the issue that the recent (in memory) dirstate isn't visible to external
processes (e.g. "precommit" hooks), "dirstate.write()" should be invoked before
invocation of external processes. But at the same time, ".hg/dirstate" should be
restored to its content before "dirstate.write()" during an unexpected failure
in some cases.
This patch adds the class "dirstateguard" to easily restore ".hg/dirstate"
during unexpected failures. Typical usecase of it is:
# (1) build dirstate up
....
# (2) write dirstate out, and backup ".hg/dirstate"
dsguard = dirstateguard(repo, 'scopename')
try:
# (3) execute somethig to do:
# this may imply making some additional changes on dirstate
....
# (4) unlink backed-up dirstate file at the end of dsguard scope
dsguard.close()
finally:
# (5) if execution is aborted before "dsguard.close()",
# ".hg/dirstate" is restored from the backup
dsguard.release()
For this kind of issue, an "extending transaction" approach (in
https://titanpad.com/mercurial32-sprint) seems to not be suitable, because:
- transaction nesting occurs in some cases (e.g. "shelve => rebase"), and
- "dirstate" may be already modified since the beginning of OUTER
transaction scope, then
- dirstate should be backed up into the file other than
"dirstate.journal" at the beginning of INNER transaction scope, but
- such alternative backup files are useless for transaction itself,
and increases complication of its implementation
"transaction" and "dirstateguard" differ from each other also in "what
it should do for .hg/dirstate" in cases other than success.
============== ======= ======== =============
type success fail "hg rollback"
============== ======= ======== =============
transaction keep keep restore
dirstateguard keep restore (not implied)
============== ======= ======== =============
Some collaboration between transaction and dirstate will probably be introduced
in the future. But this layer is needed in all cases.
2015-05-07 06:07:10 +03:00
|
|
|
|
2015-10-16 19:15:33 +03:00
|
|
|
self._repo.dirstate._clearbackup(self._repo.currenttransaction(),
|
|
|
|
self._suffix)
|
cmdutil: add class to restore dirstate during unexpected failure
Before this patch, after "dirstate.write()" execution, there was no way to
restore dirstate to the original status before "dirstate.write()".
In some code paths, "dirstate.invalidate()" is used as a kind of "restore
.hg/dirstate to the original status", but it just avoids writing changes in
memory out, and doesn't actually restore the ".hg/dirstate" file.
To fix the issue that the recent (in memory) dirstate isn't visible to external
processes (e.g. "precommit" hooks), "dirstate.write()" should be invoked before
invocation of external processes. But at the same time, ".hg/dirstate" should be
restored to its content before "dirstate.write()" during an unexpected failure
in some cases.
This patch adds the class "dirstateguard" to easily restore ".hg/dirstate"
during unexpected failures. Typical usecase of it is:
# (1) build dirstate up
....
# (2) write dirstate out, and backup ".hg/dirstate"
dsguard = dirstateguard(repo, 'scopename')
try:
# (3) execute somethig to do:
# this may imply making some additional changes on dirstate
....
# (4) unlink backed-up dirstate file at the end of dsguard scope
dsguard.close()
finally:
# (5) if execution is aborted before "dsguard.close()",
# ".hg/dirstate" is restored from the backup
dsguard.release()
For this kind of issue, an "extending transaction" approach (in
https://titanpad.com/mercurial32-sprint) seems to not be suitable, because:
- transaction nesting occurs in some cases (e.g. "shelve => rebase"), and
- "dirstate" may be already modified since the beginning of OUTER
transaction scope, then
- dirstate should be backed up into the file other than
"dirstate.journal" at the beginning of INNER transaction scope, but
- such alternative backup files are useless for transaction itself,
and increases complication of its implementation
"transaction" and "dirstateguard" differ from each other also in "what
it should do for .hg/dirstate" in cases other than success.
============== ======= ======== =============
type success fail "hg rollback"
============== ======= ======== =============
transaction keep keep restore
dirstateguard keep restore (not implied)
============== ======= ======== =============
Some collaboration between transaction and dirstate will probably be introduced
in the future. But this layer is needed in all cases.
2015-05-07 06:07:10 +03:00
|
|
|
self._active = False
|
|
|
|
self._closed = True
|
|
|
|
|
|
|
|
def _abort(self):
|
2015-10-16 19:15:33 +03:00
|
|
|
self._repo.dirstate._restorebackup(self._repo.currenttransaction(),
|
|
|
|
self._suffix)
|
cmdutil: add class to restore dirstate during unexpected failure
Before this patch, after "dirstate.write()" execution, there was no way to
restore dirstate to the original status before "dirstate.write()".
In some code paths, "dirstate.invalidate()" is used as a kind of "restore
.hg/dirstate to the original status", but it just avoids writing changes in
memory out, and doesn't actually restore the ".hg/dirstate" file.
To fix the issue that the recent (in memory) dirstate isn't visible to external
processes (e.g. "precommit" hooks), "dirstate.write()" should be invoked before
invocation of external processes. But at the same time, ".hg/dirstate" should be
restored to its content before "dirstate.write()" during an unexpected failure
in some cases.
This patch adds the class "dirstateguard" to easily restore ".hg/dirstate"
during unexpected failures. Typical usecase of it is:
# (1) build dirstate up
....
# (2) write dirstate out, and backup ".hg/dirstate"
dsguard = dirstateguard(repo, 'scopename')
try:
# (3) execute somethig to do:
# this may imply making some additional changes on dirstate
....
# (4) unlink backed-up dirstate file at the end of dsguard scope
dsguard.close()
finally:
# (5) if execution is aborted before "dsguard.close()",
# ".hg/dirstate" is restored from the backup
dsguard.release()
For this kind of issue, an "extending transaction" approach (in
https://titanpad.com/mercurial32-sprint) seems to not be suitable, because:
- transaction nesting occurs in some cases (e.g. "shelve => rebase"), and
- "dirstate" may be already modified since the beginning of OUTER
transaction scope, then
- dirstate should be backed up into the file other than
"dirstate.journal" at the beginning of INNER transaction scope, but
- such alternative backup files are useless for transaction itself,
and increases complication of its implementation
"transaction" and "dirstateguard" differ from each other also in "what
it should do for .hg/dirstate" in cases other than success.
============== ======= ======== =============
type success fail "hg rollback"
============== ======= ======== =============
transaction keep keep restore
dirstateguard keep restore (not implied)
============== ======= ======== =============
Some collaboration between transaction and dirstate will probably be introduced
in the future. But this layer is needed in all cases.
2015-05-07 06:07:10 +03:00
|
|
|
self._active = False
|
|
|
|
|
|
|
|
def release(self):
|
|
|
|
if not self._closed:
|
|
|
|
if not self._active: # already inactivated
|
2015-10-13 20:49:17 +03:00
|
|
|
msg = (_("can't release already inactivated backup:"
|
|
|
|
" dirstate%s")
|
|
|
|
% self._suffix)
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(msg)
|
cmdutil: add class to restore dirstate during unexpected failure
Before this patch, after "dirstate.write()" execution, there was no way to
restore dirstate to the original status before "dirstate.write()".
In some code paths, "dirstate.invalidate()" is used as a kind of "restore
.hg/dirstate to the original status", but it just avoids writing changes in
memory out, and doesn't actually restore the ".hg/dirstate" file.
To fix the issue that the recent (in memory) dirstate isn't visible to external
processes (e.g. "precommit" hooks), "dirstate.write()" should be invoked before
invocation of external processes. But at the same time, ".hg/dirstate" should be
restored to its content before "dirstate.write()" during an unexpected failure
in some cases.
This patch adds the class "dirstateguard" to easily restore ".hg/dirstate"
during unexpected failures. Typical usecase of it is:
# (1) build dirstate up
....
# (2) write dirstate out, and backup ".hg/dirstate"
dsguard = dirstateguard(repo, 'scopename')
try:
# (3) execute somethig to do:
# this may imply making some additional changes on dirstate
....
# (4) unlink backed-up dirstate file at the end of dsguard scope
dsguard.close()
finally:
# (5) if execution is aborted before "dsguard.close()",
# ".hg/dirstate" is restored from the backup
dsguard.release()
For this kind of issue, an "extending transaction" approach (in
https://titanpad.com/mercurial32-sprint) seems to not be suitable, because:
- transaction nesting occurs in some cases (e.g. "shelve => rebase"), and
- "dirstate" may be already modified since the beginning of OUTER
transaction scope, then
- dirstate should be backed up into the file other than
"dirstate.journal" at the beginning of INNER transaction scope, but
- such alternative backup files are useless for transaction itself,
and increases complication of its implementation
"transaction" and "dirstateguard" differ from each other also in "what
it should do for .hg/dirstate" in cases other than success.
============== ======= ======== =============
type success fail "hg rollback"
============== ======= ======== =============
transaction keep keep restore
dirstateguard keep restore (not implied)
============== ======= ======== =============
Some collaboration between transaction and dirstate will probably be introduced
in the future. But this layer is needed in all cases.
2015-05-07 06:07:10 +03:00
|
|
|
self._abort()
|