From: Eric S. Raymond Date: Tue, 2 Oct 2012 19:43:03 +0000 (-0400) Subject: This version of Mercurial support might actually work. X-Git-Tag: 1.5~22 X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=5a2ca3431f16ecd268c10b9ebae85241147bda82;p=irker.git This version of Mercurial support might actually work. --- diff --git a/Makefile b/Makefile index d6af763..6e2f779 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ uninstall: rm -f $(DESTDIR)/usr/share/man/man1/irkerhook.1 clean: - rm -f irkerd.8 irker-*.tar.gz *~ + rm -f irkerd.8 irkerhook.1 irker-*.tar.gz *~ rm -f SHIPPER.* *.html PYLINTOPTS = --rcfile=/dev/null --reports=n --include-ids=y --disable="C0103,C0111,C0301,R0201,R0902,R0903,R0912,E1101,W0201,W0621,W0702,F0401" diff --git a/NEWS b/NEWS index 675d909..ff46cd0 100644 --- a/NEWS +++ b/NEWS @@ -27,6 +27,10 @@ The color variable is no longer boolean; may be miRC or ANSI. The installation instructions for irkerhook.py have changed! +1.5 @ + Mercurial support. + + diff --git a/README b/README index f4d931c..5b33b3a 100644 --- a/README +++ b/README @@ -6,7 +6,7 @@ listening socket. It is meant to be used by hook scripts in version-control repositories, allowing them to send commit notifications to project -IRC channels. A hook script, irkerhook.py, supporting git and +IRC channels. A hook script, irkerhook.py, supporting git, hg, and Subversion is included in the distribution; see the install.txt file for installation instructions. diff --git a/control b/control index dd71f76..98b1725 100644 --- a/control +++ b/control @@ -7,7 +7,7 @@ Description: An IRC client that runs as a daemon accepting notification requests as JSON objects presented to a listening socket. It is meant to be used by hook scripts in version-control repositories, allowing them to send commit notifications to project IRC channels. A hook script - that works with git and svn is included in the distribution. + that works with git, hg, and svn is included in the distribution. XBS-Gitorious-URL: https://gitorious.org/irker diff --git a/install.txt b/install.txt index 4666a6b..0ed1d53 100644 --- a/install.txt +++ b/install.txt @@ -41,7 +41,8 @@ installed to launch irkerd as a boot-time service on that system. Under git, a call to irkerhook.py should be installed in the update hook script of your repo. Under Subversion, the call goes in your -repo's post-commit script. See the irkerhook manual page for details. +repo's post-commit script. Under Mercurial there are twi different +ways to install it. See the irkerhook manual page for details. == Testing == diff --git a/irkerhook.py b/irkerhook.py index d8b0719..983699b 100755 --- a/irkerhook.py +++ b/irkerhook.py @@ -269,25 +269,23 @@ class HgExtractor(GenericExtractor): # file is exercised). In the first case, we already get repository and # ui objects from Mercurial, in the second case, we have to create them # from the root path. + self.repository = None + self.node = None if arguments and type(arguments[0]) == type(()): # Called from hg_hook function - ui, repo, self.node = arguments[0] + ui, self.repository, self.node = arguments[0] arguments = [] # Should not be processed further by do_overrides else: # Called from command line: create repo/ui objects from mercurial import hg, ui as uimod repopath = '.' - commit = '-1' # i.e. tip for tok in arguments: if tok.startswith('--repository='): repopath = tok[13:] - elif tok.startswith('--commit='): - commit = tok[9:] ui = uimod.ui() ui.readconfig(os.path.join(repopath, '.hg', 'hgrc'), repopath) - repo = hg.repository(ui, repopath) - node = repo.lookup(commit) + self.repository = hg.repository(ui, repopath) GenericExtractor.__init__(self, arguments) @@ -297,7 +295,7 @@ class HgExtractor(GenericExtractor): if arguments and type(arguments[0]) == type(()): # Called from hg_hook function - ui, repo, node = arguments[0] + ui, self.repository, self.node = arguments[0] # Extract global values from the hg configuration file(s) self.project = ui.config('irker', 'project') @@ -313,20 +311,24 @@ class HgExtractor(GenericExtractor): self.urlprefix = self.urlprefix.rstrip('/') + '/rev' # self.commit is appended to this by do_overrides if not self.project: - self.project = os.path.basename(repo.root.rstrip('/')) - - # Extract commit-specific values from a "context" object - ctx = repo.changectx(node) - self.commit = short(node) - self.rev = '%d:%s' % (ctx.rev(), self.commit) - self.branch = ctx.branch() - self.author = person(ctx.user()) - self.logmsg = ctx.description() - - st = repo.status(ctx.p1().node(), ctx.node()) - self.files = ' '.join(st[0] + st[1] + st[2]) - + self.project = os.path.basename(self.repo.root.rstrip('/')) self.do_overrides() + def commit_factory(self, commit_id=None): + # Extract commit-specific values from a "context" object + if commit_id is None: + node = self.node + commit_id = short(self.node) + else: + node = self.repository.lookup(commit_id) + commit = Commit(self, commit_id) + ctx = self.repository.changectx(node) + commit.rev = '%d:%s' % (ctx.rev(), commit_id) + commit.branch = ctx.branch() + commit.author = person(ctx.user()) + commit.logmsg = ctx.description() + st = self.repository.status(ctx.p1().node(), ctx.node()) + commit.files = ' '.join(st[0] + st[1] + st[2]) + return commit def head(self): "Return a symbolic reference to the tip commit of the current branch." return "-1" @@ -337,9 +339,9 @@ def hg_hook(ui, repo, _hooktype, node=None, _url=None, **_kwds): # [hooks] # incoming.irker = python:/path/to/irkerhook.py:hg_hook extractor = HgExtractor([(ui, repo, node)]) - ship(extractor) + ship(extractor.commit_factory()) -def ship(commit, debug): +def ship(commit, debug=False): "Ship a notification for the sspecified commit." metadata = extractor.commit_factory(commit) # Message reduction. The assumption here is that IRC can't handle diff --git a/irkerhook.xml b/irkerhook.xml index 90a5f06..e10d5b8 100644 --- a/irkerhook.xml +++ b/irkerhook.xml @@ -220,7 +220,7 @@ may have the following values: accepts a --repository option with value (the absolute pathname of the Subversion repository) and a commit argument (the numeric revision level of the commit). The defaults are the current working directory and HEAD, -respectively. +respectively. Note, however, that you cannot default the repository argumment inside a Subversion post-commit hook. Instead, @@ -263,9 +263,6 @@ that would have unhappy results. Mercurial -NOTE: Mercurial support is currently broken. It is expected -this will be fixed in the next release. - Under Mercurial, irkerhook.py can be invoked in two ways: either as a Python hook (preferred) or as a script.