Implemented basic support for converting the date of the perforce change to the git format. The timezone isn't correctly set up yet though.
Signed-off-by: Simon Hausmann <shausman@trolltech.com>
Simon Hausmann committed
Jan 31, 2007 at 16:39 UTC
72b2f0ada30adbb2880d551bd92d9519396897dd
1 file changed
+15
-11
contrib/fast-import/p4-fast-export.py
+15
-11
@@ -5,8 +5,7 @@
5
# Author: Simon Hausmann <hausmann@kde.org>
6
# License: MIT <http://www.opensource.org/licenses/mit-license.php>
7
#
8
-# TODO: - fix date parsing (how hard can it be?)
9
-# - support integrations (at least p4i)
8
+# TODO: - support integrations (at least p4i)
9
# - support incremental imports
10
# - create tags
11
# - instead of reading all files into a variable try to pipe from
@@ -15,7 +14,7 @@
14
# - support p4 submit (hah!)
15
# - don't hardcode the import to master
16
#
18
-import os, string, sys
17
+import os, string, sys, time
18
19
if len(sys.argv) != 2:
20
sys.stderr.write("usage: %s //depot/path[@revRange]\n" % sys.argv[0]);
@@ -44,22 +43,25 @@ def describe(change):
43
44
firstLine = output[0]
45
47
- author = firstLine.split(" ")[3]
46
+ splitted = firstLine.split(" ")
47
+ author = splitted[3]
48
author = author[:author.find("@")]
49
+ tm = time.strptime(splitted[5] + " " + splitted[6] + time.tzname[0], "%Y/%m/%d %H:%M:%S %Z")
50
+ epoch = int(time.mktime(tm))
51
52
filesSection = 0
53
try:
54
filesSection = output.index("Affected files ...\n")
55
except ValueError:
56
sys.stderr.write("Change %s doesn't seem to affect any files. Weird.\n" % change)
55
- return [], [], [], []
57
+ return [], [], [], [], []
58
59
differencesSection = 0
60
try:
61
differencesSection = output.index("Differences ...\n")
62
except ValueError:
63
sys.stderr.write("Change %s doesn't seem to have a differences section. Weird.\n" % change)
62
- return [], [], [], []
64
+ return [], [], [], [], []
65
66
log = output[2:filesSection - 1]
67
@@ -85,7 +87,7 @@ def describe(change):
87
else:
88
changed.append(path)
89
88
- return author, log, changed, removed
90
+ return author, log, epoch, changed, removed
91
92
def p4cat(path):
93
return os.popen("p4 print -q \"%s\"" % path).read()
@@ -124,9 +126,9 @@ changes.reverse()
126
127
sys.stderr.write("\n")
128
127
-cnt = 0
129
+cnt = 1
130
for change in changes:
129
- [ author, log, changedFiles, removedFiles ] = describe(change)
131
+ [ author, log, epoch, changedFiles, removedFiles ] = describe(change)
132
sys.stderr.write("\rimporting revision %s (%s%%)" % (change, cnt * 100 / len(changes)))
133
cnt = cnt + 1
134
# sys.stderr.write("%s\n" % log)
@@ -135,9 +137,9 @@ for change in changes:
137
138
print "commit refs/heads/master"
139
if author in users:
138
- print "committer %s 1 2" % users[author]
140
+ print "committer %s %s +0000" % (users[author], epoch)
141
else:
140
- print "committer %s <a@b> 1 2" % author
142
+ print "committer %s <a@b> %s +0000" % (author, epoch)
143
print "data <<EOT"
144
for l in log:
145
print l[:len(l) - 1]
@@ -165,3 +167,5 @@ for change in changes:
167
168
print ""
169
170
+sys.stderr.write("\n")
171
+