changeset 5921:549a7ebe1607

merge with crew-stable
author Thomas Arendsen Hein <thomas@intevation.de>
date Tue, 22 Jan 2008 00:55:01 +0100
parents d0576d065993 (current diff) 5df7cb799baf (diff)
children df7f66f290b9
files hgext/convert/cvs.py hgext/convert/hg.py hgext/convert/subversion.py mercurial/util.py tests/test-convert-cvs tests/test-convert-cvs.out
diffstat 6 files changed, 93 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/cvs.py	Sun Jan 20 14:39:25 2008 +0100
+++ b/hgext/convert/cvs.py	Tue Jan 22 00:55:01 2008 +0100
@@ -53,11 +53,13 @@
             os.chdir(self.path)
             id = None
             state = 0
+            filerevids = {}
             for l in util.popen(cmd):
                 if state == 0: # header
                     if l.startswith("PatchSet"):
                         id = l[9:-2]
                         if maxrev and int(id) > maxrev:
+                            # ignore everything
                             state = 3
                     elif l.startswith("Date"):
                         date = util.parsedate(l[6:-1], ["%Y/%m/%d %H:%M:%S"])
@@ -68,7 +70,8 @@
                         self.lastbranch[branch] = id
                     elif l.startswith("Ancestor branch"):
                         ancestor = l[17:-1]
-                        self.parent[id] = self.lastbranch[ancestor]
+                        # figure out the parent later
+                        self.parent[id] = None
                     elif l.startswith("Author"):
                         author = self.recode(l[8:-1])
                     elif l.startswith("Tag:") or l.startswith("Tags:"):
@@ -77,23 +80,36 @@
                         if (len(t) > 1) or (t[0] and (t[0] != "(none)")):
                             self.tags.update(dict.fromkeys(t, id))
                     elif l.startswith("Log:"):
+                        # switch to gathering log
                         state = 1
                         log = ""
                 elif state == 1: # log
                     if l == "Members: \n":
+                        # switch to gathering members
                         files = {}
+                        oldrevs = []
                         log = self.recode(log[:-1])
                         state = 2
                     else:
+                        # gather log
                         log += l
-                elif state == 2:
-                    if l == "\n": #
+                elif state == 2: # members
+                    if l == "\n": # start of next entry
                         state = 0
                         p = [self.parent[id]]
                         if id == "1":
                             p = []
                         if branch == "HEAD":
                             branch = ""
+                        if branch and p[0] == None:
+                            latest = None
+                            # the last changeset that contains a base
+                            # file is our parent
+                            for r in oldrevs:
+                                latest = max(filerevids[r], latest)
+                            p = [latest]
+
+                        # add current commit to set
                         c = commit(author=author, date=date, parents=p,
                                    desc=log, branch=branch)
                         self.changeset[id] = c
@@ -102,9 +118,14 @@
                         colon = l.rfind(':')
                         file = l[1:colon]
                         rev = l[colon+1:-2]
-                        rev = rev.split("->")[1]
+                        oldrev, rev = rev.split("->")
                         files[file] = rev
+
+                        # save some information for identifying branch points
+                        oldrevs.append("%s:%s" % (oldrev, file))
+                        filerevids["%s:%s" % (rev, file)] = id
                 elif state == 3:
+                    # swallow all input
                     continue
 
             self.heads = self.lastbranch.values()
--- a/hgext/convert/hg.py	Sun Jan 20 14:39:25 2008 +0100
+++ b/hgext/convert/hg.py	Tue Jan 22 00:55:01 2008 +0100
@@ -30,6 +30,8 @@
         if os.path.isdir(path) and len(os.listdir(path)) > 0:
             try:
                 self.repo = hg.repository(self.ui, path)
+                if not self.repo.local():
+                    raise NoRepo(_('%s is not a local Mercurial repo') % path)
             except hg.RepoError, err:
                 ui.print_exc()
                 raise NoRepo(err.args[0])
@@ -37,6 +39,8 @@
             try:
                 ui.status(_('initializing destination %s repository\n') % path)
                 self.repo = hg.repository(self.ui, path, create=True)
+                if not self.repo.local():
+                    raise NoRepo(_('%s is not a local Mercurial repo') % path)
                 self.created.append(path)
             except hg.RepoError, err:
                 ui.print_exc()
--- a/hgext/convert/subversion.py	Sun Jan 20 14:39:25 2008 +0100
+++ b/hgext/convert/subversion.py	Tue Jan 22 00:55:01 2008 +0100
@@ -646,7 +646,7 @@
             # '2007-01-04T17:35:00.902377Z'
             date = util.parsedate(date[:19] + " UTC", ["%Y-%m-%dT%H:%M:%S"])
 
-            log = message and self.recode(message)
+            log = message and self.recode(message) or ''
             author = author and self.recode(author) or ''
             try:
                 branch = self.module.split("/")[-1]
--- a/mercurial/util.py	Sun Jan 20 14:39:25 2008 +0100
+++ b/mercurial/util.py	Tue Jan 22 00:55:01 2008 +0100
@@ -15,7 +15,7 @@
 from i18n import _
 import cStringIO, errno, getpass, popen2, re, shutil, sys, tempfile, strutil
 import os, stat, threading, time, calendar, ConfigParser, locale, glob, osutil
-import re, urlparse
+import urlparse
 
 try:
     set = set
--- a/tests/test-convert-cvs	Sun Jan 20 14:39:25 2008 +0100
+++ b/tests/test-convert-cvs	Tue Jan 22 00:55:01 2008 +0100
@@ -71,3 +71,25 @@
 cat src-hg/b/c
 hg -R src-filemap log --template '#rev# #desc# files: #files#\n'
 
+echo % commit branch
+cd src
+cvs -q update -r1.1 b/c
+cvs -q tag -b branch
+cvs -q update -r branch
+echo d >> b/c
+cvs -q commit -mci2 . | grep '<--' |\
+    sed -e 's:.*src/\(.*\),v.*:checking in src/\1,v:g'
+cd ..
+
+echo % convert again
+hg convert src src-hg | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
+cat src-hg/a
+cat src-hg/b/c
+
+echo % convert again with --filemap
+hg convert --filemap filemap src src-filemap | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
+cat src-hg/b/c
+hg -R src-filemap log --template '#rev# #desc# files: #files#\n'
+
+echo "graphlog = " >> $HGRCPATH
+hg -R src-hg glog --template '#rev# (#branches#) #desc# files: #files#\n'
--- a/tests/test-convert-cvs.out	Sun Jan 20 14:39:25 2008 +0100
+++ b/tests/test-convert-cvs.out	Tue Jan 22 00:55:01 2008 +0100
@@ -67,3 +67,43 @@
 2 update tags files: .hgtags
 1 ci0 files: b/c
 0 Initial revision files: b/c
+% commit branch
+U b/c
+T a
+T b/c
+checking in src/b/c,v
+% convert again
+connecting to cvsrepo
+scanning source...
+sorting...
+converting...
+0 ci2
+a
+a
+c
+d
+% convert again with --filemap
+connecting to cvsrepo
+scanning source...
+sorting...
+converting...
+0 ci2
+c
+d
+4 ci2 files: b/c
+3 ci1 files: b/c
+2 update tags files: .hgtags
+1 ci0 files: b/c
+0 Initial revision files: b/c
+o  5 (branch) ci2 files: b/c
+|
+| o  4 () ci1 files: a b/c
+| |
+| o  3 () update tags files: .hgtags
+| |
+| o  2 () ci0 files: b/c
+|/
+| o  1 (INITIAL) import files:
+|/
+o  0 () Initial revision files: a b/c
+