Patchwork [2,of,2,PoC] hgweb: link to successors of obsoleted changesets (PoC)

login
register
mail settings
Submitter Anton Shestakov
Date Dec. 15, 2017, 2:41 p.m.
Message ID <4273260ac0d6e9bcb293.1513348908@neuro>
Download mbox | patch
Permalink /patch/26310/
State Superseded
Headers show

Comments

Anton Shestakov - Dec. 15, 2017, 2:41 p.m.
# HG changeset patch
# User Anton Shestakov <av6@dwimlabs.net>
# Date 1513346027 -28800
#      Fri Dec 15 21:53:47 2017 +0800
# Node ID 4273260ac0d6e9bcb293607c7bdc16d0d246e6e9
# Parent  3764b68ff62bb5144f814f17ffe6465bd915e51b
# EXP-Topic hgweb-more-info
hgweb: link to successors of obsoleted changesets (PoC)

This sort of works, but I have doubts about that "node" attribute that is
added. Something tells me that there may be a better way to do this, that's why
this is a proof of concept for now.

I'm not sure if there's a way to somehow access node and other changeset
attributes without actually adding them to this lambda function. But other
functions in templatekw module, like showparents, also use _hybrid() with a
similar makemap argument (a lambda that returns a dict with only ctx and
revcache), and if I do, for example

    hg log -T '{parents%"{node|short} {author} {date|isodate}"}'

it will show node, but also author and date, even though these attributes
aren't explicitly provided by anything in showparents().

But in hgweb, this is not enough, and there needs to be "node" in that dict,
otherwise the links wouldn't work. Any suggestions?
Yuya Nishihara - Dec. 20, 2017, 1:01 p.m.
On Fri, 15 Dec 2017 22:41:48 +0800, Anton Shestakov wrote:
> # HG changeset patch
> # User Anton Shestakov <av6@dwimlabs.net>
> # Date 1513346027 -28800
> #      Fri Dec 15 21:53:47 2017 +0800
> # Node ID 4273260ac0d6e9bcb293607c7bdc16d0d246e6e9
> # Parent  3764b68ff62bb5144f814f17ffe6465bd915e51b
> # EXP-Topic hgweb-more-info
> hgweb: link to successors of obsoleted changesets (PoC)
> 
> This sort of works, but I have doubts about that "node" attribute that is
> added. Something tells me that there may be a better way to do this, that's why
> this is a proof of concept for now.
> 
> I'm not sure if there's a way to somehow access node and other changeset
> attributes without actually adding them to this lambda function. But other
> functions in templatekw module, like showparents, also use _hybrid() with a
> similar makemap argument (a lambda that returns a dict with only ctx and
> revcache), and if I do, for example
> 
>     hg log -T '{parents%"{node|short} {author} {date|isodate}"}'
> 
> it will show node, but also author and date, even though these attributes
> aren't explicitly provided by anything in showparents().
> 
> But in hgweb, this is not enough, and there needs to be "node" in that dict,
> otherwise the links wouldn't work. Any suggestions?

One way is to put repo and node to the commonentry.

  'ctx': ctx,
  'repo': repo,
  'node': templatekw.shownode,  # need to drop 'tmpl' from arguments
  'succsandmarkers': templatekw.showsuccsandmarkers,

However, the story gets worse because hgweb overloads the keyword 'repo'
for a repository name. This seems not easily fixable, so we'll have to bind
a repo argument locally.

  'node': lambda ctx, **x: templatekw.shownode(repo, ctx),
  ...

Ugly, but works.
Anton Shestakov - Dec. 22, 2017, 2:53 p.m.
On Wed, 20 Dec 2017 22:01:49 +0900
Yuya Nishihara <yuya@tcha.org> wrote:

> On Fri, 15 Dec 2017 22:41:48 +0800, Anton Shestakov wrote:
> > # HG changeset patch
> > # User Anton Shestakov <av6@dwimlabs.net>
> > # Date 1513346027 -28800
> > #      Fri Dec 15 21:53:47 2017 +0800
> > # Node ID 4273260ac0d6e9bcb293607c7bdc16d0d246e6e9
> > # Parent  3764b68ff62bb5144f814f17ffe6465bd915e51b
> > # EXP-Topic hgweb-more-info
> > hgweb: link to successors of obsoleted changesets (PoC)
> > 
> > This sort of works, but I have doubts about that "node" attribute that is
> > added. Something tells me that there may be a better way to do this, that's why
> > this is a proof of concept for now.
> > 
> > I'm not sure if there's a way to somehow access node and other changeset
> > attributes without actually adding them to this lambda function. But other
> > functions in templatekw module, like showparents, also use _hybrid() with a
> > similar makemap argument (a lambda that returns a dict with only ctx and
> > revcache), and if I do, for example
> > 
> >     hg log -T '{parents%"{node|short} {author} {date|isodate}"}'
> > 
> > it will show node, but also author and date, even though these attributes
> > aren't explicitly provided by anything in showparents().
> > 
> > But in hgweb, this is not enough, and there needs to be "node" in that dict,
> > otherwise the links wouldn't work. Any suggestions?
> 
> One way is to put repo and node to the commonentry.
> 
>   'ctx': ctx,
>   'repo': repo,
>   'node': templatekw.shownode,  # need to drop 'tmpl' from arguments
>   'succsandmarkers': templatekw.showsuccsandmarkers,
> 
> However, the story gets worse because hgweb overloads the keyword 'repo'
> for a repository name. This seems not easily fixable, so we'll have to bind
> a repo argument locally.
> 
>   'node': lambda ctx, **x: templatekw.shownode(repo, ctx),
>   ...
> 
> Ugly, but works.

Agreed, and for now I decided to try and do something that wouldn't
start bringing all regular template functions to hgweb (which, I feel,
would open a can of worms that this feature might not be worth).
There's a V2 of this series on the list.

I just saw your PoC patch that exports regular template functions to
hgweb after I sent my series, but I didn't look at it in detail yet. If
you think that's the way to go, then feel free to drop the second patch
from my V2. I guess the first patch can still be queued independently.

Patch

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -772,7 +772,7 @@  def showsuccsandmarkers(repo, ctx, **arg
 
         successors = [hex(n) for n in successors]
         successors = _hybrid(None, successors,
-                             lambda x: {'ctx': repo[x], 'revcache': {}},
+                             lambda x: {'ctx': repo[x], 'node': x, 'revcache': {}},
                              lambda x: scmutil.formatchangeid(repo[x]))
 
         # Format markers
diff --git a/mercurial/templates/gitweb/map b/mercurial/templates/gitweb/map
--- a/mercurial/templates/gitweb/map
+++ b/mercurial/templates/gitweb/map
@@ -271,7 +271,8 @@  branchtag = '<span class="branchtag" tit
 inbranchtag = '<span class="inbranchtag" title="{name|escape}">{name|escape}</span> '
 bookmarktag = '<span class="bookmarktag" title="{name|escape}">{name|escape}</span> '
 alltags = '<span class="logtags">{phasetag}{obsoletetag}{instabilities%instabilitytag}{inbranch%inbranchtag}{branches%branchtag}{tags%tagtag}{bookmarks%bookmarktag}</span>'
-obsfatesuccessors = '{if(successors, ' as ')}{join(successors, ', ')}'
+successorlink = '<a class="list" href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">{node|short}</a> '
+obsfatesuccessors = '{if(successors, ' as ')}{successors%successorlink}'
 obsfateverb = '{obsfateverb(successors, markers)}'
 obsfateoperations = '{if(obsfateoperations(markers), ' using {join(obsfateoperations(markers), ', ')}')}'
 obsfateentry = '{obsfateverb}{obsfateoperations}{obsfatesuccessors}'
diff --git a/mercurial/templates/monoblue/map b/mercurial/templates/monoblue/map
--- a/mercurial/templates/monoblue/map
+++ b/mercurial/templates/monoblue/map
@@ -229,7 +229,8 @@  branchtag = '<span class="branchtag" tit
 inbranchtag = '<span class="inbranchtag" title="{name|escape}">{name|escape}</span> '
 bookmarktag = '<span class="bookmarktag" title="{name|escape}">{name|escape}</span> '
 alltags = '<span class="logtags">{phasetag}{obsoletetag}{instabilities%instabilitytag}{inbranch%inbranchtag}{branches%branchtag}{tags%tagtag}{bookmarks%bookmarktag}</span>'
-obsfatesuccessors = '{if(successors, ' as ')}{join(successors, ', ')}'
+successorlink = '<a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">{node|short}</a> '
+obsfatesuccessors = '{if(successors, ' as ')}{successors%successorlink}'
 obsfateverb = '{obsfateverb(successors, markers)}'
 obsfateoperations = '{if(obsfateoperations(markers), ' using {join(obsfateoperations(markers), ', ')}')}'
 obsfateentry = '{obsfateverb}{obsfateoperations}{obsfatesuccessors}'
diff --git a/mercurial/templates/paper/map b/mercurial/templates/paper/map
--- a/mercurial/templates/paper/map
+++ b/mercurial/templates/paper/map
@@ -209,7 +209,8 @@  changelogbranchhead = '<span class="bran
 changelogbranchname = '<span class="branchname">{name|escape}</span> '
 alltags = '{phasetag}{obsoletetag}{instabilities%instabilitytag}{inbranch%changelogbranchname}{branches%changelogbranchhead}{tags%changelogtag}{bookmarks%changelogtag}'
 
-obsfatesuccessors = '{if(successors, ' as ')}{join(successors, ', ')}'
+successorlink = '<a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">{node|short}</a> '
+obsfatesuccessors = '{if(successors, ' as ')}{successors%successorlink}'
 obsfateverb = '{obsfateverb(successors, markers)}'
 obsfateoperations = '{if(obsfateoperations(markers), ' using {join(obsfateoperations(markers), ', ')}')}'
 obsfateentry = '{obsfateverb}{obsfateoperations}{obsfatesuccessors}'
diff --git a/mercurial/templates/spartan/map b/mercurial/templates/spartan/map
--- a/mercurial/templates/spartan/map
+++ b/mercurial/templates/spartan/map
@@ -166,7 +166,8 @@  branchentry = '
 diffblock = '<pre class="parity{parity}">{lines}</pre>'
 changelogtag = '<tr><th class="tag">tag:</th><td class="tag">{tag|escape}</td></tr>'
 changesettag = '<tr><th class="tag">tag:</th><td class="tag">{tag|escape}</td></tr>'
-obsfatesuccessors = '{if(successors, ' as ')}{join(successors, ', ')}'
+successorlink = '<a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">{node|short}</a> '
+obsfatesuccessors = '{if(successors, ' as ')}{successors%successorlink}'
 obsfateverb = '{obsfateverb(successors, markers)}'
 obsfateoperations = '{if(obsfateoperations(markers), ' using {join(obsfateoperations(markers), ', ')}')}'
 obsfateentry = '{obsfateverb}{obsfateoperations}{obsfatesuccessors}'
diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
--- a/tests/test-obsolete.t
+++ b/tests/test-obsolete.t
@@ -1036,15 +1036,15 @@  check obsolete changeset
 
 check an obsolete changeset that has been rewritten
   $ get-with-headers.py localhost:$HGPORT 'rev/cda648ca50f5?style=paper' | grep rewritten
-   <td>rewritten as 6:3de5eca88c00</td>
+   <td>rewritten as <a href="/rev/3de5eca88c00?style=paper">3de5eca88c00</a> </td>
   $ get-with-headers.py localhost:$HGPORT 'rev/cda648ca50f5?style=coal' | grep rewritten
-   <td>rewritten as 6:3de5eca88c00</td>
+   <td>rewritten as <a href="/rev/3de5eca88c00?style=coal">3de5eca88c00</a> </td>
   $ get-with-headers.py localhost:$HGPORT 'rev/cda648ca50f5?style=gitweb' | grep rewritten
-  <tr><td>obsolete</td><td>rewritten as 6:3de5eca88c00</td></tr>
+  <tr><td>obsolete</td><td>rewritten as <a class="list" href="/rev/3de5eca88c00?style=gitweb">3de5eca88c00</a> </td></tr>
   $ get-with-headers.py localhost:$HGPORT 'rev/cda648ca50f5?style=monoblue' | grep rewritten
-          <dt>obsolete</dt><dd>rewritten as 6:3de5eca88c00</dd>
+          <dt>obsolete</dt><dd>rewritten as <a href="/rev/3de5eca88c00?style=monoblue">3de5eca88c00</a> </dd>
   $ get-with-headers.py localhost:$HGPORT 'rev/cda648ca50f5?style=spartan' | grep rewritten
-   <td class="obsolete">rewritten as 6:3de5eca88c00</td>
+   <td class="obsolete">rewritten as <a href="/rev/3de5eca88c00?style=spartan">3de5eca88c00</a> </td>
 
 check changeset with instabilities