[Svnmerge] Patch for log message indentation

Giovanni Bajo rasky at develer.com
Tue Feb 28 02:46:14 PST 2006


Alan Barrett <apb at cequrux.com> wrote:

>>> Personally, I also find the indented style much easier to read and
>>> would like to see his patch committed. If there is some opposition
>>> to this, then we can always add a --logindent=n option, where n
>>> defaults to 0.
>>
>> Fine by me. I don't think it's worth an additional command line
>> option.
>
> My patch has the unwanted effect of appending an extra blank line to
> each log message.  Please don't commit it as-is.
>
>>>> +#LOG_LINE_PREFIX = ''
>>>> +LOG_LINE_PREFIX = 2 * ' '
>>
>> Don't keep a commented line around.
>
> It's intended as a hint to people who want to switch between the
> indenting or non-indenting behaviours by editing the script.
>
>>>> +def prefix_lines(prefix, lines):
>>>> + """Given a string representing lines of text,
>>>> + insert the specified prefix at the begining of each line,
>>>> + and return the result."""
>>>> + result = ""
>>>> + for line in lines.split("\n"):
>>>> + result = result + prefix + line + "\n"
>>>> + return result
>>
>> The referenced patch concatenates strings in quadratic time using
>> repeated "operator +". A faster version would be:
>>
>> return "\n".join([prefix + L for L in lines])
>
> Thank you.  I assume you meant
>
> return "\n".join([prefix + L for L in lines.split("\n")])

Right.

> Do you also have an efficient way of removing the last element of
> lines.split("\n") if and only if it is empty?

I'd do it the other way. Before splitting, do:

lines = rstrip(lines, "\n")

Notice that the actual Python syntax is lines.rstrip("\n"), but "rstrip" was
added in a later Python version than 2.0, so I added a global rstrip() function
at the top of svnmerge.py for usage in the module.

Giovanni Bajo




More information about the Svnmerge mailing list