[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mercurial
Subject:    Re: Mercurial hook to set policy on tag names.
From:       Idan Kamara <idankk86 () gmail ! com>
Date:       2011-07-20 12:23:47
Message-ID: CAMz0A7=DDqL3hPcofk=f67O29bWDd9QHabPiBTAnF0s57Qu3pA () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


On Tue, Jul 19, 2011 at 4:01 PM, Oleksandr Gavenko <gavenkoa@gmail.com>
wrote:
>
> I write (in-process) hook to prevent add BAD tag name locally (which
> successfully work):
>
> .hg/hgrc:
>
> pretag.badtagname = python:.hg/hgcheck.py:localbadtag
>
> .hg/hgcheck.py:
>
> goodtag_re = r'(ver-\d+\.\d+\.\d+|tip)$'
> def localbadtag(ui, repo, hooktype, node, **kwargs):
>    assert(hooktype == 'pretag')
>    re_ = re.compile(goodtag_re)
>    if not re_.match(tag):
>        ui.warn('Invalid tag name "%s".\n' % tag)
>        ui.warn('Use one of tip, ver-xx.xx.xx\n')
>        return True
>    return False
>
> How make this check for pretxnchangegroup hook (so prevent to adding
> bad named tags with push command on server side)?
>
> I try write this code:
>
> def pushbadtag(ui, repo, hooktype, node, **kwargs):
>    assert(hooktype == 'pretxnchangegroup')
>    re_ = re.compile(goodtag_re)
>    for rev in xrange(repo[node].rev(), len(repo)):
>        ui.warn('rev: %d\n' % rev)
>        for tag in repo[rev].tags():
>            ui.warn('tag: ' + tag + '\n')
>            if not re_.match(tag):
>                ui.warn('Invalid tag name "%s" for rev: "%s".\n' % (tag,
rev))
>                ui.warn('Use one of tip, ver-xx.xx.xx\n')
>                return True
>    return False
>
> but when I push to repo with upper pretxnchangegroup hook enabled:
>
>  $ hg tag gg
>  $ hg push -f -r tip
> pushing to /cygdrive/d/home/tmp/hg/good
> searching for changes
> adding changesets
> adding manifests
> adding file changes
> added 1 changesets with 1 changes to 1 files (+1 heads)
> rev: 35
> tag: tip
>
> you can see that rev.tags() do not return gg tag! So it can not filter

The problem is the actual tag is (probably) not in the pushed csets.

If your server contains rev 0, and rev 1 is the result of `hg tag foo` and
is local,
that is rev 1 is tagging rev 0, then pushing rev 1 won't show 'foo' on any
of the incoming csets, because it already has the tagged cset, 0.

I'm not sure there's anything that can be done here on the server side,
short of inspecting the incoming csets, looking for .hgtags.

And this can get tricky, because if you have some rev is adding a bad tag,
then another
one is removing it, you wouldn't want to reject that.

Perhaps a saner approach would be to look at the incoming csets
that are also heads, and do the parsing of .hgtags on those.

[Attachment #5 (text/html)]

<div dir="ltr">On Tue, Jul 19, 2011 at 4:01 PM, Oleksandr Gavenko &lt;<a \
href="mailto:gavenkoa@gmail.com">gavenkoa@gmail.com</a>&gt; wrote:<br>&gt;<br>&gt; I \
write (in-process) hook to prevent add BAD tag name locally (which<br> &gt; \
successfully work):<br>&gt;<br>&gt; .hg/hgrc:<br>&gt;<br>&gt; pretag.badtagname = \
python:.hg/hgcheck.py:localbadtag<br>&gt;<br>&gt; .hg/hgcheck.py:<br>&gt;<br>&gt; \
goodtag_re = r&#39;(ver-\d+\.\d+\.\d+|tip)$&#39;<br> &gt; def localbadtag(ui, repo, \
hooktype, node, **kwargs):<br>&gt;    assert(hooktype == &#39;pretag&#39;)<br>&gt;    \
re_ = re.compile(goodtag_re)<br>&gt;    if not re_.match(tag):<br>&gt;        \
ui.warn(&#39;Invalid tag name &quot;%s&quot;.\n&#39; % tag)<br> &gt;        \
ui.warn(&#39;Use one of tip, ver-xx.xx.xx\n&#39;)<br>&gt;        return True<br>&gt;  \
return False<br>&gt;<br>&gt; How make this check for pretxnchangegroup hook (so \
prevent to adding<br>&gt; bad named tags with push command on server side)?<br> \
&gt;<br>&gt; I try write this code:<br>&gt;<br>&gt; def pushbadtag(ui, repo, \
hooktype, node, **kwargs):<br>&gt;    assert(hooktype == \
&#39;pretxnchangegroup&#39;)<br>&gt;    re_ = re.compile(goodtag_re)<br>&gt;    for \
rev in xrange(repo[node].rev(), len(repo)):<br> &gt;        ui.warn(&#39;rev: \
%d\n&#39; % rev)<br>&gt;        for tag in repo[rev].tags():<br>&gt;            \
ui.warn(&#39;tag: &#39; + tag + &#39;\n&#39;)<br>&gt;            if not \
re_.match(tag):<br>&gt;                ui.warn(&#39;Invalid tag name &quot;%s&quot; \
for rev: &quot;%s&quot;.\n&#39; % (tag, rev))<br> &gt;                \
ui.warn(&#39;Use one of tip, ver-xx.xx.xx\n&#39;)<br>&gt;                return \
True<br>&gt;    return False<br>&gt;<br>&gt; but when I push to repo with upper \
pretxnchangegroup hook enabled:<br>&gt;<br> &gt;  $ hg tag gg<br>&gt;  $ hg push -f \
-r tip<br>&gt; pushing to /cygdrive/d/home/tmp/hg/good<br>&gt; searching for \
changes<br>&gt; adding changesets<br>&gt; adding manifests<br>&gt; adding file \
changes<br>&gt; added 1 changesets with 1 changes to 1 files (+1 heads)<br> &gt; rev: \
35<br>&gt; tag: tip<br>&gt;<br>&gt; you can see that rev.tags() do not return gg tag! \
So it can not filter<br><div><br></div><div>The problem is the actual tag is \
(probably) not in the pushed csets.</div><div><br> </div><div>If your server contains \
rev 0, and rev 1 is the result of `hg tag foo` and is local,</div><div>that is rev 1 \
is tagging rev 0, then pushing rev 1 won&#39;t show &#39;foo&#39; on any</div><div>of \
the incoming csets, because it already has the tagged cset, 0.</div> \
<div><br></div><div>I&#39;m not sure there&#39;s anything that can be done here on \
the server side,</div><div>short of inspecting the incoming csets, looking for \
.hgtags.</div><div><br></div><div>And this can get tricky, because if you have some \
rev is adding a bad tag, then another</div> <div>one is removing it, you wouldn&#39;t \
want to reject that. </div><div><br></div><div>Perhaps a saner approach would be to \
look at the incoming csets</div><div>that are also heads, and do the parsing of \
.hgtags on those.</div> </div>



_______________________________________________
Mercurial mailing list
Mercurial@selenic.com
http://selenic.com/mailman/listinfo/mercurial


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic