# [PATCH] hg-to-git: fix parent analysis

2 messages from 2008-02-15 to 2008-02-19. Participants: Stelian Pop, Karl Hasselström.
Thread: https://gitlist.dev/t/12119

## Stelian Pop, 2008-02-15 21:20

Subject: [PATCH] hg-to-git: fix parent analysis
Message-ID: <1203110444.5579.23.camel@galileo>
URL: https://gitlist.dev/e/1203110444.5579.23.camel%40galileo

```
Fix a bug in the hg-to-git convertor introduced by commit
1bc7c13af9f936aa80893100120b542338a10bf4: when searching the changeset
parents, 'hg log' returns an extra space at the end of the line, which
confuses the .split(' ') based tokenizer:

    Traceback (most recent call last):
      File "hg-to-git.py", line 123, in <module>
          hgchildren[mparent] += ( str(cset), )
      KeyError: ''

Signed-off-by: Stelian Pop <stelian@popies.net>

---

diff --git a/contrib/hg-to-git/hg-to-git.py b/contrib/hg-to-git/hg-to-git.py
index c35b158..d72ffbb 100755
--- a/contrib/hg-to-git/hg-to-git.py
+++ b/contrib/hg-to-git/hg-to-git.py
@@ -111,7 +111,7 @@ hgparents["0"] = (None, None)
 hgbranch["0"] = "master"
 for cset in range(1, int(tip) + 1):
     hgchildren[str(cset)] = ()
-    prnts = os.popen('hg log -r %d --template "{parents}"' % cset).read().split(' ')
+    prnts = os.popen('hg log -r %d --template "{parents}"' % cset).read().strip().split(' ')
     prnts = map(lambda x: x[:x.find(':')], prnts)
     if prnts[0] != '':
         parent = prnts[0].strip()

-- 
Stelian Pop <stelian@popies.net>

```

## Karl Hasselström, 2008-02-19 10:12

Subject: Re: [PATCH] hg-to-git: fix parent analysis
Message-ID: <20080219101244.GA3825@diana.vm.bytemark.co.uk>
URL: https://gitlist.dev/e/20080219101244.GA3825%40diana.vm.bytemark.co.uk
In-Reply-To: <1203110444.5579.23.camel@galileo>

```
On 2008-02-15 22:20:44 +0100, Stelian Pop wrote:

> -    prnts = os.popen('hg log -r %d --template "{parents}"' % cset).read().split(' ')
> +    prnts = os.popen('hg log -r %d --template "{parents}"' % cset).read().strip().split(' ')

If it's not already too late, you could wrap this line when you're
changing it anyway. Something like this maybe:

    prnts = os.popen('hg log -r %d --template "{parents}"' % cset
                     ).read().strip().split(' ')

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle

```
