Mercurial > hg
annotate hgext/convert/monotone.py @ 9823:11d7bb5e0df2
convert/mtn: handle change in mtn 0.45 certs output
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Tue, 10 Nov 2009 23:45:24 +0100 |
parents | f6c99b1628d7 |
children | 25e572394f5c |
rev | line source |
---|---|
8250
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8127
diff
changeset
|
1 # monotone.py - monotone support for the convert extension |
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8127
diff
changeset
|
2 # |
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8127
diff
changeset
|
3 # Copyright 2008, 2009 Mikkel Fahnoe Jorgensen <mikkel@dvide.com> and |
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8127
diff
changeset
|
4 # others |
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8127
diff
changeset
|
5 # |
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8127
diff
changeset
|
6 # This software may be used and distributed according to the terms of the |
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8127
diff
changeset
|
7 # GNU General Public License version 2, incorporated herein by reference. |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
8 |
7873
4a4c7f6a5912
cleanup: drop unused imports
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
6632
diff
changeset
|
9 import os, re |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
10 from mercurial import util |
7873
4a4c7f6a5912
cleanup: drop unused imports
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
6632
diff
changeset
|
11 from common import NoRepo, commit, converter_source, checktool |
6332
950e72fc7cf3
convert: allow missing tools not to stop source type detection
Patrick Mezard <pmezard@gmail.com>
parents:
6307
diff
changeset
|
12 from common import commandline |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
13 from mercurial.i18n import _ |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
14 |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
15 class monotone_source(converter_source, commandline): |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
16 def __init__(self, ui, path=None, rev=None): |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
17 converter_source.__init__(self, ui, path, rev) |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
18 commandline.__init__(self, ui, 'mtn') |
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
19 |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
20 self.ui = ui |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
21 self.path = path |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
22 |
7973
db3a68fd9387
convert: attempt to check repo type before checking for tool
Matt Mackall <mpm@selenic.com>
parents:
7957
diff
changeset
|
23 norepo = NoRepo (_("%s does not look like a monotone repo") % path) |
db3a68fd9387
convert: attempt to check repo type before checking for tool
Matt Mackall <mpm@selenic.com>
parents:
7957
diff
changeset
|
24 if not os.path.exists(os.path.join(path, '_MTN')): |
8052
fe2a87a3d344
convert/mtn: allow monotone database files as sources
Patrick Mezard <pmezard@gmail.com>
parents:
8051
diff
changeset
|
25 # Could be a monotone repository (SQLite db file) |
fe2a87a3d344
convert/mtn: allow monotone database files as sources
Patrick Mezard <pmezard@gmail.com>
parents:
8051
diff
changeset
|
26 try: |
fe2a87a3d344
convert/mtn: allow monotone database files as sources
Patrick Mezard <pmezard@gmail.com>
parents:
8051
diff
changeset
|
27 header = file(path, 'rb').read(16) |
fe2a87a3d344
convert/mtn: allow monotone database files as sources
Patrick Mezard <pmezard@gmail.com>
parents:
8051
diff
changeset
|
28 except: |
fe2a87a3d344
convert/mtn: allow monotone database files as sources
Patrick Mezard <pmezard@gmail.com>
parents:
8051
diff
changeset
|
29 header = '' |
fe2a87a3d344
convert/mtn: allow monotone database files as sources
Patrick Mezard <pmezard@gmail.com>
parents:
8051
diff
changeset
|
30 if header != 'SQLite format 3\x00': |
fe2a87a3d344
convert/mtn: allow monotone database files as sources
Patrick Mezard <pmezard@gmail.com>
parents:
8051
diff
changeset
|
31 raise norepo |
7973
db3a68fd9387
convert: attempt to check repo type before checking for tool
Matt Mackall <mpm@selenic.com>
parents:
7957
diff
changeset
|
32 |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
33 # regular expressions for parsing monotone output |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
34 space = r'\s*' |
6632
aa3f61884a48
convert.monotone: fix quotes and backslashes in change descriptions.
David Reiss <davidn@gmail.com>
parents:
6376
diff
changeset
|
35 name = r'\s+"((?:\\"|[^"])*)"\s*' |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
36 value = name |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
37 revision = r'\s+\[(\w+)\]\s*' |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
38 lines = r'(?:.|\n)+' |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
39 |
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
40 self.dir_re = re.compile(space + "dir" + name) |
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
41 self.file_re = re.compile(space + "file" + name + "content" + revision) |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
42 self.add_file_re = re.compile(space + "add_file" + name + "content" + revision) |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
43 self.patch_re = re.compile(space + "patch" + name + "from" + revision + "to" + revision) |
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
44 self.rename_re = re.compile(space + "rename" + name + "to" + name) |
6376
b40e90341ae2
convert: record deleted files in monotone source
Patrick Mezard <pmezard@gmail.com>
parents:
6332
diff
changeset
|
45 self.delete_re = re.compile(space + "delete" + name) |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
46 self.tag_re = re.compile(space + "tag" + name + "revision" + revision) |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
47 self.cert_re = re.compile(lines + space + "name" + name + "value" + value) |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
48 |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
49 attr = space + "file" + lines + space + "attr" + space |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
50 self.attr_execute_re = re.compile(attr + '"mtn:execute"' + space + '"true"') |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
51 |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
52 # cached data |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
53 self.manifest_rev = None |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
54 self.manifest = None |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
55 self.files = None |
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
56 self.dirs = None |
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
57 |
6332
950e72fc7cf3
convert: allow missing tools not to stop source type detection
Patrick Mezard <pmezard@gmail.com>
parents:
6307
diff
changeset
|
58 checktool('mtn', abort=False) |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
59 |
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
60 # test if there are any revisions |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
61 self.rev = None |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
62 try: |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
63 self.getheads() |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
64 except: |
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
65 raise norepo |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
66 self.rev = rev |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
67 |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
68 def mtnrun(self, *args, **kwargs): |
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
69 kwargs['d'] = self.path |
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
70 return self.run0('automate', *args, **kwargs) |
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
71 |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
72 def mtnloadmanifest(self, rev): |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
73 if self.manifest_rev == rev: |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
74 return |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
75 self.manifest = self.mtnrun("get_manifest_of", rev).split("\n\n") |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
76 self.manifest_rev = rev |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
77 self.files = {} |
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
78 self.dirs = {} |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
79 |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
80 for e in self.manifest: |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
81 m = self.file_re.match(e) |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
82 if m: |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
83 attr = "" |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
84 name = m.group(1) |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
85 node = m.group(2) |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
86 if self.attr_execute_re.match(e): |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
87 attr += "x" |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
88 self.files[name] = (node, attr) |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
89 m = self.dir_re.match(e) |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
90 if m: |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
91 self.dirs[m.group(1)] = True |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
92 |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
93 def mtnisfile(self, name, rev): |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
94 # a non-file could be a directory or a deleted or renamed file |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
95 self.mtnloadmanifest(rev) |
8458
f6c99b1628d7
convert: cleanups in monotone converter
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8250
diff
changeset
|
96 return name in self.files |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
97 |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
98 def mtnisdir(self, name, rev): |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
99 self.mtnloadmanifest(rev) |
8458
f6c99b1628d7
convert: cleanups in monotone converter
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8250
diff
changeset
|
100 return name in self.dirs |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
101 |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
102 def mtngetcerts(self, rev): |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
103 certs = {"author":"<missing>", "date":"<missing>", |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
104 "changelog":"<missing>", "branch":"<missing>"} |
9823
11d7bb5e0df2
convert/mtn: handle change in mtn 0.45 certs output
Patrick Mezard <pmezard@gmail.com>
parents:
8458
diff
changeset
|
105 certlist = self.mtnrun("certs", rev) |
11d7bb5e0df2
convert/mtn: handle change in mtn 0.45 certs output
Patrick Mezard <pmezard@gmail.com>
parents:
8458
diff
changeset
|
106 # mtn < 0.45: |
11d7bb5e0df2
convert/mtn: handle change in mtn 0.45 certs output
Patrick Mezard <pmezard@gmail.com>
parents:
8458
diff
changeset
|
107 # key "test@selenic.com" |
11d7bb5e0df2
convert/mtn: handle change in mtn 0.45 certs output
Patrick Mezard <pmezard@gmail.com>
parents:
8458
diff
changeset
|
108 # mtn >= 0.45: |
11d7bb5e0df2
convert/mtn: handle change in mtn 0.45 certs output
Patrick Mezard <pmezard@gmail.com>
parents:
8458
diff
changeset
|
109 # key [ff58a7ffb771907c4ff68995eada1c4da068d328] |
11d7bb5e0df2
convert/mtn: handle change in mtn 0.45 certs output
Patrick Mezard <pmezard@gmail.com>
parents:
8458
diff
changeset
|
110 certlist = re.split('\n\n key ["\[]', certlist) |
11d7bb5e0df2
convert/mtn: handle change in mtn 0.45 certs output
Patrick Mezard <pmezard@gmail.com>
parents:
8458
diff
changeset
|
111 for e in certlist: |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
112 m = self.cert_re.match(e) |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
113 if m: |
6632
aa3f61884a48
convert.monotone: fix quotes and backslashes in change descriptions.
David Reiss <davidn@gmail.com>
parents:
6376
diff
changeset
|
114 name, value = m.groups() |
aa3f61884a48
convert.monotone: fix quotes and backslashes in change descriptions.
David Reiss <davidn@gmail.com>
parents:
6376
diff
changeset
|
115 value = value.replace(r'\"', '"') |
aa3f61884a48
convert.monotone: fix quotes and backslashes in change descriptions.
David Reiss <davidn@gmail.com>
parents:
6376
diff
changeset
|
116 value = value.replace(r'\\', '\\') |
aa3f61884a48
convert.monotone: fix quotes and backslashes in change descriptions.
David Reiss <davidn@gmail.com>
parents:
6376
diff
changeset
|
117 certs[name] = value |
8101
d8229670710f
convert/mtn: handle subsecond commit dates (issue1616)
Paul Aurich <paul@darkrain42.org>
parents:
8099
diff
changeset
|
118 # Monotone may have subsecond dates: 2005-02-05T09:39:12.364306 |
8125
da9f3866c637
convert/mtn: mtn does not record timezones, mark dates as UTC (issue1624)
Paul Aurich <paul@darkrain42.org>
parents:
8124
diff
changeset
|
119 # and all times are stored in UTC |
da9f3866c637
convert/mtn: mtn does not record timezones, mark dates as UTC (issue1624)
Paul Aurich <paul@darkrain42.org>
parents:
8124
diff
changeset
|
120 certs["date"] = certs["date"].split('.')[0] + " UTC" |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
121 return certs |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
122 |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
123 # implement the converter_source interface: |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
124 |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
125 def getheads(self): |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
126 if not self.rev: |
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
127 return self.mtnrun("leaves").splitlines() |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
128 else: |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
129 return [self.rev] |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
130 |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
131 def getchanges(self, rev): |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
132 #revision = self.mtncmd("get_revision %s" % rev).split("\n\n") |
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
133 revision = self.mtnrun("get_revision", rev).split("\n\n") |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
134 files = {} |
8123
933b874e402f
convert/mtn: handle files moved in a moved directory (issue1619/2)
Patrick Mezard <pmezard@gmail.com>
parents:
8101
diff
changeset
|
135 ignoremove = {} |
8099
3cdf4872941a
convert/mtn: handle new files in moved directories (issue1619)
Patrick Mezard <pmezard@gmail.com>
parents:
8050
diff
changeset
|
136 renameddirs = [] |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
137 copies = {} |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
138 for e in revision: |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
139 m = self.add_file_re.match(e) |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
140 if m: |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
141 files[m.group(1)] = rev |
8123
933b874e402f
convert/mtn: handle files moved in a moved directory (issue1619/2)
Patrick Mezard <pmezard@gmail.com>
parents:
8101
diff
changeset
|
142 ignoremove[m.group(1)] = rev |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
143 m = self.patch_re.match(e) |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
144 if m: |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
145 files[m.group(1)] = rev |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
146 # Delete/rename is handled later when the convert engine |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
147 # discovers an IOError exception from getfile, |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
148 # but only if we add the "from" file to the list of changes. |
6376
b40e90341ae2
convert: record deleted files in monotone source
Patrick Mezard <pmezard@gmail.com>
parents:
6332
diff
changeset
|
149 m = self.delete_re.match(e) |
b40e90341ae2
convert: record deleted files in monotone source
Patrick Mezard <pmezard@gmail.com>
parents:
6332
diff
changeset
|
150 if m: |
b40e90341ae2
convert: record deleted files in monotone source
Patrick Mezard <pmezard@gmail.com>
parents:
6332
diff
changeset
|
151 files[m.group(1)] = rev |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
152 m = self.rename_re.match(e) |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
153 if m: |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
154 toname = m.group(2) |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
155 fromname = m.group(1) |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
156 if self.mtnisfile(toname, rev): |
8123
933b874e402f
convert/mtn: handle files moved in a moved directory (issue1619/2)
Patrick Mezard <pmezard@gmail.com>
parents:
8101
diff
changeset
|
157 ignoremove[toname] = 1 |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
158 copies[toname] = fromname |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
159 files[toname] = rev |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
160 files[fromname] = rev |
8099
3cdf4872941a
convert/mtn: handle new files in moved directories (issue1619)
Patrick Mezard <pmezard@gmail.com>
parents:
8050
diff
changeset
|
161 elif self.mtnisdir(toname, rev): |
3cdf4872941a
convert/mtn: handle new files in moved directories (issue1619)
Patrick Mezard <pmezard@gmail.com>
parents:
8050
diff
changeset
|
162 renameddirs.append((fromname, toname)) |
3cdf4872941a
convert/mtn: handle new files in moved directories (issue1619)
Patrick Mezard <pmezard@gmail.com>
parents:
8050
diff
changeset
|
163 |
3cdf4872941a
convert/mtn: handle new files in moved directories (issue1619)
Patrick Mezard <pmezard@gmail.com>
parents:
8050
diff
changeset
|
164 # Directory renames can be handled only once we have recorded |
3cdf4872941a
convert/mtn: handle new files in moved directories (issue1619)
Patrick Mezard <pmezard@gmail.com>
parents:
8050
diff
changeset
|
165 # all new files |
3cdf4872941a
convert/mtn: handle new files in moved directories (issue1619)
Patrick Mezard <pmezard@gmail.com>
parents:
8050
diff
changeset
|
166 for fromdir, todir in renameddirs: |
3cdf4872941a
convert/mtn: handle new files in moved directories (issue1619)
Patrick Mezard <pmezard@gmail.com>
parents:
8050
diff
changeset
|
167 renamed = {} |
3cdf4872941a
convert/mtn: handle new files in moved directories (issue1619)
Patrick Mezard <pmezard@gmail.com>
parents:
8050
diff
changeset
|
168 for tofile in self.files: |
8123
933b874e402f
convert/mtn: handle files moved in a moved directory (issue1619/2)
Patrick Mezard <pmezard@gmail.com>
parents:
8101
diff
changeset
|
169 if tofile in ignoremove: |
8099
3cdf4872941a
convert/mtn: handle new files in moved directories (issue1619)
Patrick Mezard <pmezard@gmail.com>
parents:
8050
diff
changeset
|
170 continue |
3cdf4872941a
convert/mtn: handle new files in moved directories (issue1619)
Patrick Mezard <pmezard@gmail.com>
parents:
8050
diff
changeset
|
171 if tofile.startswith(todir + '/'): |
3cdf4872941a
convert/mtn: handle new files in moved directories (issue1619)
Patrick Mezard <pmezard@gmail.com>
parents:
8050
diff
changeset
|
172 renamed[tofile] = fromdir + tofile[len(todir):] |
8124
d883bfbd2e60
convert/mtn: handle directory move into moved directory (issue1619/3)
Patrick Mezard <pmezard@gmail.com>
parents:
8123
diff
changeset
|
173 # Avoid chained moves like: |
d883bfbd2e60
convert/mtn: handle directory move into moved directory (issue1619/3)
Patrick Mezard <pmezard@gmail.com>
parents:
8123
diff
changeset
|
174 # d1(/a) => d3/d1(/a) |
d883bfbd2e60
convert/mtn: handle directory move into moved directory (issue1619/3)
Patrick Mezard <pmezard@gmail.com>
parents:
8123
diff
changeset
|
175 # d2 => d3 |
d883bfbd2e60
convert/mtn: handle directory move into moved directory (issue1619/3)
Patrick Mezard <pmezard@gmail.com>
parents:
8123
diff
changeset
|
176 ignoremove[tofile] = 1 |
8099
3cdf4872941a
convert/mtn: handle new files in moved directories (issue1619)
Patrick Mezard <pmezard@gmail.com>
parents:
8050
diff
changeset
|
177 for tofile, fromfile in renamed.items(): |
8100 | 178 self.ui.debug (_("copying file in renamed directory " |
179 "from '%s' to '%s'") | |
8099
3cdf4872941a
convert/mtn: handle new files in moved directories (issue1619)
Patrick Mezard <pmezard@gmail.com>
parents:
8050
diff
changeset
|
180 % (fromfile, tofile), '\n') |
3cdf4872941a
convert/mtn: handle new files in moved directories (issue1619)
Patrick Mezard <pmezard@gmail.com>
parents:
8050
diff
changeset
|
181 files[tofile] = rev |
3cdf4872941a
convert/mtn: handle new files in moved directories (issue1619)
Patrick Mezard <pmezard@gmail.com>
parents:
8050
diff
changeset
|
182 copies[tofile] = fromfile |
3cdf4872941a
convert/mtn: handle new files in moved directories (issue1619)
Patrick Mezard <pmezard@gmail.com>
parents:
8050
diff
changeset
|
183 for fromfile in renamed.values(): |
3cdf4872941a
convert/mtn: handle new files in moved directories (issue1619)
Patrick Mezard <pmezard@gmail.com>
parents:
8050
diff
changeset
|
184 files[fromfile] = rev |
3cdf4872941a
convert/mtn: handle new files in moved directories (issue1619)
Patrick Mezard <pmezard@gmail.com>
parents:
8050
diff
changeset
|
185 |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
186 return (files.items(), copies) |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
187 |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
188 def getmode(self, name, rev): |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
189 self.mtnloadmanifest(rev) |
8458
f6c99b1628d7
convert: cleanups in monotone converter
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8250
diff
changeset
|
190 node, attr = self.files.get(name, (None, "")) |
f6c99b1628d7
convert: cleanups in monotone converter
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8250
diff
changeset
|
191 return attr |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
192 |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
193 def getfile(self, name, rev): |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
194 if not self.mtnisfile(name, rev): |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
195 raise IOError() # file was deleted or renamed |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
196 try: |
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
197 return self.mtnrun("get_file_of", name, r=rev) |
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
198 except: |
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
199 raise IOError() # file was deleted or renamed |
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
200 |
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
201 def getcommit(self, rev): |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
202 certs = self.mtngetcerts(rev) |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
203 return commit( |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
204 author=certs["author"], |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
205 date=util.datestr(util.strdate(certs["date"], "%Y-%m-%dT%H:%M:%S")), |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
206 desc=certs["changelog"], |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
207 rev=rev, |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
208 parents=self.mtnrun("parents", rev).splitlines(), |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
209 branch=certs["branch"]) |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
210 |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
211 def gettags(self): |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
212 tags = {} |
6307
6840668e3bf6
cleanup monotone conversion and use commandline class
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
6306
diff
changeset
|
213 for e in self.mtnrun("tags").split("\n\n"): |
6306
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
214 m = self.tag_re.match(e) |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
215 if m: |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
216 tags[m.group(1)] = m.group(2) |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
217 return tags |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
218 |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
219 def getchangedfiles(self, rev, i): |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
220 # This function is only needed to support --filemap |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
221 # ... and we don't support that |
2f9de4aaea9e
initial version of monotone source for convert extension
Mikkel Fahnøe Jørgensen <mikkel@dvide.com>
parents:
diff
changeset
|
222 raise NotImplementedError() |