Re: [PATCH] hg-to-git: do not include the branch name as the first line of commit msg
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Dec 4, 2007, 01:20 UTC
- Message-ID
- <7vsl2jcl32.fsf@gitster.siamese.dyndns.org>
- In-Reply-To
- <4751A036.1080209@gmail.com>
Mark Drago <markdrago@gmail.com> writes:
Show 17 quoted lines
> Signed-off-by: Mark Drago <markdrago@gmail.com>
> ---
> contrib/hg-to-git/hg-to-git.py | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/contrib/hg-to-git/hg-to-git.py b/contrib/hg-to-git/hg-to-git.py
> index 7a1c3e4..6bff49b 100755
> --- a/contrib/hg-to-git/hg-to-git.py
> +++ b/contrib/hg-to-git/hg-to-git.py
> @@ -158,7 +158,7 @@ for cset in range(int(tip) + 1):
> mparent = None
>
> (fdcomment, filecomment) = tempfile.mkstemp()
> - csetcomment = os.popen('hg log -r %d -v | grep -v ^changeset: | grep -v ^parent: | grep -v ^user: | grep -v ^date | grep -v ^files: | grep -v ^description: | grep -v ^tag:' % cset).read().strip()
> + csetcomment = os.popen('hg log -r %d -v | grep -v ^changeset: | grep -v ^parent: | grep -v ^user: | grep -v ^date | grep -v ^files: | grep -v ^description: | grep -v ^tag: | grep -v ^branch:' % cset).read().strip()
> os.write(fdcomment, csetcomment)
> os.close(fdcomment)Isn't this one of the ugliest lines in the whole git.git project, I have to wonder?
I also wonder missing colon after "date" is a bug from the original version, and assuming that it is, how about doing something less error prone like this?
def included(line):
keywords = ('changeset', 'parent', 'user', 'date', 'files',
'description', 'tag', 'branch')
for kw in keywords:
if line.startswith(kw + ':'):
return 0
return 1 hglog = os.popen('hg log -r %d -v' % cset).read();
csetcomment = '\n'.join(filter(included, hglog.split('\n'))).strip()If you are excluding _all_ of the <word>: header lines, the "included" function may have to become cleverer but much simpler by doing something like:
import re
header_re = re.compile(r'^\w+:')
def included(line):
return not header_re.match(line)