]>
git.ipfire.org Git - thirdparty/git.git/blob - contrib/fast-import/p4-fast-export.py
5 # Author: Simon Hausmann <hausmann@kde.org>
6 # License: MIT <http://www.opensource.org/licenses/mit-license.php>
8 # TODO: - fix date parsing (how hard can it be?)
9 # - support integrations (at least p4i)
10 # - support incremental imports
12 # - instead of reading all files into a variable try to pipe from
13 # - p4 print directly to stdout. need to figure out file size somehow
15 # - support p4 submit (hah!)
16 # - don't hardcode the import to master
18 import os
, string
, sys
20 # yep, that's hardcoded right. will fix to a commandline option rsn :)
21 prefix
= "//depot/qt/main/"
22 # that's in revision range syntax, for example @2342,523634
26 output
= os
.popen("p4 describe %s" % change
).readlines()
30 author
= firstLine
.split(" ")[3]
31 author
= author
[:author
.find("@")]
35 filesSection
= output
.index("Affected files ...\n")
37 sys
.stderr
.write("Change %s doesn't seem to affect any files. Weird.\n" % change
)
40 differencesSection
= 0
42 differencesSection
= output
.index("Differences ...\n")
44 sys
.stderr
.write("Change %s doesn't seem to have a differences section. Weird.\n" % change
)
47 log
= output
[2:filesSection
- 1]
49 lines
= output
[filesSection
+ 2:differencesSection
- 1]
55 # chop off "... " and trailing newline
56 line
= line
[4:len(line
) - 1]
58 lastSpace
= line
.rfind(" ")
60 sys
.stderr
.write("trouble parsing line %s, skipping!\n" % line
)
63 operation
= line
[lastSpace
+ 1:]
64 path
= line
[:lastSpace
]
66 if operation
== "delete":
71 return author
, log
, changed
, removed
74 return os
.popen("p4 print -q \"%s\"" % path
).read()
76 def stripRevision(path
):
77 hashPos
= path
.rindex("#")
82 output
= os
.popen("p4 users")
84 firstSpace
= line
.index(" ")
85 secondSpace
= line
.index(" ", firstSpace
+ 1)
86 key
= line
[:firstSpace
]
87 email
= line
[firstSpace
+ 1:secondSpace
]
88 openParenPos
= line
.index("(", secondSpace
)
89 closedParenPos
= line
.index(")", openParenPos
)
90 name
= line
[openParenPos
+ 1:closedParenPos
]
92 users
[key
] = name
+ " " + email
99 output
= os
.popen("p4 changes %s...%s" % (prefix
, changeRange
)).readlines()
103 changeNum
= line
.split(" ")[1]
104 changes
.append(changeNum
)
108 sys
.stderr
.write("\n")
111 for change
in changes
:
112 [ author
, log
, changedFiles
, removedFiles
] = describe(change
)
113 sys
.stderr
.write("\rimporting revision %s (%s%%)" % (change
, cnt
* 100 / len(changes
)))
115 # sys.stderr.write("%s\n" % log)
116 # sys.stderr.write("%s\n" % changedFiles)
117 # sys.stderr.write("%s\n" % removedFiles)
119 print "commit refs/heads/master"
121 print "committer %s 1 2" % users
[author
]
123 print "committer %s <a@b> 1 2" % author
131 for f
in changedFiles
:
132 if not f
.startswith(prefix
):
133 sys
.stderr
.write("\nchanged files: ignoring path %s outside of %s in change %s\n" % (f
, prefix
, change
))
135 relpath
= f
[len(prefix
):]
136 print "M 644 inline %s" % stripRevision(relpath
)
138 print "data %s" % len(data
)
139 sys
.stdout
.write(data
)
142 for f
in removedFiles
:
143 if not f
.startswith(prefix
):
144 sys
.stderr
.write("\ndeleted files: ignoring path %s outside of %s in change %s\n" % (f
, prefix
, change
))
146 relpath
= f
[len(prefix
):]
147 print "D %s" % stripRevision(relpath
)