From: Eric S. Raymond Date: Tue, 2 Oct 2012 19:00:31 +0000 (-0400) Subject: Simplify and regularize irkerhook defaults. X-Git-Tag: 1.5~25 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7712c79c782cb07c46fa988bcde9fed81e10c0e6;p=irker.git Simplify and regularize irkerhook defaults. --- diff --git a/irkerhook.py b/irkerhook.py index 0ecef84..26855c4 100755 --- a/irkerhook.py +++ b/irkerhook.py @@ -99,6 +99,9 @@ class GenericExtractor: self.color = None self.bold = self.green = self.blue = "" self.yellow = self.brown = self.reset = "" + def head(self): + "Return a symbolic reference to the tip commit of the current branch." + return "HEAD" def activate_color(self, style): "IRC color codes." if style == 'mIRC': @@ -324,6 +327,9 @@ class HgExtractor(GenericExtractor): self.files = ' '.join(st[0] + st[1] + st[2]) self.do_overrides() + def head(self): + "Return a symbolic reference to the tip commit of the current branch." + return "1" def hg_hook(ui, repo, _hooktype, node=None, _url=None, **_kwds): # To be called from a Mercurial "commit" or "incoming" hook. Example @@ -335,7 +341,7 @@ def hg_hook(ui, repo, _hooktype, node=None, _url=None, **_kwds): if __name__ == "__main__": notify = True - repository = None + repository = "." refname = None commits = [] for arg in sys.argv[1:]: @@ -362,16 +368,12 @@ if __name__ == "__main__": # Someday we'll have extractors for several version-control systems if vcs == "svn": extractor = SvnExtractor(sys.argv[1:]) - if not commits: - commits = ['HEAD'] elif vcs == "hg": extractor = HgExtractor(sys.argv[1:]) - if not commits: - commits = ['-1'] else: extractor = GitExtractor(sys.argv[1:]) - if not commits: - commits = [do("git rev-parse HEAD")] + if not commits: + commits = [extractor.head()] for commit in commits: metadata = extractor.commit_factory(commit) diff --git a/irkerhook.xml b/irkerhook.xml index c6a4696..90a5f06 100644 --- a/irkerhook.xml +++ b/irkerhook.xml @@ -217,10 +217,15 @@ may have the following values: Subversion Under Subversion, irkerhook.py -requires a --repository option with value (the absolute pathname of the +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 values must be the two arguments that Subversion -gives its post-commit hook. Thus, a typical invocation in the post-commit +the commit). The defaults are the current working directory and HEAD, +respectively. + +Note, however, that you cannot default the +repository argumment inside a Subversion post-commit hook. Instead, +the values must be the two arguments that Subversion passes to that +hook as arguments. Thus, a typical invocation in the post-commit script will look like this: @@ -234,8 +239,8 @@ given on the command line, and will override any settings in an irker.conf file. The default for the project variable is the basename of the -(required) --repository argument.The default value of the "urlprefix" -variable is "viewcvs". +repository. The default value of the "urlprefix" variable is +"viewcvs". If an irker.conf file exists in the repository root directory (not the checkout directory but where internals such as the @@ -265,10 +270,21 @@ this will be fixed in the next release. invoked in two ways: either as a Python hook (preferred) or as a script. -When called as a script, the hook requires a --repository option -with value (the absolute pathname of the Subversion repository) and can take a -commit argument (the Mercurial hash ID of the commit or a reference to it). -The default commit argument is '-1', designating the current tip commit. +To call it as a Python hook, add the collowing to the +"commit" or "incoming" hook declaration in your Mercurial +repository: + + +[hooks] + incoming.irker = python:/path/to/irkerhook.py:hg_hook + + +When called as a script, the hook accepts a --repository option +with value (the absolute pathname of the Mercurial repository) and can +take a commit argument (the Mercurial hash ID of the commit or a +reference to it). The default for the repository argument is the +current directory. The default commit argument is '-1', designating +the current tip commit. As for git, in both cases all variables may be set in the repo hgrc file in an [irker] section. Command-line