Make sure all popen calls use binary mode (for Windows) and
also make gitBranchExists work on Windows. Signed-off-by: Simon Hausmann <hausmann@kde.org>
Simon Hausmann committed
May 15, 2007 at 14:57 UTC
caace111129545559bf798d83ac8cfd596d36f66
1 file changed
+19
-17
contrib/fast-import/git-p4
+19
-17
@@ -14,6 +14,9 @@ from sets import Set;
14
15
gitdir = os.environ.get("GIT_DIR", "")
16
17
+def mypopen(command):
18
+ return os.popen(command, "rb");
19
+
20
def p4CmdList(cmd):
21
cmd = "p4 -G %s" % cmd
22
pipe = os.popen(cmd, "rb")
@@ -57,7 +60,7 @@ def die(msg):
60
sys.exit(1)
61
62
def currentGitBranch():
60
- return os.popen("git name-rev HEAD").read().split(" ")[1][:-1]
63
+ return mypopen("git name-rev HEAD").read().split(" ")[1][:-1]
64
65
def isValidGitDir(path):
66
if os.path.exists(path + "/HEAD") and os.path.exists(path + "/refs") and os.path.exists(path + "/objects"):
@@ -71,7 +74,7 @@ def system(cmd):
74
def extractLogMessageFromGitCommit(commit):
75
logMessage = ""
76
foundTitle = False
74
- for log in os.popen("git cat-file commit %s" % commit).readlines():
77
+ for log in mypopen("git cat-file commit %s" % commit).readlines():
78
if not foundTitle:
79
if len(log) == 1:
80
foundTitle = True
@@ -100,9 +103,8 @@ def extractDepotPathAndChangeFromGitLog(log):
103
return values.get("depot-path"), values.get("change")
104
105
def gitBranchExists(branch):
103
- if os.system("git rev-parse %s 2>/dev/null >/dev/null" % branch) == 0:
104
- return True
105
- return False
106
+ proc = subprocess.Popen(["git", "rev-parse", branch], stderr=subprocess.PIPE, stdout=subprocess.PIPE);
107
+ return proc.wait() == 0;
108
109
class Command:
110
def __init__(self):
@@ -146,7 +148,7 @@ class P4CleanTags(Command):
148
caretIdx = len(output) - 1
149
rev = int(output[tagIdx + 9 : caretIdx])
150
149
- allTags = os.popen("git tag -l p4/").readlines()
151
+ allTags = mypopen("git tag -l p4/").readlines()
152
for i in range(len(allTags)):
153
allTags[i] = int(allTags[i][3:-1])
154
@@ -155,7 +157,7 @@ class P4CleanTags(Command):
157
allTags.remove(rev)
158
159
for rev in allTags:
158
- print os.popen("git tag -d p4/%s" % rev).read()
160
+ print mypopen("git tag -d p4/%s" % rev).read()
161
162
print "%s tags removed." % len(allTags)
163
return True
@@ -194,7 +196,7 @@ class P4Submit(Command):
196
die("Cannot start sync. Previous sync config found at %s" % self.configFile)
197
198
commits = []
197
- for line in os.popen("git rev-list --no-merges %s..%s" % (self.origin, self.master)).readlines():
199
+ for line in mypopen("git rev-list --no-merges %s..%s" % (self.origin, self.master)).readlines():
200
commits.append(line[:-1])
201
commits.reverse()
202
@@ -224,8 +226,8 @@ class P4Submit(Command):
226
return result
227
228
def apply(self, id):
227
- print "Applying %s" % (os.popen("git log --max-count=1 --pretty=oneline %s" % id).read())
228
- diff = os.popen("git diff-tree -r --name-status \"%s^\" \"%s\"" % (id, id)).readlines()
229
+ print "Applying %s" % (mypopen("git log --max-count=1 --pretty=oneline %s" % id).read())
230
+ diff = mypopen("git diff-tree -r --name-status \"%s^\" \"%s\"" % (id, id)).readlines()
231
filesToAdd = set()
232
filesToDelete = set()
233
for line in diff:
@@ -282,11 +284,11 @@ class P4Submit(Command):
284
logMessage = logMessage.replace("\n", "\n\t")
285
logMessage = logMessage[:-1]
286
285
- template = os.popen("p4 change -o").read()
287
+ template = mypopen("p4 change -o").read()
288
289
if self.interactive:
290
submitTemplate = self.prepareLogMessage(template, logMessage)
289
- diff = os.popen("p4 diff -du ...").read()
291
+ diff = mypopen("p4 diff -du ...").read()
292
293
for newFile in filesToAdd:
294
diff += "==== new file ====\n"
@@ -323,7 +325,7 @@ class P4Submit(Command):
325
print submitTemplate
326
raw_input("Press return to continue...")
327
else:
326
- pipe = os.popen("p4 submit -i", "w")
328
+ pipe = mypopen("p4 submit -i", "w")
329
pipe.write(submitTemplate)
330
pipe.close()
331
else:
@@ -920,7 +922,7 @@ class P4Sync(Command):
922
endPos = caretIdx
923
self.rev = int(output[tagIdx + 9 : endPos]) + 1
924
self.changeRange = "@%s,#head" % self.rev
923
- self.initialParent = os.popen("git rev-parse %s" % self.branch).read()[:-1]
925
+ self.initialParent = mypopen("git rev-parse %s" % self.branch).read()[:-1]
926
except:
927
pass
928
@@ -977,7 +979,7 @@ class P4Sync(Command):
979
980
changes.sort()
981
else:
980
- output = os.popen("p4 changes %s...%s" % (self.depotPath, self.changeRange)).readlines()
982
+ output = mypopen("p4 changes %s...%s" % (self.depotPath, self.changeRange)).readlines()
983
984
for line in output:
985
changeNum = line.split(" ")[1]
@@ -1060,7 +1062,7 @@ class P4Rebase(Command):
1062
sync = P4Sync()
1063
sync.run([])
1064
print "Rebasing the current branch"
1063
- oldHead = os.popen("git rev-parse HEAD").read()[:-1]
1065
+ oldHead = mypopen("git rev-parse HEAD").read()[:-1]
1066
system("git rebase p4")
1067
system("git diff-tree --stat --summary -M %s HEAD" % oldHead)
1068
return True
@@ -1176,7 +1178,7 @@ if cmd.needsGit:
1178
if len(gitdir) == 0:
1179
gitdir = ".git"
1180
if not isValidGitDir(gitdir):
1179
- cdup = os.popen("git rev-parse --show-cdup").read()[:-1]
1181
+ cdup = mypopen("git rev-parse --show-cdup").read()[:-1]
1182
if isValidGitDir(cdup + "/" + gitdir):
1183
os.chdir(cdup)
1184