2014-07-23 20:47:35 +04:00
|
|
|
# tweakdefaults.py
|
|
|
|
#
|
|
|
|
# Copyright 2013 Facebook, Inc.
|
|
|
|
#
|
|
|
|
# This software may be used and distributed according to the terms of the
|
|
|
|
# GNU General Public License version 2 or any later version.
|
|
|
|
|
2014-09-19 04:22:14 +04:00
|
|
|
from mercurial import util, cmdutil, commands, hg, scmutil
|
2014-07-23 20:47:35 +04:00
|
|
|
from mercurial import bookmarks
|
|
|
|
from mercurial.extensions import wrapcommand
|
|
|
|
from mercurial.i18n import _
|
|
|
|
from hgext import rebase
|
|
|
|
import errno, os
|
|
|
|
|
|
|
|
cmdtable = {}
|
|
|
|
command = cmdutil.command(cmdtable)
|
|
|
|
testedwith = 'internal'
|
|
|
|
|
2014-09-25 22:34:07 +04:00
|
|
|
def extsetup(ui):
|
|
|
|
wrapcommand(commands.table, 'update', update)
|
|
|
|
wrapcommand(rebase.cmdtable, 'rebase', _rebase)
|
|
|
|
|
|
|
|
entry = wrapcommand(commands.table, 'log', log)
|
|
|
|
for opt in logopts:
|
|
|
|
opt = (opt[0], opt[1], opt[2], opt[3])
|
|
|
|
entry[1].append(opt)
|
|
|
|
|
2014-08-19 22:21:45 +04:00
|
|
|
def update(orig, ui, repo, node=None, rev=None, **kwargs):
|
2014-07-23 20:47:35 +04:00
|
|
|
# 'hg update' should do nothing
|
2014-08-19 22:21:45 +04:00
|
|
|
if not node and not rev:
|
2014-09-08 23:43:38 +04:00
|
|
|
raise util.Abort(
|
|
|
|
'you must specify a destination to update to',
|
|
|
|
hint="if you're trying to move a bookmark forward, try " +
|
|
|
|
"'hg rebase -d <destination>'")
|
2014-07-23 20:47:35 +04:00
|
|
|
|
2014-09-03 19:46:45 +04:00
|
|
|
return orig(ui, repo, node=node, rev=rev, **kwargs)
|
2014-07-23 20:47:35 +04:00
|
|
|
|
2014-09-25 02:11:10 +04:00
|
|
|
@command('histgrep', commands.table['grep'][1], commands.table['grep'][2])
|
|
|
|
def histgrep(ui, repo, pattern, *pats, **opts):
|
|
|
|
"""search for a pattern in specified files and revisions
|
|
|
|
|
|
|
|
Search revisions of files for a regular expression.
|
|
|
|
|
|
|
|
The command used to be hg grep.
|
|
|
|
|
|
|
|
This command behaves differently than Unix grep. It only accepts
|
|
|
|
Python/Perl regexps. It searches repository history, not the working
|
|
|
|
directory. It always prints the revision number in which a match appears.
|
|
|
|
|
|
|
|
By default, grep only prints output for the first revision of a file in
|
|
|
|
which it finds a match. To get it to print every revision that contains a
|
|
|
|
change in match status ("-" for a match that becomes a non-match, or "+"
|
|
|
|
for a non-match that becomes a match), use the --all flag.
|
|
|
|
|
|
|
|
Returns 0 if a match is found, 1 otherwise."""
|
|
|
|
return commands.grep(ui, repo, pattern, **opts)
|
|
|
|
|
|
|
|
del commands.table['grep']
|
2014-09-26 00:50:36 +04:00
|
|
|
@command('grep',
|
|
|
|
[('A', 'after-context', '', 'print NUM lines of trailing context', 'NUM'),
|
|
|
|
('B', 'before-context', '', 'print NUM lines of leading context', 'NUM'),
|
|
|
|
('C', 'context', '', 'print NUM lines of output context', 'NUM'),
|
|
|
|
('i', 'ignore-case', None, 'ignore case when matching'),
|
|
|
|
('l', 'files-with-matches', None, 'print only filenames that match'),
|
|
|
|
('n', 'line-number', None, 'print matching line numbers'),
|
|
|
|
('V', 'invert-match', None, 'select non-matching lines'),
|
|
|
|
('w', 'word-regexp', None, 'match whole words only'),
|
|
|
|
('E', 'extended-regexp', None, 'use POSIX extended regexps'),
|
|
|
|
('F', 'fixed-strings', None, 'interpret pattern as fixed string'),
|
|
|
|
('P', 'perl-regexp', None, 'use Perl-compatible regexps'),
|
|
|
|
], '[OPTION]... PATTERN [FILE]...',
|
|
|
|
inferrepo=True)
|
|
|
|
def grep(ui, repo, pattern, *pats, **opts):
|
|
|
|
"""search for a pattern in tracked files in the working directory
|
|
|
|
|
|
|
|
The default regexp style is POSIX basic regexps. If no FILE parameters are
|
|
|
|
passed in, the current directory and its subdirectories will be searched.
|
|
|
|
|
|
|
|
For the old 'hg grep', see 'histgrep'."""
|
2014-09-25 02:11:10 +04:00
|
|
|
|
|
|
|
optstr = ''
|
|
|
|
if opts.get('after_context'):
|
|
|
|
optstr += '-A' + opts.get('after_context') + ' '
|
|
|
|
if opts.get('before_context'):
|
|
|
|
optstr += '-B' + opts.get('before_context') + ' '
|
|
|
|
if opts.get('context'):
|
|
|
|
optstr += '-C' + opts.get('context') + ' '
|
|
|
|
if opts.get('ignore_case'):
|
|
|
|
optstr += '-i '
|
|
|
|
if opts.get('files_with_matches'):
|
|
|
|
optstr += '-l '
|
|
|
|
if opts.get('line_number'):
|
|
|
|
optstr += '-n '
|
|
|
|
if opts.get('invert_match'):
|
|
|
|
optstr += '-v '
|
|
|
|
if opts.get('word_regexp'):
|
|
|
|
optstr += '-w '
|
2014-09-26 00:50:36 +04:00
|
|
|
if opts.get('extended_regexp'):
|
|
|
|
optstr += '-E '
|
|
|
|
if opts.get('fixed_strings'):
|
|
|
|
optstr += '-F '
|
|
|
|
if opts.get('perl_regexp'):
|
|
|
|
optstr += '-P '
|
|
|
|
|
|
|
|
# color support, using the color extension
|
|
|
|
colormode = getattr(ui, '_colormode', '')
|
|
|
|
if colormode == 'ansi':
|
|
|
|
optstr += '--color=always '
|
|
|
|
|
|
|
|
includes = ''
|
|
|
|
if pats:
|
|
|
|
for pat in pats:
|
|
|
|
includes += '-I %s ' % util.shellquote(pat)
|
|
|
|
|
|
|
|
return util.system("hg status --no-status --clean --modified --added "
|
|
|
|
"--print0 . %s | xargs -0 grep --no-messages "
|
|
|
|
"--binary-files=without-match --with-filename "
|
|
|
|
"--regexp=%s %s --" %
|
|
|
|
(includes, util.shellquote(pattern), optstr),
|
|
|
|
out=ui.fout)
|
2014-09-25 02:11:10 +04:00
|
|
|
|
2014-07-23 20:47:35 +04:00
|
|
|
def _rebase(orig, ui, repo, **opts):
|
2014-08-19 01:27:37 +04:00
|
|
|
if opts.get('continue') or opts.get('abort'):
|
|
|
|
return orig(ui, repo, **opts)
|
|
|
|
|
2014-07-23 20:47:35 +04:00
|
|
|
# 'hg rebase' w/o args should do nothing
|
|
|
|
if not opts.get('dest'):
|
|
|
|
raise util.Abort("you must specify a destination (-d) for the rebase")
|
|
|
|
|
2014-09-19 04:22:14 +04:00
|
|
|
# 'hg rebase' can fast-forward bookmark
|
|
|
|
prev = repo['.']
|
|
|
|
dest = scmutil.revsingle(repo, opts.get('dest'))
|
2014-07-23 20:47:35 +04:00
|
|
|
|
2014-09-19 04:22:14 +04:00
|
|
|
# Only fast-forward the bookmark if no source nodes were explicitly
|
|
|
|
# specified.
|
|
|
|
if not (opts.get('base') or opts.get('source') or opts.get('rev')):
|
|
|
|
common = dest.ancestor(prev)
|
2014-07-23 20:47:35 +04:00
|
|
|
if prev == common:
|
2014-09-19 04:22:14 +04:00
|
|
|
result = hg.update(repo, dest.node())
|
2014-07-23 20:47:35 +04:00
|
|
|
if repo._bookmarkcurrent:
|
2014-09-19 04:22:14 +04:00
|
|
|
bookmarks.update(repo, [prev.node()], dest.node())
|
2014-07-23 20:47:35 +04:00
|
|
|
return result
|
|
|
|
|
|
|
|
return orig(ui, repo, **opts)
|
|
|
|
|
|
|
|
logopts = [
|
|
|
|
('', 'all', None, _('shows all commits in the repo')),
|
|
|
|
]
|
|
|
|
|
|
|
|
def log(orig, ui, repo, *pats, **opts):
|
|
|
|
# 'hg log' defaults to -f
|
|
|
|
# All special uses of log (--date, --branch, etc) will also now do follow.
|
|
|
|
if not opts.get('rev') and not opts.get('all'):
|
|
|
|
opts['follow'] = True
|
|
|
|
|
|
|
|
return orig(ui, repo, *pats, **opts)
|
|
|
|
|