/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/builtins.py

  • Committer: Jelmer Vernooij
  • Date: 2019-03-02 22:31:28 UTC
  • mfrom: (7291 work)
  • mto: This revision was merged to the branch mainline in revision 7293.
  • Revision ID: jelmer@jelmer.uk-20190302223128-0qk1i5tozmzq5nyq
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1480
1480
            revision_id = br_from.last_revision()
1481
1481
        if to_location is None:
1482
1482
            to_location = urlutils.derive_to_location(from_location)
1483
 
        to_transport = transport.get_transport(to_location)
 
1483
        to_transport = transport.get_transport(to_location, purpose='write')
1484
1484
        try:
1485
1485
            to_transport.mkdir('.')
1486
1486
        except errors.FileExists:
1574
1574
 
1575
1575
    def run(self, location=".", recursive=False):
1576
1576
        if recursive:
1577
 
            t = transport.get_transport(location)
 
1577
            t = transport.get_transport(location, purpose='read')
1578
1578
            if not t.listable():
1579
1579
                raise errors.BzrCommandError(
1580
1580
                    "Can't scan this type of location.")
2058
2058
        if location is None:
2059
2059
            location = u'.'
2060
2060
 
2061
 
        to_transport = transport.get_transport(location)
 
2061
        to_transport = transport.get_transport(location, purpose='write')
2062
2062
 
2063
2063
        # The path has to exist to initialize a
2064
2064
        # branch inside of it.
2178
2178
        if location is None:
2179
2179
            location = '.'
2180
2180
 
2181
 
        to_transport = transport.get_transport(location)
 
2181
        to_transport = transport.get_transport(location, purpose='write')
2182
2182
 
2183
2183
        if format.fixed_components:
2184
2184
            repo_format_name = None
6831
6831
            cmd_reconcile().run(".")
6832
6832
 
6833
6833
 
 
6834
class cmd_grep(Command):
 
6835
    """Print lines matching PATTERN for specified files and revisions.
 
6836
 
 
6837
    This command searches the specified files and revisions for a given
 
6838
    pattern.  The pattern is specified as a Python regular expressions[1].
 
6839
 
 
6840
    If the file name is not specified, the revisions starting with the
 
6841
    current directory are searched recursively. If the revision number is
 
6842
    not specified, the working copy is searched. To search the last committed
 
6843
    revision, use the '-r -1' or '-r last:1' option.
 
6844
 
 
6845
    Unversioned files are not searched unless explicitly specified on the
 
6846
    command line. Unversioned directores are not searched.
 
6847
 
 
6848
    When searching a pattern, the output is shown in the 'filepath:string'
 
6849
    format. If a revision is explicitly searched, the output is shown as
 
6850
    'filepath~N:string', where N is the revision number.
 
6851
 
 
6852
    --include and --exclude options can be used to search only (or exclude
 
6853
    from search) files with base name matches the specified Unix style GLOB
 
6854
    pattern.  The GLOB pattern an use *, ?, and [...] as wildcards, and \\
 
6855
    to quote wildcard or backslash character literally. Note that the glob
 
6856
    pattern is not a regular expression.
 
6857
 
 
6858
    [1] http://docs.python.org/library/re.html#regular-expression-syntax
 
6859
    """
 
6860
 
 
6861
    encoding_type = 'replace'
 
6862
    takes_args = ['pattern', 'path*']
 
6863
    takes_options = [
 
6864
        'verbose',
 
6865
        'revision',
 
6866
        Option('color', type=text_type, argname='when',
 
6867
               help='Show match in color. WHEN is never, always or auto.'),
 
6868
        Option('diff', short_name='p',
 
6869
               help='Grep for pattern in changeset for each revision.'),
 
6870
        ListOption('exclude', type=text_type, argname='glob', short_name='X',
 
6871
                   help="Skip files whose base name matches GLOB."),
 
6872
        ListOption('include', type=text_type, argname='glob', short_name='I',
 
6873
                   help="Search only files whose base name matches GLOB."),
 
6874
        Option('files-with-matches', short_name='l',
 
6875
               help='Print only the name of each input file in '
 
6876
               'which PATTERN is found.'),
 
6877
        Option('files-without-match', short_name='L',
 
6878
               help='Print only the name of each input file in '
 
6879
               'which PATTERN is not found.'),
 
6880
        Option('fixed-string', short_name='F',
 
6881
               help='Interpret PATTERN is a single fixed string (not regex).'),
 
6882
        Option('from-root',
 
6883
               help='Search for pattern starting from the root of the branch. '
 
6884
               '(implies --recursive)'),
 
6885
        Option('ignore-case', short_name='i',
 
6886
               help='Ignore case distinctions while matching.'),
 
6887
        Option('levels',
 
6888
               help='Number of levels to display - 0 for all, 1 for collapsed '
 
6889
               '(1 is default).',
 
6890
               argname='N',
 
6891
               type=_parse_levels),
 
6892
        Option('line-number', short_name='n',
 
6893
               help='Show 1-based line number.'),
 
6894
        Option('no-recursive',
 
6895
               help="Don't recurse into subdirectories. (default is --recursive)"),
 
6896
        Option('null', short_name='Z',
 
6897
               help='Write an ASCII NUL (\\0) separator '
 
6898
               'between output lines rather than a newline.'),
 
6899
        ]
 
6900
 
 
6901
    @display_command
 
6902
    def run(self, verbose=False, ignore_case=False, no_recursive=False,
 
6903
            from_root=False, null=False, levels=None, line_number=False,
 
6904
            path_list=None, revision=None, pattern=None, include=None,
 
6905
            exclude=None, fixed_string=False, files_with_matches=False,
 
6906
            files_without_match=False, color=None, diff=False):
 
6907
        from breezy import _termcolor
 
6908
        from . import grep
 
6909
        import re
 
6910
        if path_list is None:
 
6911
            path_list = ['.']
 
6912
        else:
 
6913
            if from_root:
 
6914
                raise errors.BzrCommandError(
 
6915
                    'cannot specify both --from-root and PATH.')
 
6916
 
 
6917
        if files_with_matches and files_without_match:
 
6918
            raise errors.BzrCommandError(
 
6919
                'cannot specify both '
 
6920
                '-l/--files-with-matches and -L/--files-without-matches.')
 
6921
 
 
6922
        global_config = _mod_config.GlobalConfig()
 
6923
 
 
6924
        if color is None:
 
6925
            color = global_config.get_user_option('grep_color')
 
6926
 
 
6927
        if color is None:
 
6928
            color = 'never'
 
6929
 
 
6930
        if color not in ['always', 'never', 'auto']:
 
6931
            raise errors.BzrCommandError('Valid values for --color are '
 
6932
                                         '"always", "never" or "auto".')
 
6933
 
 
6934
        if levels is None:
 
6935
            levels = 1
 
6936
 
 
6937
        print_revno = False
 
6938
        if revision is not None or levels == 0:
 
6939
            # print revision numbers as we may be showing multiple revisions
 
6940
            print_revno = True
 
6941
 
 
6942
        eol_marker = '\n'
 
6943
        if null:
 
6944
            eol_marker = '\0'
 
6945
 
 
6946
        if not ignore_case and grep.is_fixed_string(pattern):
 
6947
            # if the pattern isalnum, implicitly use to -F for faster grep
 
6948
            fixed_string = True
 
6949
        elif ignore_case and fixed_string:
 
6950
            # GZ 2010-06-02: Fall back to regexp rather than lowercasing
 
6951
            #                pattern and text which will cause pain later
 
6952
            fixed_string = False
 
6953
            pattern = re.escape(pattern)
 
6954
 
 
6955
        patternc = None
 
6956
        re_flags = re.MULTILINE
 
6957
        if ignore_case:
 
6958
            re_flags |= re.IGNORECASE
 
6959
 
 
6960
        if not fixed_string:
 
6961
            patternc = grep.compile_pattern(
 
6962
                pattern.encode(grep._user_encoding), re_flags)
 
6963
 
 
6964
        if color == 'always':
 
6965
            show_color = True
 
6966
        elif color == 'never':
 
6967
            show_color = False
 
6968
        elif color == 'auto':
 
6969
            show_color = _termcolor.allow_color()
 
6970
 
 
6971
        opts = grep.GrepOptions()
 
6972
 
 
6973
        opts.verbose = verbose
 
6974
        opts.ignore_case = ignore_case
 
6975
        opts.no_recursive = no_recursive
 
6976
        opts.from_root = from_root
 
6977
        opts.null = null
 
6978
        opts.levels = levels
 
6979
        opts.line_number = line_number
 
6980
        opts.path_list = path_list
 
6981
        opts.revision = revision
 
6982
        opts.pattern = pattern
 
6983
        opts.include = include
 
6984
        opts.exclude = exclude
 
6985
        opts.fixed_string = fixed_string
 
6986
        opts.files_with_matches = files_with_matches
 
6987
        opts.files_without_match = files_without_match
 
6988
        opts.color = color
 
6989
        opts.diff = False
 
6990
 
 
6991
        opts.eol_marker = eol_marker
 
6992
        opts.print_revno = print_revno
 
6993
        opts.patternc = patternc
 
6994
        opts.recursive = not no_recursive
 
6995
        opts.fixed_string = fixed_string
 
6996
        opts.outf = self.outf
 
6997
        opts.show_color = show_color
 
6998
 
 
6999
        if diff:
 
7000
            # options not used:
 
7001
            # files_with_matches, files_without_match
 
7002
            # levels(?), line_number, from_root
 
7003
            # include, exclude
 
7004
            # These are silently ignored.
 
7005
            grep.grep_diff(opts)
 
7006
        elif revision is None:
 
7007
            grep.workingtree_grep(opts)
 
7008
        else:
 
7009
            grep.versioned_grep(opts)
 
7010
 
 
7011
 
6834
7012
def _register_lazy_builtins():
6835
7013
    # register lazy builtins from other modules; called at startup and should
6836
7014
    # be only called once.