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 = scmutil.canonpath(self.root, cwd, pats[0]) target = scmutil.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 haskwsource(dest): '''Returns true if dest is a regular file and configured for expansion or a symlink which points to a file configured for expansion. ''' source = repo.dirstate.copied(dest) if 'l' in wctx.flags(source): source = scmutil.canonpath(repo.root, cwd, os.path.realpath(source)) return kwt.match(source)
def init_data(self, pats): """calculate initial values for widgets""" fname = '' target = '' root = self.repo.root cwd = os.getcwd() try: fname = scmutil.canonpath(root, cwd, pats[0]) target = scmutil.canonpath(root, cwd, pats[1]) except: pass os.chdir(root) fname = hglib.tounicode(util.normpath(fname)) if target: target = hglib.tounicode(util.normpath(target)) else: target = fname return (fname, target)
def canonpaths(list): 'Get canonical paths (relative to root) for list of files' # This is a horrible hack. Please remove this when HG acquires a # decent case-folding solution. canonpats = [] cwd = os.getcwd() root = paths.find_root(cwd) for f in list: try: canonpats.append(canonpath(root, cwd, f)) except util.Abort: # Attempt to resolve case folding conflicts. fu = f.upper() cwdu = cwd.upper() if fu.startswith(cwdu): canonpats.append(canonpath(root, cwd, f[len(cwd+os.sep):])) else: # May already be canonical canonpats.append(f) return canonpats
def canonpaths(list): 'Get canonical paths (relative to root) for list of files' # This is a horrible hack. Please remove this when HG acquires a # decent case-folding solution. canonpats = [] cwd = os.getcwd() root = paths.find_root(cwd) for f in list: try: canonpats.append(scmutil.canonpath(root, cwd, f)) except util.Abort: # Attempt to resolve case folding conflicts. fu = f.upper() cwdu = cwd.upper() if fu.startswith(cwdu): canonpats.append( scmutil.canonpath(root, cwd, f[len(cwd + os.sep):])) else: # May already be canonical canonpats.append(f) return canonpats
def copyfile(abssrc, relsrc, otarget, exact): abstarget = scmutil.canonpath(repo.root, cwd, otarget) reltarget = repo.pathto(abstarget, cwd) target = repo.wjoin(abstarget) src = repo.wjoin(abssrc) state = repo.dirstate[abstarget] scmutil.checkportable(ui, abstarget) # check for collisions prevsrc = targets.get(abstarget) if prevsrc is not None: ui.warn(_('%s: not overwriting - %s collides with %s\n') % (reltarget, repo.pathto(abssrc, cwd), repo.pathto(prevsrc, cwd))) return # check for overwrites exists = os.path.lexists(target) if not after and exists or after and state in 'mn': if not opts['force']: ui.warn(_('%s: not overwriting - file exists\n') % reltarget) return if after: if not exists: if rename: ui.warn(_('%s: not recording move - %s does not exist\n') % (relsrc, reltarget)) else: ui.warn(_('%s: not recording copy - %s does not exist\n') % (relsrc, reltarget)) return elif not dryrun: try: if exists: os.unlink(target) targetdir = os.path.dirname(target) or '.' if not os.path.isdir(targetdir): os.makedirs(targetdir) util.copyfile(src, target) srcexists = True except IOError, inst: if inst.errno == errno.ENOENT: ui.warn(_('%s: deleted in working copy\n') % relsrc) srcexists = False else: ui.warn(_('%s: cannot copy - %s\n') % (relsrc, inst.strerror)) return True # report a failure
def targetpathfn(pat, dest, srcs): if os.path.isdir(pat): abspfx = scmutil.canonpath(repo.root, cwd, pat) abspfx = util.localpath(abspfx) if destdirexists: striplen = len(os.path.split(abspfx)[0]) else: striplen = len(abspfx) if striplen: striplen += len(os.sep) res = lambda p: os.path.join(dest, util.localpath(p)[striplen:]) elif destdirexists: res = lambda p: os.path.join(dest, os.path.basename(util.localpath(p))) else: res = lambda p: dest return res
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 = scmutil.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
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 = scmutil.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
def targetpathafterfn(pat, dest, srcs): if matchmod.patkind(pat): # a mercurial pattern res = lambda p: os.path.join(dest, os.path.basename(util.localpath(p))) else: abspfx = scmutil.canonpath(repo.root, cwd, pat) if len(abspfx) < len(srcs[0][0]): # A directory. Either the target path contains the last # component of the source path or it does not. def evalpath(striplen): score = 0 for s in srcs: t = os.path.join(dest, util.localpath(s[0])[striplen:]) if os.path.lexists(t): score += 1 return score abspfx = util.localpath(abspfx) striplen = len(abspfx) if striplen: striplen += len(os.sep) if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): score = evalpath(striplen) striplen1 = len(os.path.split(abspfx)[0]) if striplen1: striplen1 += len(os.sep) if evalpath(striplen1) > score: striplen = striplen1 res = lambda p: os.path.join(dest, util.localpath(p)[striplen:]) else: # a file if destdirexists: res = lambda p: os.path.join(dest, os.path.basename(util.localpath(p))) else: res = lambda p: dest return res
def makestandin(relpath): path = scmutil.canonpath(repo.root, repo.getcwd(), relpath) return os.path.join(repo.wjoin(lfutil.standin(path)))
def cleanpath(repo, path): path = path.lstrip('/') return scmutil.canonpath(repo.root, '', path)