Patchwork [2,of,2] convert: support multiple specifed revs in git source

login
register
mail settings
Submitter Durham Goode
Date July 8, 2015, 7:26 p.m.
Message ID <9364d0d278b0c616a2ed.1436383577@dev2000.prn2.facebook.com>
Download mbox | patch
Permalink /patch/9928/
State Accepted
Commit f2748cc43b2a774ea6f7ae9ee38298a7d9ebd47d
Headers show

Comments

Durham Goode - July 8, 2015, 7:26 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1436376551 25200
#      Wed Jul 08 10:29:11 2015 -0700
# Node ID 9364d0d278b0c616a2edf4f412c1467297dbfc39
# Parent  3bca115973ad5f471e1ca4aa4252ad6e151ff1c8
convert: support multiple specifed revs in git source

This allows specifying multiple revs/branches to convert from a git repo.
Matt Mackall - July 8, 2015, 8 p.m.
On Wed, 2015-07-08 at 12:26 -0700, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1436376551 25200
> #      Wed Jul 08 10:29:11 2015 -0700
> # Node ID 9364d0d278b0c616a2edf4f412c1467297dbfc39
> # Parent  3bca115973ad5f471e1ca4aa4252ad6e151ff1c8
> convert: support multiple specifed revs in git source

These are queued for default, thanks.

Patch

diff --git a/hgext/convert/git.py b/hgext/convert/git.py
--- a/hgext/convert/git.py
+++ b/hgext/convert/git.py
@@ -89,10 +89,6 @@  class convert_git(converter_source):
     def __init__(self, ui, path, revs=None):
         super(convert_git, self).__init__(ui, path, revs=revs)
 
-        if revs and len(revs) > 1:
-            raise util.Abort(_("git source does not support specifying "
-                               "multiple revs"))
-
         if os.path.isdir(path + "/.git"):
             path += "/.git"
         if not os.path.exists(path + "/objects"):
@@ -126,12 +122,15 @@  class convert_git(converter_source):
         if not self.revs:
             heads, ret = self.gitread('git rev-parse --branches --remotes')
             heads = heads.splitlines()
+            if ret:
+                raise util.Abort(_('cannot retrieve git heads'))
         else:
-            heads, ret = self.gitread("git rev-parse --verify %s" %
-                                      self.revs[0])
-            heads = [heads[:-1]]
-        if ret:
-            raise util.Abort(_('cannot retrieve git heads'))
+            heads = []
+            for rev in self.revs:
+                rawhead, ret = self.gitread("git rev-parse --verify %s" % rev)
+                heads.append(rawhead[:-1])
+                if ret:
+                    raise util.Abort(_('cannot retrieve git head "%s"') % rev)
         return heads
 
     def catfile(self, rev, type):
diff --git a/tests/test-convert-git.t b/tests/test-convert-git.t
--- a/tests/test-convert-git.t
+++ b/tests/test-convert-git.t
@@ -442,6 +442,40 @@  convert author committer
   abort: --sourcesort is not supported by this data source
   [255]
 
+test converting certain branches
+
+  $ mkdir git-testrevs
+  $ cd git-testrevs
+  $ git init
+  Initialized empty Git repository in $TESTTMP/git-testrevs/.git/
+  $ echo a >> a ; git add a > /dev/null; git commit -m 'first' > /dev/null
+  $ echo a >> a ; git add a > /dev/null; git commit -m 'master commit' > /dev/null
+  $ git checkout -b goodbranch 'HEAD^'
+  Switched to a new branch 'goodbranch'
+  $ echo a >> b ; git add b > /dev/null; git commit -m 'good branch commit' > /dev/null
+  $ git checkout -b badbranch 'HEAD^'
+  Switched to a new branch 'badbranch'
+  $ echo a >> c ; git add c > /dev/null; git commit -m 'bad branch commit' > /dev/null
+  $ cd ..
+  $ hg convert git-testrevs hg-testrevs --rev master --rev goodbranch
+  initializing destination hg-testrevs repository
+  scanning source...
+  sorting...
+  converting...
+  2 first
+  1 good branch commit
+  0 master commit
+  updating bookmarks
+  $ cd hg-testrevs
+  $ hg log -G -T '{rev} {bookmarks}'
+  o  2 master
+  |
+  | o  1 goodbranch
+  |/
+  o  0
+  
+  $ cd ..
+
 test sub modules
 
   $ mkdir git-repo5