def revset_fromgit(repo, subset, x): '''``fromgit()`` Select changesets that originate from Git. ''' args = revset.getargs(x, 0, 0, "fromgit takes no arguments") git = GitHandler(repo, repo.ui) return [r for r in subset if git.map_git_get(repo[r].hex()) is not None]
def write(self, *args, **kwargs): super(ext_ui, self).write(*args, **kwargs) # Changesets are printed twice in the current hg code, always with label log.changeset if kwargs.has_key('label') and kwargs['label'] == 'log.changeset' and len(args) and cached_repo: global changeset_re global cached_git if not changeset_re: changeset_re = re.compile('(\d+):\w+(\s*)$') match = changeset_re.search(args[0]) if match: # Parse out from the changeset string: The numeric local rev, and the line terminator # (So that we know if we need to print the git revision with a newline or not) rev, terminator = match.group(1,2) try: # Works in Mercurial 1.9.x from mercurial.templatefilters import hexfilter, short except: # Works in Mercurial 1.8.x from mercurial.templatefilters import filters hexfilter = filters["hex"] short = filters["short"] hgsha = cached_repo.lookup(int(rev)) # Ints are efficient on lookup if (hgsha): hgsha = hexfilter(hgsha) if not cached_git: cached_git = GitHandler(cached_repo, self) gitsha = cached_git.map_git_get(hgsha) else: # Currently this case is hit when you do hg outgoing. I'm not sure why. gitsha = None if gitsha: if terminator == '\n': # hg log, etc output = _("git-rev: %s\n") else: # hg sum output = "git:%s " super(ext_ui, self).write(output % (short(gitsha)), label='log.gitchangeset')
def __init__(self): self.config_file = os.path.dirname(os.path.abspath(__file__)) + '/config.json' config_data = self.load_configuration() self.command_runner = SystemCommandRunner() self.configuration = ConfigurationLoader(json_config_data=config_data) self.git_handler = GitHandler(project_path=self.configuration.get_project_path_value())
def findoutgoing(self, remote, base=None, heads=None, force=False): if isinstance(remote, gitrepo): git = GitHandler(self, self.ui) base, heads = git.get_refs(remote.path) out, h = super(hgrepo, self).findoutgoing(remote, base, heads, force) return out else: #pragma: no cover return super(hgrepo, self).findoutgoing(remote, base, heads, force)
def _findtags(self): (tags, tagtypes) = super(hgrepo, self)._findtags() git = GitHandler(self, self.ui) for tag, rev in git.tags.iteritems(): tags[tag] = bin(rev) tagtypes[tag] = 'git' return (tags, tagtypes)
def gitnodekw(**args): """:gitnode: String. The Git changeset identification hash, as a 40 hexadecimal digit string.""" node = args['ctx'] repo = args['repo'] git = GitHandler(repo, repo.ui) gitnode = git.map_git_get(node.hex()) if gitnode is None: gitnode = '' return gitnode
def getremotechanges(orig, ui, repo, other, *args, **opts): if isinstance(other, gitrepo.gitrepo): revs = opts.get('onlyheads', opts.get('revs')) git = GitHandler(repo, ui) r, c, cleanup = git.getremotechanges(other, revs) # ugh. This is ugly even by mercurial API compatibility standards if 'onlyheads' not in orig.func_code.co_varnames: cleanup = None return r, c, cleanup return orig(ui, repo, other, *args, **opts)
def push(self, remote, force=False, revs=None, newbranch=None): if isinstance(remote, gitrepo): git = GitHandler(self, self.ui) git.push(remote.path, revs, force) else: #pragma: no cover # newbranch was added in 1.6 if newbranch is None: return super(hgrepo, self).push(remote, force, revs) else: return super(hgrepo, self).push(remote, force, revs, newbranch)
def push(self, remote, force=False, revs=None, newbranch=None): if isinstance(remote, gitrepo): git = GitHandler(self, self.ui) # This is needed for bookmark deletion to work. remote.git_handler = git return git.push(remote.path, revs, force) else: #pragma: no cover # newbranch was added in 1.6 if newbranch is None: return super(hgrepo, self).push(remote, force, revs) else: return super(hgrepo, self).push(remote, force, revs, newbranch)
def revset_gitnode(repo, subset, x): '''``gitnode(hash)`` Select changesets that originate in the given Git revision. ''' args = revset.getargs(x, 1, 1, "gitnode takes one argument") rev = revset.getstring(args[0], "the argument to gitnode() must be a hash") git = GitHandler(repo, repo.ui) def matches(r): gitnode = git.map_git_get(repo[r].hex()) if gitnode is None: return False return rev in [gitnode, gitnode[:12]] return [r for r in subset if matches(r)]
def findoutgoing(orig, local, remote, *args, **kwargs): kw = {} kw.update(kwargs) for val, k in zip(args, ('base', kwname, 'force')): kw[k] = val if isinstance(remote, gitrepo.gitrepo): # clean up this cruft when we're 1.7-only, remoteheads and # the return value change happened between 1.6 and 1.7. git = GitHandler(local, local.ui) base, heads = git.get_refs(remote.path) newkw = {'base': base, kwname: heads} newkw.update(kw) kw = newkw if kwname == 'heads': r = orig(local, remote, **kw) return [x[0] for x in r] return orig(local, remote, **kw)
def findcommonoutgoing(orig, repo, other, *args, **kwargs): if isinstance(other, gitrepo.gitrepo): git = GitHandler(repo, repo.ui) heads = git.get_refs(other.path)[0] kw = {} kw.update(kwargs) for val, k in zip(args, ('onlyheads', 'force', 'commoninc', 'portable')): kw[k] = val force = kw.get('force', False) commoninc = kw.get('commoninc', None) if commoninc is None: commoninc = discovery.findcommonincoming(repo, other, heads=heads, force=force) kw['commoninc'] = commoninc return orig(repo, other, **kw) return orig(repo, other, *args, **kwargs)
def tags(self): if not hasattr(self, 'tagscache'): # mercurial 1.4 tmp = super(hgrepo, self).tags() tmp.update(self.gitrefs()) return tmp if self.tagscache: return self.tagscache git = GitHandler(self, self.ui) tagscache = super(hgrepo, self).tags() for tag, rev in git.tags.iteritems(): if tag in tagscache: continue tagscache[tag] = bin(rev) self._tagstypecache[tag] = 'git' return tagscache
def tags(self): if hasattr(self, 'tagscache') and self.tagscache: # Mercurial 1.4 and earlier. return self.tagscache elif hasattr(self, '_tags') and self._tags: # Mercurial 1.5 and later. return self._tags git = GitHandler(self, self.ui) tagscache = super(hgrepo, self).tags() tagscache.update(self.gitrefs()) for tag, rev in git.tags.iteritems(): if tag in tagscache: continue tagscache[tag] = bin(rev) if hasattr(self, '_tagstypecache'): # Only present in Mercurial 1.3 and earlier. self._tagstypecache[tag] = 'git' return tagscache
def findoutgoing(orig, local, remote, *args, **kwargs): if isinstance(remote, gitrepo.gitrepo): hgver = hg.util.version() if hgver >= '1.8.9' or (hgver > '1.8' and '+' in hgver): raise hgutil.Abort( 'hg-git outgoing support is broken on hg 1.9.x') # clean up this cruft when we're 1.7-only, remoteheads and # the return value change happened between 1.6 and 1.7. kw = {} kw.update(kwargs) for val, k in zip(args, ('base', kwname, 'force')): kw[k] = val git = GitHandler(local, local.ui) base, heads = git.get_refs(remote.path) newkw = {'base': base, kwname: heads} newkw.update(kw) kw = newkw if kwname == 'heads': r = orig(local, remote, **kw) return [x[0] for x in r] if kwname == 'onlyheads': del kw['base'] return orig(local, remote, **kw) return orig(local, remote, *args, **kwargs)
def githandler(self): '''get the GitHandler for an hg repo This only makes sense if the repo talks to at least one git remote. ''' return GitHandler(self, self.ui)
def get_git_handler(): git_handler = GitHandler(os.path.dirname(os.path.abspath(__file__))) return git_handler
def _initializehandler(self): if self.handler is None and self.localrepo is not None: self.handler = GitHandler(self.localrepo, self.localrepo.ui) return self.handler
def gsummary(ui, repo): ctx = repo[None] parents = ctx.parents() git = GitHandler(repo, ui) for p in parents: repo.ui.status(_('git-rev: %s\n') % git.map_git_get(p.hex()))
def gclear(ui, repo): repo.ui.status(_("clearing out the git cache data\n")) git = GitHandler(repo, ui) git.clear()
def gexport(ui, repo): git = GitHandler(repo, ui) git.export_commits()
def gimport(ui, repo, remote_name=None): git = GitHandler(repo, ui) git.import_commits(remote_name)
def pull(self, remote, heads=None, force=False): if isinstance(remote, gitrepo): git = GitHandler(self, self.ui) return git.fetch(remote.path, heads) else: #pragma: no cover return super(hgrepo, self).pull(remote, heads, force)