/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-24 02:48:51 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-20100224024851-e3bm96u2tv20chcr
fixed relative path handling

Show diffs side-by-side

added added

removed removed

Lines of Context:
82
82
            raise errors.BzrError("Invalid pattern: '%s'" % pattern)
83
83
 
84
84
        for path in path_list:
85
 
            path = os.path.abspath(path)
86
85
            if osutils.isdir(path):
87
86
                tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(path)
 
87
 
 
88
                # setup rpath to open files relative to cwd
 
89
                rpath = relpath
 
90
                if relpath:
 
91
                    rpath = os.path.join('..',relpath)
 
92
 
88
93
                tree.lock_read()
89
94
                try:
90
95
                    for fp, fc, fkind, fid, entry in tree.list_files(include_root=False,
91
96
                        from_dir=relpath, recursive=recursive):
92
97
                        if fc == 'V' and fkind == 'file':
93
 
                            self.file_grep(relpath, fp, patternc, eol_marker)
 
98
                            self.file_grep(rpath, fp, patternc, eol_marker)
94
99
                finally:
95
100
                    tree.unlock()
96
101
            else:
100
105
 
101
106
    def file_grep(self, relpath, path, patternc, eol_marker):
102
107
        index = 1
103
 
        path = os.path.normpath(os.path.join('..', relpath, path))
 
108
        path = os.path.normpath(os.path.join(relpath, path))
104
109
        fmt = path + ":%d:%s" + eol_marker
105
110
        for line in open(path):
106
111
            res = patternc.search(line)