/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 __init__.py

  • Committer: Parth Malwankar
  • Date: 2010-02-23 18:28:21 UTC
  • mto: (0.44.2 grep) (6531.3.1 merge-grep)
  • mto: This revision was merged to the branch mainline in revision 6555.
  • Revision ID: parth.malwankar@gmail.com-20100223182821-87y22f6u6m7u73n4
grep is working now howerver paths are not printed in the
best possible way.

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
            if from_root:
66
66
                raise errors.BzrCommandError('cannot specify both --from-root and PATH.')
67
67
 
68
 
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch('.')
69
 
 
70
68
        re_flags = 0
71
69
        if ignore_case:
72
70
            re_flags = re.IGNORECASE
83
81
        except re.error, e:
84
82
            raise errors.BzrError("Invalid pattern: '%s'" % pattern)
85
83
 
86
 
        tree.lock_read()
87
 
        self.add_cleanup(tree.unlock)
88
84
        for path in path_list:
 
85
            path = os.path.abspath(path)
89
86
            if osutils.isdir(path):
90
 
                from_dir = os.path.abspath(os.path.join(relpath, path))
91
 
                for fp, fc, fkind, fid, entry in tree.list_files(include_root=False,
92
 
                    from_dir=from_dir, recursive=recursive):
93
 
                    if fc == 'V' and fkind == 'file':
94
 
                        self.file_grep(fp, patternc, eol_marker)
 
87
                tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(path)
 
88
                tree.lock_read()
 
89
                try:
 
90
                    for fp, fc, fkind, fid, entry in tree.list_files(include_root=False,
 
91
                        from_dir=relpath, recursive=recursive):
 
92
                        if fc == 'V' and fkind == 'file':
 
93
                            self.file_grep(relpath, fp, patternc, eol_marker)
 
94
                finally:
 
95
                    tree.unlock()
95
96
            else:
96
97
                # if user has explicitly specified a file
97
98
                # we don't care if its versioned
98
 
                self.file_grep(path, patternc, eol_marker)
 
99
                self.file_grep('.', path, patternc, eol_marker)
99
100
 
100
 
    def file_grep(self, path, patternc, eol_marker):
 
101
    def file_grep(self, relpath, path, patternc, eol_marker):
101
102
        index = 1
102
 
        fmt = "%s:%d:%s" + eol_marker
 
103
        path = os.path.normpath(os.path.join('..', relpath, path))
 
104
        fmt = path + ":%d:%s" + eol_marker
103
105
        for line in open(path):
104
106
            res = patternc.search(line)
105
107
            if res:
106
 
                self.outf.write( fmt % (path, index, line.strip()))
 
108
                self.outf.write( fmt % (index, line.strip()))
107
109
            index += 1
108
110
 
109
111
register_command(cmd_grep)