Esempio n. 1
0
def repository(_ui=None, path='', create=False, bundle=None):
    '''Returns a subclassed Mercurial repository to which new
    THG-specific methods have been added. The repository object
    is obtained using mercurial.hg.repository()'''
    if bundle:
        if _ui is None:
            _ui = uimod.ui()
        repo = bundlerepo.bundlerepository(_ui, path, bundle)
        repo.__class__ = _extendrepo(repo)
        repo._pyqtobj = ThgRepoWrapper(repo)
        return repo
    if create or path not in _repocache:
        if _ui is None:
            _ui = uimod.ui()
        try:
            repo = hg.repository(_ui, path, create)
            repo.__class__ = _extendrepo(repo)
            repo._pyqtobj = ThgRepoWrapper(repo)
            _repocache[path] = repo
            return repo
        except EnvironmentError:
            raise error.RepoError('Cannot open repository at %s' % path)
    if not os.path.exists(os.path.join(path, '.hg/')):
        del _repocache[path]
        # this error must be in local encoding
        raise error.RepoError('%s is not a valid repository' % path)
    return _repocache[path]
Esempio n. 2
0
def download_patch(source, lastrev, patchbranch):
    from mercurial import hg, ui, localrepo, commands, bundlerepo
    UI = ui.ui()
    bundle = tempfile.mktemp(dir="/var/tmp")
    cwd = os.getcwd()
    os.chdir(base)
    try:
        repo0 = hg.repository(UI,base)
        repo0.ui.quiet=True
        repo0.ui.pushbuffer()
        commands.pull(repo0.ui, repo0, quiet=True)
        repo0.ui.popbuffer() # discard all pull output
        # find out what the head revision of the given branch is
        repo0.ui.pushbuffer()
        head = repo0.ui.popbuffer().strip()
        repo0.ui.pushbuffer()
        if commands.incoming(repo0.ui, repo0, source=source, branch=[patchbranch], bundle=bundle, force=False) != 0:
            raise ValueError, "Repository contains no changes"
        rhead = repo0.ui.popbuffer()
        if rhead:
            # output is a list of revisions, one per line. last line should be newest revision
            rhead = rhead.splitlines()[-1].split(':')[1]
        if rhead == lastrev:
            raise NotChanged
        repo=bundlerepo.bundlerepository(UI, ".", bundle)
        repo.ui.pushbuffer()
        old = 'max(ancestors(branch("%s"))-outgoing("%s"))' % (patchbranch, base)
        commands.diff(repo.ui, repo, rev=[old, patchbranch])
        result = repo.ui.popbuffer()
    finally:
        os.chdir(cwd)
        if os.path.exists(bundle):
            os.unlink(bundle)
    return result, rhead
Esempio n. 3
0
def repository(_ui=None, path='', bundle=None):
    '''Returns a subclassed Mercurial repository to which new
    THG-specific methods have been added. The repository object
    is obtained using mercurial.hg.repository()'''
    if bundle:
        if _ui is None:
            _ui = uimod.ui()
        repo = bundlerepo.bundlerepository(_ui, path, bundle)
        repo.__class__ = _extendrepo(repo)
        agent = RepoAgent(repo)
        return agent.rawRepo()
    if path not in _repocache:
        if _ui is None:
            _ui = uimod.ui()
        try:
            repo = hg.repository(_ui, path)
            # get unfiltered repo in version safe manner
            repo = getattr(repo, 'unfiltered', lambda: repo)()
            repo.__class__ = _extendrepo(repo)
            agent = RepoAgent(repo)
            _repocache[path] = agent.rawRepo()
            return agent.rawRepo()
        except EnvironmentError:
            raise error.RepoError('Cannot open repository at %s' % path)
    if not os.path.exists(os.path.join(path, '.hg/')):
        del _repocache[path]
        # this error must be in local encoding
        raise error.RepoError('%s is not a valid repository' % path)
    return _repocache[path]
Esempio n. 4
0
def incoming(repo, origin, revs):
    '''return a list of incoming changesets'''
    if revs:
        revs = [origin.lookup(rev) for rev in revs]
    common, incoming, rheads = findcommonincoming(repo,
                                                  origin,
                                                  heads=revs,
                                                  force=False)
    if not incoming:
        return incoming
    if not origin.local():
        # create a bundle (uncompressed if other repo is not local)
        if not revs and origin.capable('changegroupsubset'):
            revs = rheads

        if not revs:
            cg = origin.changegroup(incoming, 'incoming')
        else:
            cg = origin.changegroupsubset(incoming, revs, 'incoming')
        fname = changegroup.writebundle(cg, None, "HG10UN")
        origin = bundlerepo.bundlerepository(repo.ui, repo.root, fname)
    incoming = origin.changelog.nodesbetween(incoming, revs)[0]
    if hasattr(origin, 'close'):
        origin.close()
    return incoming
Esempio n. 5
0
def repository(_ui=None, path='', create=False, bundle=None):
    '''Returns a subclassed Mercurial repository to which new
    THG-specific methods have been added. The repository object
    is obtained using mercurial.hg.repository()'''
    if bundle:
        if _ui is None:
            _ui = uimod.ui()
        repo = bundlerepo.bundlerepository(_ui, path, bundle)
        repo.__class__ = _extendrepo(repo)
        repo._pyqtobj = ThgRepoWrapper(repo)
        return repo
    if create or path not in _repocache:
        if _ui is None:
            _ui = uimod.ui()
        try:
            repo = hg.repository(_ui, path, create)
            repo.__class__ = _extendrepo(repo)
            repo._pyqtobj = ThgRepoWrapper(repo)
            _repocache[path] = repo
            return repo
        except EnvironmentError:
            raise error.RepoError('Cannot open repository at %s' % path)
    if not os.path.exists(os.path.join(path, '.hg/')):
        del _repocache[path]
        # this error must be in local encoding
        raise error.RepoError('%s is not a valid repository' % path)
    return _repocache[path]
Esempio n. 6
0
def repository(_ui=None, path='', bundle=None):
    '''Returns a subclassed Mercurial repository to which new
    THG-specific methods have been added. The repository object
    is obtained using mercurial.hg.repository()'''
    if bundle:
        if _ui is None:
            _ui = uimod.ui()
        repo = bundlerepo.bundlerepository(_ui, path, bundle)
        repo.__class__ = _extendrepo(repo)
        agent = RepoAgent(repo)
        return agent.rawRepo()
    if path not in _repocache:
        if _ui is None:
            _ui = uimod.ui()
        try:
            repo = hg.repository(_ui, path)
            # get unfiltered repo in version safe manner
            repo = getattr(repo, 'unfiltered', lambda: repo)()
            repo.__class__ = _extendrepo(repo)
            agent = RepoAgent(repo)
            _repocache[path] = agent.rawRepo()
            return agent.rawRepo()
        except EnvironmentError:
            raise error.RepoError('Cannot open repository at %s' % path)
    if not os.path.exists(os.path.join(path, '.hg/')):
        del _repocache[path]
        # this error must be in local encoding
        raise error.RepoError('%s is not a valid repository' % path)
    return _repocache[path]
Esempio n. 7
0
	def incoming(self):
		limit = cmdutil.loglimit(opts)
		source, revs, checkout = hg.parseurl(ui.expandpath(source), opts.get('rev'))
		other = hg.repository(cmdutil.remoteui(repo, opts), source)
		ui.status(_('comparing with %s\n') % url.hidepassword(source))
		if revs:
			revs = [other.lookup(rev) for rev in revs]
		common, incoming, rheads = repo.findcommonincoming(other, heads=revs,
                                                       force=opts["force"])
		if not incoming:
			try:
				os.unlink(opts["bundle"])
			except:
				pass
			ui.status(_("no changes found\n"))
			return 1

		cleanup = None
		try:
			fname = opts["bundle"]
			if fname or not other.local():
				# create a bundle (uncompressed if other repo is not local)

				if revs is None and other.capable('changegroupsubset'):
					revs = rheads

				if revs is None:
					cg = other.changegroup(incoming, "incoming")
				else:
					cg = other.changegroupsubset(incoming, revs, 'incoming')
				bundletype = other.local() and "HG10BZ" or "HG10UN"
				fname = cleanup = changegroup.writebundle(cg, fname, bundletype)
				# keep written bundle?
				if opts["bundle"]:
					cleanup = None
				if not other.local():
					# use the created uncompressed bundlerepo
					other = bundlerepo.bundlerepository(ui, repo.root, fname)

			o = other.changelog.nodesbetween(incoming, revs)[0]
			if opts.get('newest_first'):
				o.reverse()
			displayer = cmdutil.show_changeset(ui, other, opts)
			count = 0
			for n in o:
				if count >= limit:
					break
				parents = [p for p in other.changelog.parents(n) if p != nullid]
				if opts.get('no_merges') and len(parents) == 2:
					continue
				count += 1
				displayer.show(other[n])
		finally:
			if hasattr(other, 'close'):
				other.close()
			if cleanup:
				os.unlink(cleanup)
Esempio n. 8
0
def gincoming(ui, repo, source="default", **opts):
    """show the incoming changesets alongside an ASCII revision graph

    Print the incoming changesets alongside a revision graph drawn with
    ASCII characters.

    Nodes printed as an @ character are parents of the working
    directory.
    """

    check_unsupported_flags(opts)
    source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch'))
    other = hg.repository(cmdutil.remoteui(repo, opts), source)
    revs, checkout = hg.addbranchrevs(repo, other, branches, opts.get('rev'))
    ui.status(_('comparing with %s\n') % url.hidepassword(source))
    if revs:
        revs = [other.lookup(rev) for rev in revs]
    incoming = repo.findincoming(other, heads=revs, force=opts["force"])
    if not incoming:
        try:
            os.unlink(opts["bundle"])
        except:
            pass
        ui.status(_("no changes found\n"))
        return

    cleanup = None
    try:

        fname = opts["bundle"]
        if fname or not other.local():
            # create a bundle (uncompressed if other repo is not local)
            if revs is None:
                cg = other.changegroup(incoming, "incoming")
            else:
                cg = other.changegroupsubset(incoming, revs, 'incoming')
            bundletype = other.local() and "HG10BZ" or "HG10UN"
            fname = cleanup = changegroup.writebundle(cg, fname, bundletype)
            # keep written bundle?
            if opts["bundle"]:
                cleanup = None
            if not other.local():
                # use the created uncompressed bundlerepo
                other = bundlerepo.bundlerepository(ui, repo.root, fname)

        chlist = other.changelog.nodesbetween(incoming, revs)[0]
        revdag = graphrevs(other, chlist, opts)
        displayer = show_changeset(ui, other, opts, buffered=True)
        showparents = [ctx.node() for ctx in repo[None].parents()]
        generate(ui, revdag, displayer, showparents, asciiedges)

    finally:
        if hasattr(other, 'close'):
            other.close()
        if cleanup:
            os.unlink(cleanup)
Esempio n. 9
0
    def getremotechanges(repo, url):
        sourcerepo = ui.expandpath(url)
        source = hg.repository(ui, sourcerepo)
        incoming = repo.findincoming(source, force=True)
        if not incoming:
            return (source, None, None)

        bundle = None
        if not source.local():
            cg = source.changegroup(incoming, 'incoming')
            bundle = changegroup.writebundle(cg, None, 'HG10UN')
            source = bundlerepo.bundlerepository(ui, repo.root, bundle)

        return (source, incoming, bundle)
Esempio n. 10
0
    def getremotechanges(repo, url):
        sourcerepo = ui.expandpath(url)
        source = hg.repository(ui, sourcerepo)
        incoming = repo.findincoming(source, force=True)
        if not incoming:
            return (source, None, None)

        bundle = None
        if not source.local():
            cg = source.changegroup(incoming, 'incoming')
            bundle = changegroup.writebundle(cg, None, 'HG10UN')
            source = bundlerepo.bundlerepository(ui, repo.root, bundle)

        return (source, incoming, bundle)
Esempio n. 11
0
    def getremotechanges(repo, url):
        sourcerepo = ui.expandpath(url)
        source = hg.repository(ui, sourcerepo)
        common, incoming, rheads = repo.findcommonincoming(source, force=True)
        if not incoming:
            return (source, None, None)

        bundle = None
        if not source.local():
            if source.capable('changegroupsubset'):
                cg = source.changegroupsubset(incoming, rheads, 'incoming')
            else:
                cg = source.changegroup(incoming, 'incoming')
            bundle = changegroup.writebundle(cg, None, 'HG10UN')
            source = bundlerepo.bundlerepository(ui, repo.root, bundle)

        return (source, incoming, bundle)
Esempio n. 12
0
    def getremotechanges(repo, url):
        sourcerepo = ui.expandpath(url)
        source = hg.repository(ui, sourcerepo)
        common, incoming, rheads = repo.findcommonincoming(source, force=True)
        if not incoming:
            return (source, None, None)

        bundle = None
        if not source.local():
            if source.capable('changegroupsubset'):
                cg = source.changegroupsubset(incoming, rheads, 'incoming')
            else:
                cg = source.changegroup(incoming, 'incoming')
            bundle = changegroup.writebundle(cg, None, 'HG10UN')
            source = bundlerepo.bundlerepository(ui, repo.root, bundle)

        return (source, incoming, bundle)
Esempio n. 13
0
def incoming(wdrepo, masterrepo):
    try:
        return wdrepo.findincoming(masterrepo)
    except AttributeError:
        from mercurial import hg, discovery
        revs, checkout = hg.addbranchrevs(wdrepo, masterrepo, ('', []), None)
        common, incoming, rheads = discovery.findcommonincoming(
            wdrepo, masterrepo, heads=revs)
        if not masterrepo.local():
            from mercurial import bundlerepo, changegroup
            if revs is None and masterrepo.capable('changegroupsubset'):
                revs = rheads
            if revs is None:
                cg = masterrepo.changegroup(incoming, "incoming")
            else:
                cg = masterrepo.changegroupsubset(incoming, revs, 'incoming')
            fname = changegroup.writebundle(cg, None, "HG10UN")
            # use the created uncompressed bundlerepo
            masterrepo = bundlerepo.bundlerepository(wdrepo.ui, wdrepo.root, fname)
        return masterrepo.changelog.nodesbetween(incoming, revs)[0]
Esempio n. 14
0
def download_patch(source, lastrev, patchbranch):
    from mercurial import hg, ui, localrepo, commands, bundlerepo
    UI = ui.ui()
    bundle = tempfile.mktemp(dir="/var/tmp")
    cwd = os.getcwd()
    os.chdir(base)
    try:
        repo0 = hg.repository(UI, base)
        repo0.ui.quiet = True
        repo0.ui.pushbuffer()
        commands.pull(repo0.ui, repo0, quiet=True)
        repo0.ui.popbuffer()  # discard all pull output
        # find out what the head revision of the given branch is
        repo0.ui.pushbuffer()
        head = repo0.ui.popbuffer().strip()
        repo0.ui.pushbuffer()
        if commands.incoming(repo0.ui,
                             repo0,
                             source=source,
                             branch=[patchbranch],
                             bundle=bundle,
                             force=False) != 0:
            raise ValueError, "Repository contains no changes"
        rhead = repo0.ui.popbuffer()
        if rhead:
            # output is a list of revisions, one per line. last line should be newest revision
            rhead = rhead.splitlines()[-1].split(':')[1]
        if rhead == lastrev:
            raise NotChanged
        repo = bundlerepo.bundlerepository(UI, ".", bundle)
        repo.ui.pushbuffer()
        old = 'max(ancestors(branch("%s"))-outgoing("%s"))' % (patchbranch,
                                                               base)
        commands.diff(repo.ui, repo, rev=[old, patchbranch])
        result = repo.ui.popbuffer()
    finally:
        os.chdir(cwd)
        if os.path.exists(bundle):
            os.unlink(bundle)
    return result, rhead
Esempio n. 15
0
def incoming(repo, origin, revs):
    '''return a list of incoming changesets'''
    if revs:
        revs = [origin.lookup(rev) for rev in revs]
    common, incoming, rheads = findcommonincoming(repo, origin, heads=revs, force=False)
    if not incoming:
        return incoming
    if not origin.local():
        # create a bundle (uncompressed if other repo is not local)
        if not revs and origin.capable('changegroupsubset'):
            revs = rheads

        if not revs:
            cg = origin.changegroup(incoming, 'incoming')
        else:
            cg = origin.changegroupsubset(incoming, revs, 'incoming')
        fname  = changegroup.writebundle(cg, None, "HG10UN")
        origin = bundlerepo.bundlerepository(repo.ui, repo.root, fname)
    incoming = origin.changelog.nodesbetween(incoming, revs)[0]
    if hasattr(origin, 'close'):
        origin.close()
    return incoming
Esempio n. 16
0
def bundle2rebase(op, part):
    '''unbundle a bundle2 containing a changegroup to rebase'''

    params = part.params
    tr = op.gettransaction()
    hookargs = dict(tr.hookargs)

    bundlefile = None
    onto = scmutil.revsingle(op.repo, params['onto'])
    if not params['newhead']:
        if not op.repo.revs('%r and head()', params['onto']):
            raise util.Abort(_('rebase would produce a new head on server'))

    try: # guards bundlefile
        bundlefile = _makebundlefile(part)
        bundle = bundlerepository(op.repo.ui, op.repo.root, bundlefile)
        revs = _getrevs(bundle, onto)

        op.repo.hook("prechangegroup", **hookargs)

        replacements = {}
        added = []

        for rev in revs:
            newrev = _graft(op.repo, onto, rev)
            onto = op.repo[newrev]
            replacements[rev.node()] = onto.node()
            added.append(onto.node())
        _buildobsolete(replacements, bundle, op.repo)
    finally:
        try:
            if bundlefile:
                os.unlink(bundlefile)
        except OSError, e:
            if e.errno != errno.ENOENT:
                raise
Esempio n. 17
0
 def bundlerepo(self):
     return bundlerepo.bundlerepository(self.repo.baseui, self.repo.root,
                                        self.vfs.join(self.fname))
Esempio n. 18
0
 def bundlerepo(self):
     return bundlerepo.bundlerepository(self.repo.baseui, self.repo.root,
                                        self.vfs.join(self.fname))