def _findbundle(repo, rev): """Returns the backup bundle that contains the given rev. If found, it returns the bundle peer and the full rev hash. If not found, it return None and the given rev value. """ ui = repo.ui backuppath = repo.localvfs.join("strip-backup") backups = filter(os.path.isfile, glob.glob(backuppath + "/*.hg")) backups.sort(key=lambda x: os.path.getmtime(x), reverse=True) for backup in backups: # Much of this is copied from the hg incoming logic source = os.path.relpath(backup, pycompat.getcwd()) source = ui.expandpath(source) source, branches = hg.parseurl(source) other = hg.peer(repo, {}, source) quiet = ui.quiet try: ui.quiet = True ret = bundlerepo.getremotechanges(ui, repo, other, None, None, None) localother, chlist, cleanupfn = ret for node in chlist: if hex(node).startswith(rev): return other, node except error.LookupError: continue finally: ui.quiet = quiet return None, rev
def debugnetwork(ui, repo, remote="default", **opts): """debug the network connection to a remote""" alltests = not any(opts.get(opt) for opt in ["connection", "speed"]) ui.status(_("Remote name: %s\n") % remote, component="debugnetwork") path, branches = hg.parseurl(repo.ui.expandpath(remote)) ui.status(_("Remote url: %s\n") % path, component="debugnetwork") url = util.url(path) if url.scheme == "ssh": checkspeed = checkhgspeed checkserverhostname = checksshcommand servertype = "Mercurial" else: checkspeed = checkspeedhttp checkserverhostname = checkmononokehost servertype = "Mononoke" if url.port is None: url.port = "443" if alltests or opts.get("connection"): addrinfos = checkdnsresolution(ui, url) if not addrinfos: msg = _("Failed to look-up the server in DNS.\n") ui.status(msg, component=_("debugnetwork")) return 2 if not checkreachability(ui, url, addrinfos): msg = _("Failed to connect to the server on any address.\n") ui.status(msg, component=_("debugnetwork")) return 3 if not checkserverhostname(ui, url, opts): msg = _("Failed to connect to check %s server hostname.\n" ) % servertype ui.status(msg, component=_("debugnetwork")) return 4 if servertype == "Mercurial" and not checkhgserver( ui, repo, opts, path): msg = _("Failed to connect to Mercurial on the server.\n") ui.status(msg, component=_("debugnetwork")) return 5 if alltests or opts.get("speed"): if not checkspeed(ui, url, opts): msg = _( "Failed to check %s server connection speed.\n") % servertype ui.status(msg, component=_("debugnetwork")) return 6
def debugnetwork(ui, repo, remote="default", **opts): """debug the network connection to a remote""" alltests = not any(opts.get(opt) for opt in ["connection", "speed"]) ui.status(_("Remote name: %s\n") % remote, component="debugnetwork") path, branches = hg.parseurl(repo.ui.expandpath(remote)) ui.status(_("Remote url: %s\n") % path, component="debugnetwork") url = util.url(path) if url.scheme != "ssh": ui.status(_("Not checking network as remote is not an ssh peer")) return 1 if alltests or opts.get("connection"): addrinfos = checkdnsresolution(ui, url) if not addrinfos: msg = _("Failed to look-up the server in DNS.\n") ui.status(msg, component=_("debugnetwork")) return 2 if not checkreachability(ui, url, addrinfos): msg = _("Failed to connect to the server on any address.\n") ui.status(msg, component=_("debugnetwork")) return 3 if not checksshcommand(ui, url, opts): msg = _("Failed to connect to SSH on the server.\n") ui.status(msg, component=_("debugnetwork")) return 4 if not checkhgserver(ui, repo, opts, path): msg = _("Failed to connect to Mercurial on the server.\n") ui.status(msg, component=_("debugnetwork")) return 5 if alltests or opts.get("speed"): if not checkhgspeed(ui, url, opts): msg = _("Failed to check Mercurial server connection speed.\n") ui.status(msg, component=_("debugnetwork")) return 6
def gitgetmeta(ui, repo, source="default"): """get git metadata from a server that supports fb_gitmeta""" source, branch = hg.parseurl(ui.expandpath(source)) other = hg.peer(repo, {}, source) ui.status(_("getting git metadata from %s\n") % util.hidepassword(source)) kwargs = {"bundlecaps": exchange.caps20to10(repo)} capsblob = bundle2.encodecaps(bundle2.getrepocaps(repo)) kwargs["bundlecaps"].add("bundle2=" + util.urlreq.quote(capsblob)) # this would ideally not be in the bundlecaps at all, but adding new kwargs # for wire transmissions is not possible as of Mercurial d19164a018a1 kwargs["bundlecaps"].add("fb_gitmeta") kwargs["heads"] = [nullid] kwargs["cg"] = False kwargs["common"] = _getcommonheads(repo) bundle = other.getbundle("pull", **kwargs) try: op = bundle2.processbundle(repo, bundle) except error.BundleValueError as exc: raise error.Abort("missing support for %s" % exc) writebytes = op.records["fb:gitmeta:writebytes"] ui.status(_("wrote %d files (%d bytes)\n") % (len(writebytes), sum(writebytes)))
def testparse(url, branch=[]): print("%s, branches: %r" % hg.parseurl(url, branch))
def _dopull(orig, ui, repo, source="default", **opts): # Copy paste from `pull` command source, branches = hg.parseurl(ui.expandpath(source), opts.get("branch")) scratchbookmarks = {} unfi = repo.unfiltered() unknownnodes = [] pullbookmarks = opts.get("bookmark") or [] for rev in opts.get("rev", []): if repo._scratchbranchmatcher.match(rev): # rev is a scratch bookmark, treat it as a bookmark pullbookmarks.append(rev) elif rev not in unfi: unknownnodes.append(rev) if pullbookmarks: realbookmarks = [] revs = opts.get("rev") or [] for bookmark in pullbookmarks: if repo._scratchbranchmatcher.match(bookmark): # rev is not known yet # it will be fetched with listkeyspatterns next scratchbookmarks[bookmark] = "REVTOFETCH" else: realbookmarks.append(bookmark) if scratchbookmarks: other = hg.peer(repo, opts, source) fetchedbookmarks = other.listkeyspatterns( "bookmarks", patterns=scratchbookmarks) for bookmark in scratchbookmarks: if bookmark not in fetchedbookmarks: raise error.Abort("remote bookmark %s not found!" % bookmark) scratchbookmarks[bookmark] = fetchedbookmarks[bookmark] revs.append(fetchedbookmarks[bookmark]) opts["bookmark"] = realbookmarks opts["rev"] = [rev for rev in revs if rev not in scratchbookmarks] # Pulling revisions that were filtered results in a error. # Let's revive them. unfi = repo.unfiltered() torevive = [] for rev in opts.get("rev", []): try: repo[rev] except error.FilteredRepoLookupError: torevive.append(rev) except error.RepoLookupError: pass if obsolete.isenabled(repo, obsolete.createmarkersopt): obsolete.revive([unfi[r] for r in torevive]) visibility.add(repo, [unfi[r].node() for r in torevive]) if scratchbookmarks or unknownnodes: # Set anyincoming to True extensions.wrapfunction(discovery, "findcommonincoming", _findcommonincoming) try: # Remote scratch bookmarks will be deleted because remotenames doesn't # know about them. Let's save it before pull and restore after remotescratchbookmarks = bookmarks.readremotebookmarks( ui, repo, source) result = orig(ui, repo, source, **opts) # TODO(stash): race condition is possible # if scratch bookmarks was updated right after orig. # But that's unlikely and shouldn't be harmful. with repo.wlock(), repo.lock(), repo.transaction("pull"): if bookmarks.remotebookmarksenabled(ui): remotescratchbookmarks.update(scratchbookmarks) bookmarks.saveremotebookmarks(repo, remotescratchbookmarks, source) else: bookmarks.savelocalbookmarks(repo, scratchbookmarks) return result finally: if scratchbookmarks: extensions.unwrapfunction(discovery, "findcommonincoming")
def expushcmd(orig, ui, repo, dest=None, **opts): # during the upgrade from old to new remotenames, tooling that uses --force # will continue working if remotenames.forcecompat is enabled forcecompat = ui.configbool("remotenames", "forcecompat") # needed for discovery method opargs = { "delete": opts.get("delete"), "to": opts.get("to"), "create": opts.get("create") or (opts.get("force") and forcecompat), "allowanon": opts.get("allow_anon") or repo.ui.configbool("remotenames", "pushanonheads") or (opts.get("force") and forcecompat), "nonforwardmove": opts.get("non_forward_move") or repo.ui.configbool("remotenames", "allownonfastforward") or (opts.get("force") and forcecompat), } if opargs["delete"]: flag = None for f in ("to", "bookmark", "branch", "rev"): if opts.get(f): flag = f break if flag: msg = _("do not specify --delete and " "--%s at the same time") % flag raise error.Abort(msg) # we want to skip pushing any changesets while deleting a remote # bookmark, so we send the null revision opts["rev"] = ["null"] return orig(ui, repo, dest, opargs=opargs, **opts) revs = opts.get("rev") paths = dict((path, url) for path, url in ui.configitems("paths")) # XXX T58629567: The following line triggers an infinite loop in pyre, let's disable it for now. if not typing.TYPE_CHECKING: revrenames = dict( (v, k) for k, v in pycompat.iteritems(_getrenames(ui))) origdest = dest defaultpush = ui.paths.get("default-push") or ui.paths.get("default") if defaultpush: defaultpush = defaultpush.loc if ((not dest or dest == defaultpush) and not opargs["to"] and not revs and _tracking(ui)): current = repo._activebookmark tracking = _readtracking(repo) ui.debug("tracking on %s %s\n" % (current, tracking)) if current and current in tracking: track = tracking[current] path, book = splitremotename(track) # un-rename a path, if needed path = revrenames.get(path, path) if book and path in paths: dest = path opargs["to"] = book # un-rename passed path dest = revrenames.get(dest, dest) # if dest was renamed to default but we aren't specifically requesting # to push to default, change dest to default-push, if available if not origdest and dest == "default" and "default-push" in paths: dest = "default-push" # get the actual path we will push to so we can do some url sniffing for check in [ # dest may be a path name, or an actual url paths.get(dest, dest), paths.get("default-push"), paths.get("default"), ]: if check: # hggit does funky things on push. Just call direct. if check.startswith("git+"): return orig(ui, repo, dest, opargs=opargs, **opts) # Once we have found the path where we are pushing, do not continue # checking for places we are not pushing. break if not opargs["to"]: if ui.configbool("remotenames", "forceto"): msg = _("must specify --to when pushing") hint = _("see configuration option %s") % "remotenames.forceto" raise error.Abort(msg, hint=hint) if not revs: opts["rev"] = _pushrevs(repo, ui, None) return orig(ui, repo, dest, opargs=opargs, **opts) if opts.get("bookmark"): msg = _("do not specify --to/-t and --bookmark/-B at the same time") raise error.Abort(msg) if opts.get("branch"): msg = _("do not specify --to/-t and --branch/-b at the same time") raise error.Abort(msg) # if we are not using the original push command implementation, make sure # pushvars is included in opargs pushvars = opts.get("pushvars") if pushvars: opargs["pushvars"] = pushvars if revs: revs = [repo.lookup(r) for r in repo.anyrevs(revs, user=True)] else: revs = _pushrevs(repo, ui, ".") if len(revs) != 1: msg = _("--to requires exactly one rev to push") hint = _("use --rev BOOKMARK or omit --rev for current commit (.)") raise error.Abort(msg, hint=hint) rev = revs[0] # big can o' copypasta from commands.push dest = ui.expandpath(dest or "default-push", dest or "default") dest, branches = hg.parseurl(dest, opts.get("branch")) try: other = hg.peer(repo, opts, dest) except error.RepoError: if dest == "default-push": hint = _('see the "path" section in "hg help config"') raise error.Abort(_("default repository not configured!"), hint=hint) else: raise # all checks pass, go for it! node = repo.lookup(rev) ui.status_err( _("pushing rev %s to destination %s bookmark %s\n") % (short(node), dest, opargs["to"])) force = opts.get("force") bookmark = opargs["to"] pattern = ui.config("remotenames", "disallowedto") if pattern and re.match(pattern, bookmark): msg = _("this remote bookmark name is not allowed") hint = ui.config("remotenames", "disallowedhint") or _("use another bookmark name") raise error.Abort(msg, hint=hint) # NB: despite the name, 'revs' doesn't work if it's a numeric rev pushop = exchange.push(repo, other, force, revs=[node], bookmarks=(opargs["to"], ), opargs=opargs) result = not pushop.cgresult if pushop.bkresult is not None: if pushop.bkresult == 2: result = 2 elif not result and pushop.bkresult: result = 2 return result