def snapshot_node(ui, repo, files, node, tmproot): """ snapshot files as of some revision (adapted from Extdiff extension) """ mf = repo.changectx(node).manifest() dirname = os.path.basename(repo.root) if dirname == "": dirname = "root" dirname = "%s.%s" % (dirname, short(node)) base = os.path.join(tmproot, dirname) try: os.mkdir(base) except: pass ui.note(_("making snapshot of %d files from rev %s\n") % (len(files), short(node))) for fn in files: if not fn in mf: # skipping new file after a merge ? continue wfn = util.pconvert(fn) ui.note(" %s\n" % wfn) dest = os.path.join(base, wfn) destdir = os.path.dirname(dest) if not os.path.isdir(destdir): os.makedirs(destdir) data = repo.wwritedata(wfn, repo.file(wfn).read(mf[wfn])) open(dest, "wb").write(data) return dirname
def snapshot_node(ui, repo, files, node, tmproot): ''' snapshot files as of some revision (adapted from Extdiff extension) ''' ctx = repo[node] mf = ctx.manifest() dirname = os.path.basename(repo.root) if dirname == '': dirname = 'root' dirname = '%s.%s' % (dirname, str(ctx)) base = os.path.join(tmproot, dirname) try: os.mkdir(base) except: pass ui.note(_('making snapshot of %d files from rev %s\n') % (len(files), str(ctx))) for fn in files: if not fn in mf: # skipping new file after a merge ? continue wfn = util.pconvert(fn) ui.note(' %s\n' % wfn) dest = os.path.join(base, wfn) destdir = os.path.dirname(dest) if not os.path.isdir(destdir): os.makedirs(destdir) data = repo.wwritedata(wfn, repo.file(wfn).read(mf[wfn])) open(dest, 'wb').write(data) return dirname
def _activepath(self, remote): conf = config.config() try: rc = self.vfs.join('hgrc') except AttributeError: # old hg rc = self.join('hgrc') if os.path.exists(rc): with open(rc) as fp: conf.parse('.hgrc', fp.read(), include=conf.read) realpath = '' if 'paths' in conf: for path, uri in conf['paths'].items(): for s in schemes.schemes.iterkeys(): if uri.startswith('%s://' % s): # TODO: refactor schemes so we don't # duplicate this logic ui.note('performing schemes expansion with ' 'scheme %s\n' % s) scheme = hg.schemes[s] parts = uri.split('://', 1)[1].split('/', scheme.parts) if len(parts) > scheme.parts: tail = parts[-1] parts = parts[:-1] else: tail = '' context = dict((str(i+1), v) for i, v in enumerate(parts)) uri = ''.join(scheme.templater.process( scheme.url, context)) + tail uri = self.ui.expandpath(uri) if remote.local(): uri = os.path.realpath(uri) rpath = getattr(remote, 'root', None) if rpath is None: # Maybe a localpeer? (hg@1ac628cd7113, 2.3) rpath = getattr(getattr(remote, '_repo', None), 'root', None) else: rpath = getattr(remote, 'url', lambda : remote._url)() if uri.startswith('http'): try: uri = url.url(uri).authinfo()[0] except AttributeError: try: uri = util.url(uri).authinfo()[0] except AttributeError: uri = url.getauthinfo(uri)[0] uri = uri.rstrip('/') rpath = rpath.rstrip('/') if uri == rpath: realpath = path # prefer a non-default name to default if path != 'default': break return realpath
def dodiffwrapper(): try: dodiff(tmproot) finally: ui.note(_('cleaning up temp directory\n')) try: shutil.rmtree(tmproot) except (IOError, OSError), e: # Leaking temporary files, fix your diff tool config ui.note(_('unable to clean temp directory: %s\n'), str(e))
def _activepath(self, remote): conf = config.config() rc = self.join("hgrc") if os.path.exists(rc): fp = open(rc) conf.parse(".hgrc", fp.read()) fp.close() realpath = "" if "paths" in conf: for path, uri in conf["paths"].items(): for s in schemes.schemes.iterkeys(): if uri.startswith("%s://" % s): # TODO: refactor schemes so we don't # duplicate this logic ui.note("performing schemes expansion with " "scheme %s\n" % s) scheme = hg.schemes[s] parts = uri.split("://", 1)[1].split("/", scheme.parts) if len(parts) > scheme.parts: tail = parts[-1] parts = parts[:-1] else: tail = "" context = dict((str(i + 1), v) for i, v in enumerate(parts)) uri = "".join(scheme.templater.process(scheme.url, context)) + tail uri = self.ui.expandpath(uri) if remote.local(): uri = os.path.realpath(uri) rpath = getattr(remote, "root", None) if rpath is None: # Maybe a localpeer? (hg@1ac628cd7113, 2.3) rpath = getattr(getattr(remote, "_repo", None), "root", None) else: rpath = remote._url if uri.startswith("http"): try: uri = url.url(uri).authinfo()[0] except AttributeError: try: uri = util.url(uri).authinfo()[0] except AttributeError: uri = url.getauthinfo(uri)[0] uri = uri.rstrip("/") rpath = rpath.rstrip("/") if uri == rpath: realpath = path # prefer a non-default name to default if path != "default": break return realpath