Patchwork [3,of,4] subrepo: add revdetails() method

login
register
mail settings
Submitter Angel Ezquerra
Date May 7, 2014, 10:54 p.m.
Message ID <874013facd42bd2a8bbd.1399503297@Angel-PC.localdomain>
Download mbox | patch
Permalink /patch/4658/
State Superseded
Headers show

Comments

Angel Ezquerra - May 7, 2014, 10:54 p.m.
# HG changeset patch
# User Angel Ezquerra <angel.ezquerra@gmail.com>
# Date 1399414642 -7200
#      Wed May 07 00:17:22 2014 +0200
# Node ID 874013facd42bd2a8bbd07634cad02448709c5ac
# Parent  c1035596456a23347b3cfb510bf7c62a68166b90
subrepo: add revdetails() method

This method is able to show the "revision details" for a given revision.
Currently for mercurial subrepos it returns a string which resembles a lot what
the default template writes to the console when doing hg log. For all other
types of subrepos we just return the revision id as a string.

We could not use the templater to get this info because the templater writes to
the console (i.e. it does not return a string that we can use).

This method will be used on the next revision.
Pierre-Yves David - May 7, 2014, 11:38 p.m.
On 05/07/2014 03:54 PM, Angel Ezquerra wrote:
> # HG changeset patch
> # User Angel Ezquerra <angel.ezquerra@gmail.com>
> # Date 1399414642 -7200
> #      Wed May 07 00:17:22 2014 +0200
> # Node ID 874013facd42bd2a8bbd07634cad02448709c5ac
> # Parent  c1035596456a23347b3cfb510bf7c62a68166b90
> subrepo: add revdetails() method
>
> This method is able to show the "revision details" for a given revision.
> Currently for mercurial subrepos it returns a string which resembles a lot what
> the default template writes to the console when doing hg log. For all other
> types of subrepos we just return the revision id as a string.
>
> We could not use the templater to get this info because the templater writes to
> the console (i.e. it does not return a string that we can use).

Could we not fix the templater instead?
Angel Ezquerra - May 10, 2014, 9:54 a.m.
On Thu, May 8, 2014 at 1:38 AM, Pierre-Yves David
<pierre-yves.david@ens-lyon.org> wrote:
>
>
> On 05/07/2014 03:54 PM, Angel Ezquerra wrote:
>>
>> # HG changeset patch
>> # User Angel Ezquerra <angel.ezquerra@gmail.com>
>> # Date 1399414642 -7200
>> #      Wed May 07 00:17:22 2014 +0200
>> # Node ID 874013facd42bd2a8bbd07634cad02448709c5ac
>> # Parent  c1035596456a23347b3cfb510bf7c62a68166b90
>> subrepo: add revdetails() method
>>
>> This method is able to show the "revision details" for a given revision.
>> Currently for mercurial subrepos it returns a string which resembles a lot
>> what
>> the default template writes to the console when doing hg log. For all
>> other
>> types of subrepos we just return the revision id as a string.
>>
>> We could not use the templater to get this info because the templater
>> writes to
>> the console (i.e. it does not return a string that we can use).
>
>
> Could we not fix the templater instead?

I'll look into that, thanks.

Angel
Angel Ezquerra - May 10, 2014, 11:36 p.m.
On Sat, May 10, 2014 at 11:54 AM, Angel Ezquerra
<angel.ezquerra@gmail.com> wrote:
> On Thu, May 8, 2014 at 1:38 AM, Pierre-Yves David
> <pierre-yves.david@ens-lyon.org> wrote:
>>
>>
>> On 05/07/2014 03:54 PM, Angel Ezquerra wrote:
>>>
>>> # HG changeset patch
>>> # User Angel Ezquerra <angel.ezquerra@gmail.com>
>>> # Date 1399414642 -7200
>>> #      Wed May 07 00:17:22 2014 +0200
>>> # Node ID 874013facd42bd2a8bbd07634cad02448709c5ac
>>> # Parent  c1035596456a23347b3cfb510bf7c62a68166b90
>>> subrepo: add revdetails() method
>>>
>>> This method is able to show the "revision details" for a given revision.
>>> Currently for mercurial subrepos it returns a string which resembles a lot
>>> what
>>> the default template writes to the console when doing hg log. For all
>>> other
>>> types of subrepos we just return the revision id as a string.
>>>
>>> We could not use the templater to get this info because the templater
>>> writes to
>>> the console (i.e. it does not return a string that we can use).
>>
>>
>> Could we not fix the templater instead?
>
> I'll look into that, thanks.
>
> Angel

It turns out it was really easy to do. The ui class has a pushbuffer
and a popbuffer methods which let you buffer what is written to them
and read it later.

I'll send V2 of this series in a minute.

Cheers,

Angel

Patch

diff -r c1035596456a -r 874013facd42 mercurial/subrepo.py
--- a/mercurial/subrepo.py	Wed May 07 00:13:22 2014 +0200
+++ b/mercurial/subrepo.py	Wed May 07 00:17:22 2014 +0200
@@ -505,6 +505,9 @@ 
     def shortid(self, revid):
         return revid
 
+    def revdetails(self, revid):
+        return 'changeset:   %s\n' % str(revid)
+
 class hgsubrepo(abstractsubrepo):
     def __init__(self, ctx, path, state):
         self._path = path
@@ -873,6 +876,29 @@ 
     def shortid(self, revid):
         return revid[:12]
 
+    @annotatesubrepoerror
+    def revdetails(self, revid):
+        ctx = self._repo[revid]
+        desctemplate = 'changeset:   %d:%s\n' \
+                       '%s' \
+                       '%s' \
+                       'user:        %s\n' \
+                       'date:        %s\n' \
+                       'summary:     %s\n'
+        branchinfo = ''
+        branch = ctx.branch()
+        if branch != 'default':
+            branchinfo = 'branch       %s\n' % branch
+        taginfo = ''
+        tags = ctx.tags()
+        if tags:
+            taginfo = 'tags:        %s\n' % ' '.join(tags)
+        date = util.datestr(ctx.date())
+        return desctemplate % \
+               (ctx.rev(), self.shortid(revid),
+                branchinfo, taginfo,
+                ctx.user(), date, ctx.description().splitlines()[0])
+
 class svnsubrepo(abstractsubrepo):
     def __init__(self, ctx, path, state):
         self._path = path