git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] hg-to-git: do not include the branch name as the first line of commit msg

From
Stelian Pop <stelian@popies.net>
Date
Dec 6, 2007, 13:50 UTC
Message-ID
<1196949043.5388.18.camel@galileo>
In-Reply-To
<7vsl2jcl32.fsf@gitster.siamese.dyndns.org>
Le lundi 03 décembre 2007 à 17:20 -0800, Junio C Hamano a écrit :
Show 8 quoted lines
> >      (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?

It probably is, and I take full resposibility for the original version :). Incremental development woes.

> I also wonder missing colon after "date" is a bug from the original
> version, and assuming that it is, 
It is indeed a bug.
Show 13 quoted lines
> 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()
Seems great to me.
Show 8 quoted lines
> 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)

I'm afraid something like this will be much more prone to false positives.

Maybe an even better alternative, given the way mercurial outputs the changeset information, is to search for the '^description:' tag and take all the text that follows.

-- 
Stelian Pop <stelian@popies.net>
Previous: Junio C HamanoNext: Baz
Message 3 of 4 in “hg-to-git: do not include the branch name as the first line of commit msg”
  1. hg-to-git: do not include the branch name as the first line of commit msgMark Drago, Dec 1, 2007
  2. Junio C HamanoDec 4, 2007
  3. Stelian PopDec 6, 2007
  4. BazDec 6, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.