[PATCH] qfold: suppress "* * *" if the current message is empty

timeless timeless at gmail.com
Wed Mar 16 21:42:27 CDT 2011


On Thu, Mar 17, 2011 at 2:30 AM, Steve Borho <steve at borho.org> wrote:
>> @@ -2242,7 +2243,8 @@ def fold(ui, repo, *files, **opts):
>>         ph = patchheader(q.join(parent), q.plainmode)
>>         message, user = ph.message, ph.user
>>         for msg in messages:
>> -            message.append('* * *')
>> +            if message:
>> +                message.append('* * *')
>>             message.extend(msg)
>>         message = '\n'.join(message)
>
> This looks like it wants to be a "* * *\n".join([msg for msg in
> messages if msg])

it might look that way, but it turns out that what we have are lists
(of lines without newline characters), not strings.

this is what i tried:
----
a=['hello']
b=['new','world']
c=['old','soup']
d=[]
try:
 "* * *\n".join(z for z in [b,c,d] if z)
except:
 print "oops"

for z in [b,c,d]:
 if (a):
  a.append("* * *")
 a.extend(z)

a
----
It's indeed quite magical, but actually it also explains why we don't
need to worry about certain things, and i kinda like it. -- although
it meant i had to learn (now) about <list.extend>. I'm not a python
expert, in fact i won't claim to speak python, so if there's a better
way to do this, i'm open to it.

Note that the '* * *' should only be added between newly folded non
empty patch message blobs, not between individual lines of any of the
messages.

Oh, and if someone else wants to add more tests for this behavior,
it's probably a good idea, i think the coverage of this area is sparse
at best. Personally, I'd rather not rewrite this module or be asked to
do too much, i'm really trying to do something else and only
tangentially fix a couple of things in Hg as I go.

If I was in a different position and could make a commitment to the
1.9 sprint, i'd actually plan to volunteer to go to the sprint and
work on things like this, but i can't -- sorry, i really wish i could.


More information about the Mercurial-devel mailing list