##// END OF EJS Templates
Merge with crew
Matt Mackall -
r5366:ff32b272 merge default
parent child Browse files
Show More
@@ -1,137 +1,137 b''
1 1 # darcs support for the convert extension
2 2
3 3 from common import NoRepo, commit, converter_source
4 4 from mercurial.i18n import _
5 5 from mercurial import util
6 6 import os, shutil, tempfile
7 7
8 8 # The naming drift of ElementTree is fun!
9 9
10 10 try: from xml.etree.cElementTree import ElementTree
11 11 except ImportError:
12 12 try: from xml.etree.ElementTree import ElementTree
13 13 except ImportError:
14 14 try: from elementtree.cElementTree import ElementTree
15 15 except ImportError:
16 16 try: from elementtree.ElementTree import ElementTree
17 17 except ImportError: ElementTree = None
18 18
19 19
20 20 class darcs_source(converter_source):
21 21 def __init__(self, ui, path, rev=None):
22 22 super(darcs_source, self).__init__(ui, path, rev=rev)
23 23
24 24 if not os.path.exists(os.path.join(path, '_darcs', 'inventory')):
25 25 raise NoRepo("couldn't open darcs repo %s" % path)
26 26
27 27 if ElementTree is None:
28 28 raise util.Abort(_("Python ElementTree module is not available"))
29 29
30 30 self.path = os.path.realpath(path)
31 31
32 32 self.lastrev = None
33 33 self.changes = {}
34 34 self.parents = {}
35 35 self.tags = {}
36 36
37 37 def before(self):
38 38 self.tmppath = tempfile.mkdtemp(
39 39 prefix='convert-' + os.path.basename(self.path) + '-')
40 40 output, status = self.run('init', repodir=self.tmppath)
41 41 self.checkexit(status)
42 42
43 43 tree = self.xml('changes', '--xml-output', '--summary')
44 44 tagname = None
45 45 child = None
46 46 for elt in tree.findall('patch'):
47 47 node = elt.get('hash')
48 48 name = elt.findtext('name', '')
49 49 if name.startswith('TAG '):
50 50 tagname = name[4:].strip()
51 51 elif tagname is not None:
52 52 self.tags[tagname] = node
53 53 tagname = None
54 54 self.changes[node] = elt
55 55 self.parents[child] = [node]
56 56 child = node
57 57 self.parents[child] = []
58 58
59 59 def after(self):
60 60 self.ui.debug('cleaning up %s\n' % self.tmppath)
61 #shutil.rmtree(self.tmppath, ignore_errors=True)
61 shutil.rmtree(self.tmppath, ignore_errors=True)
62 62
63 63 def _run(self, cmd, *args, **kwargs):
64 64 cmdline = 'darcs %s --repodir=%r %s </dev/null' % (
65 65 cmd, kwargs.get('repodir', self.path), ' '.join(args))
66 66 self.ui.debug(cmdline, '\n')
67 67 return os.popen(cmdline, 'r')
68 68
69 69 def run(self, cmd, *args, **kwargs):
70 70 fp = self._run(cmd, *args, **kwargs)
71 71 output = fp.read()
72 72 return output, fp.close()
73 73
74 74 def checkexit(self, status, output=''):
75 75 if status:
76 76 if output:
77 ui.warn(_('darcs error:\n'))
78 ui.warn(output)
77 self.ui.warn(_('darcs error:\n'))
78 self.ui.warn(output)
79 79 msg = util.explain_exit(status)[0]
80 80 raise util.Abort(_('darcs %s') % msg)
81 81
82 82 def xml(self, cmd, *opts):
83 83 etree = ElementTree()
84 84 fp = self._run(cmd, *opts)
85 85 etree.parse(fp)
86 86 self.checkexit(fp.close())
87 87 return etree.getroot()
88 88
89 89 def getheads(self):
90 90 return self.parents[None]
91 91
92 92 def getcommit(self, rev):
93 93 elt = self.changes[rev]
94 94 date = util.strdate(elt.get('local_date'), '%a %b %d %H:%M:%S %Z %Y')
95 95 desc = elt.findtext('name') + '\n' + elt.findtext('comment', '')
96 96 return commit(author=elt.get('author'), date=util.datestr(date),
97 97 desc=desc.strip(), parents=self.parents[rev])
98 98
99 99 def pull(self, rev):
100 100 output, status = self.run('pull %r --all --match="hash %s"' %
101 101 (self.path, rev),
102 102 '--no-test', '--no-posthook',
103 103 '--external-merge=/bin/false',
104 104 repodir=self.tmppath)
105 105 if status:
106 106 if output.find('We have conflicts in') == -1:
107 107 self.checkexit(status, output)
108 108 output, status = self.run('revert --all', repodir=self.tmppath)
109 109 self.checkexit(status, output)
110 110
111 111 def getchanges(self, rev):
112 112 self.pull(rev)
113 113 copies = {}
114 114 changes = []
115 115 for elt in self.changes[rev].find('summary').getchildren():
116 116 if elt.tag in ('add_directory', 'remove_directory'):
117 117 continue
118 118 if elt.tag == 'move':
119 119 changes.append((elt.get('from'), rev))
120 120 copies[elt.get('from')] = elt.get('to')
121 121 else:
122 122 changes.append((elt.text.strip(), rev))
123 123 changes.sort()
124 124 self.lastrev = rev
125 125 return changes, copies
126 126
127 127 def getfile(self, name, rev):
128 128 if rev != self.lastrev:
129 129 raise util.Abort(_('internal calling inconsistency'))
130 130 return open(os.path.join(self.tmppath, name), 'rb').read()
131 131
132 132 def getmode(self, name, rev):
133 133 mode = os.lstat(os.path.join(self.tmppath, name)).st_mode
134 134 return (mode & 0111) and 'x' or ''
135 135
136 136 def gettags(self):
137 137 return self.tags
@@ -1,50 +1,51 b''
1 1 #!/bin/sh
2 2
3 3 "$TESTDIR/hghave" cvs cvsps || exit 80
4 4
5 5 echo "[extensions]" >> $HGRCPATH
6 6 echo "convert = " >> $HGRCPATH
7 7
8 8 echo % create cvs repository
9 9 mkdir cvsrepo
10 10 cd cvsrepo
11 11 export CVSROOT=`pwd`
12 12 cd ..
13 13
14 14 cvs -q -d "$CVSROOT" init
15 15
16 16 echo % create source directory
17 17 mkdir src-temp
18 18 cd src-temp
19 19 echo a > a
20 20 mkdir b
21 21 cd b
22 22 echo c > c
23 23 cd ..
24 24
25 25 echo % import source directory
26 26 cvs -q import -m import src INITIAL start
27 27 cd ..
28 28
29 29 echo % checkout source directory
30 30 cvs -q checkout src
31 31
32 32 echo % convert fresh repo
33 33 hg convert src src-hg | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
34 34 cat src-hg/a
35 35 cat src-hg/b/c
36 36
37 37 echo % commit new file revisions
38 38 cd src
39 39 echo a >> a
40 40 echo c >> b/c
41 cvs -q commit -mci1 . | sed -e 's:.*src/\(.*\),v:src/\1,v:g'
41 cvs -q commit -mci1 . | grep '<--' |\
42 sed -e 's:.*src/\(.*\),v.*:checking in src/\1,v:g'
42 43 cd ..
43 44
44 45 echo % convert again
45 46 hg convert src src-hg | sed -e 's/connecting to.*cvsrepo/connecting to cvsrepo/g'
46 47 cat src-hg/a
47 48 cat src-hg/b/c
48 49
49 50
50 51
@@ -1,39 +1,37 b''
1 1 % create cvs repository
2 2 % create source directory
3 3 % import source directory
4 4 N src/a
5 5 N src/b/c
6 6
7 7 No conflicts created by this import
8 8
9 9 % checkout source directory
10 10 U src/a
11 11 U src/b/c
12 12 % convert fresh repo
13 13 initializing destination src-hg repository
14 14 connecting to cvsrepo
15 15 scanning source...
16 16 sorting...
17 17 converting...
18 18 1 Initial revision
19 19 0 import
20 20 updating tags
21 21 a
22 22 c
23 23 % commit new file revisions
24 src/a,v <-- a
25 new revision: 1.2; previous revision: 1.1
26 src/b/c,v <-- b/c
27 new revision: 1.2; previous revision: 1.1
24 checking in src/a,v
25 checking in src/b/c,v
28 26 % convert again
29 27 destination src-hg is a Mercurial repository
30 28 connecting to cvsrepo
31 29 scanning source...
32 30 sorting...
33 31 converting...
34 32 0 ci1
35 33 updating tags
36 34 a
37 35 a
38 36 c
39 37 c
General Comments 0
You need to be logged in to leave comments. Login now