def init_data(self, ui, pats): """calculate initial values for widgets""" fname = '' target = '' cwd = os.getcwd() try: self.root = paths.find_root() self.repo = thgrepo.repository(ui, path=self.root) except (error.RepoError): qtlib.ErrorMsgBox(_('Error'), _('Could not find or initialize the repository ' 'from folder<p>%s</p>' % cwd)) return ('', '') try: fname = hglib.canonpath(self.root, cwd, pats[0]) target = hglib.canonpath(self.root, cwd, pats[1]) except: pass os.chdir(self.root) fname = hglib.tounicode(util.normpath(fname)) if target: target = hglib.tounicode(util.normpath(target)) else: target = fname return (fname, target)
def get_files_from_listfile(): global _lines global _linesutf8 lines = [] need_to_utf8 = False if os.name == 'nt': try: fixutf8 = extensions.find("fixutf8") if fixutf8: need_to_utf8 = True except KeyError: pass if need_to_utf8: lines += _linesutf8 for l in _lines: lines.append(hglib.toutf(l)) else: lines += _lines for l in _linesutf8: lines.append(hglib.fromutf(l)) # Convert absolute file paths to repo/cwd canonical cwd = os.getcwd() root = paths.find_root(cwd) if not root: return lines if cwd == root: cwd_rel = '' else: cwd_rel = cwd[len(root+os.sep):] + os.sep files = [] for f in lines: try: cpath = hglib.canonpath(root, cwd, f) # canonpath will abort on .hg/ paths except util.Abort: continue if cpath.startswith(cwd_rel): cpath = cpath[len(cwd_rel):] files.append(cpath) else: files.append(f) return files