Patchwork [1,of,3] gpg: extend repo with signs property

login
register
mail settings
Submitter elson.wei@gmail.com
Date Aug. 8, 2013, 1:41 a.m.
Message ID <a835e923601daaa2106c.1375926081@ElsonWei-NB.PrimeVOLT>
Download mbox | patch
Permalink /patch/2089/
State Changes Requested
Headers show

Comments

elson.wei@gmail.com - Aug. 8, 2013, 1:41 a.m.
# HG changeset patch
# User Wei, Elson <elson.wei@gmail.com>
# Date 1375841212 -28800
#      Wed Aug 07 10:06:52 2013 +0800
# Node ID a835e923601daaa2106c28f81c8cbe8618965128
# Parent  7a67f75deafc8880b539d3da42a719dab00d7cd6
gpg: extend repo with signs property

repo.signs[n] will return the (data, context) list for node n.
Matt Mackall - Aug. 14, 2013, 6:29 p.m.
On Thu, 2013-08-08 at 09:41 +0800, elson.wei@gmail.com wrote:
> # HG changeset patch
> # User Wei, Elson <elson.wei@gmail.com>
> # Date 1375841212 -28800
> #      Wed Aug 07 10:06:52 2013 +0800
> # Node ID a835e923601daaa2106c28f81c8cbe8618965128
> # Parent  7a67f75deafc8880b539d3da42a719dab00d7cd6
> gpg: extend repo with signs property

This goes against our current trend of taking things out of localrepo.

(The proper name here would also probably be 'signatures'.)

Patch

diff --git a/hgext/gpg.py b/hgext/gpg.py
--- a/hgext/gpg.py
+++ b/hgext/gpg.py
@@ -6,7 +6,7 @@ 
 '''commands to sign and verify changesets'''
 
 import os, tempfile, binascii
-from mercurial import util, commands, match, cmdutil
+from mercurial import util, commands, match, cmdutil, localrepo
 from mercurial import node as hgnode
 from mercurial.i18n import _
 
@@ -293,3 +293,23 @@ 
         return "%s\n" % hgnode.hex(node)
     else:
         raise util.Abort(_("unknown signature version"))
+
+def reposetup(ui, repo):
+    class gpgrepo(repo.__class__):
+        @localrepo.unfilteredpropertycache
+        def signs(self):
+            sigs = {}
+            for data, context in sigwalk(repo):
+                node, version, sig = data
+                fn, ln = context
+                try:
+                    n = repo.lookup(node)
+                except KeyError:
+                    ui.warn(_("%s:%d node does not exist\n") % (fn, ln))
+                    continue
+                sigs.setdefault(n, [])
+                sigs[n].extend([(data, context)])
+            return sigs
+
+    if repo.local():
+        repo.__class__ = gpgrepo