@@ -16,6 +16,41 @@ from sets import Set;
16
16
17
17
verbose = False
18
18
19
+
20
+ def p4_build_cmd (cmd ):
21
+ """Build a suitable p4 command line.
22
+
23
+ This consolidates building and returning a p4 command line into one
24
+ location. It means that hooking into the environment, or other configuration
25
+ can be done more easily.
26
+ """
27
+ real_cmd = "%s " % "p4"
28
+
29
+ user = gitConfig ("git-p4.user" )
30
+ if len (user ) > 0 :
31
+ real_cmd += "-u %s " % user
32
+
33
+ password = gitConfig ("git-p4.password" )
34
+ if len (password ) > 0 :
35
+ real_cmd += "-P %s " % password
36
+
37
+ port = gitConfig ("git-p4.port" )
38
+ if len (port ) > 0 :
39
+ real_cmd += "-p %s " % port
40
+
41
+ host = gitConfig ("git-p4.host" )
42
+ if len (host ) > 0 :
43
+ real_cmd += "-h %s " % host
44
+
45
+ client = gitConfig ("git-p4.client" )
46
+ if len (client ) > 0 :
47
+ real_cmd += "-c %s " % client
48
+
49
+ real_cmd += "%s" % (cmd )
50
+ if verbose :
51
+ print real_cmd
52
+ return real_cmd
53
+
19
54
def chdir (dir ):
20
55
if os .name == 'nt' :
21
56
os .environ ['PWD' ]= dir
@@ -39,6 +74,10 @@ def write_pipe(c, str):
39
74
40
75
return val
41
76
77
+ def p4_write_pipe (c , str ):
78
+ real_cmd = p4_build_cmd (c )
79
+ return write_pipe (c , str )
80
+
42
81
def read_pipe (c , ignore_error = False ):
43
82
if verbose :
44
83
sys .stderr .write ('Reading pipe: %s\n ' % c )
@@ -50,6 +89,9 @@ def read_pipe(c, ignore_error=False):
50
89
51
90
return val
52
91
92
+ def p4_read_pipe (c , ignore_error = False ):
93
+ real_cmd = p4_build_cmd (c )
94
+ return read_pipe (real_cmd , ignore_error )
53
95
54
96
def read_pipe_lines (c ):
55
97
if verbose :
@@ -62,12 +104,22 @@ def read_pipe_lines(c):
62
104
63
105
return val
64
106
107
+ def p4_read_pipe_lines (c ):
108
+ """Specifically invoke p4 on the command supplied. """
109
+ real_cmd = p4_build_cmd (c )
110
+ return read_pipe_lines (real_cmd )
111
+
65
112
def system (cmd ):
66
113
if verbose :
67
114
sys .stderr .write ("executing %s\n " % cmd )
68
115
if os .system (cmd ) != 0 :
69
116
die ("command failed: %s" % cmd )
70
117
118
+ def p4_system (cmd ):
119
+ """Specifically invoke p4 as the system command. """
120
+ real_cmd = p4_build_cmd (cmd )
121
+ return system (real_cmd )
122
+
71
123
def isP4Exec (kind ):
72
124
"""Determine if a Perforce 'kind' should have execute permission
73
125
@@ -89,12 +141,12 @@ def setP4ExecBit(file, mode):
89
141
if p4Type [- 1 ] == "+" :
90
142
p4Type = p4Type [0 :- 1 ]
91
143
92
- system ( "p4 reopen -t %s %s" % (p4Type , file ))
144
+ p4_system ( " reopen -t %s %s" % (p4Type , file ))
93
145
94
146
def getP4OpenedType (file ):
95
147
# Returns the perforce file type for the given file.
96
148
97
- result = read_pipe ( "p4 opened %s" % file )
149
+ result = p4_read_pipe ( " opened %s" % file )
98
150
match = re .match (".*\((.+)\)\r ?$" , result )
99
151
if match :
100
152
return match .group (1 )
@@ -150,7 +202,7 @@ def isModeExecChanged(src_mode, dst_mode):
150
202
return isModeExec (src_mode ) != isModeExec (dst_mode )
151
203
152
204
def p4CmdList (cmd , stdin = None , stdin_mode = 'w+b' ):
153
- cmd = "p4 -G %s" % cmd
205
+ cmd = p4_build_cmd ( " -G %s" % ( cmd ))
154
206
if verbose :
155
207
sys .stderr .write ("Opening pipe: %s\n " % cmd )
156
208
@@ -369,7 +421,7 @@ def originP4BranchesExist():
369
421
370
422
def p4ChangesForPaths (depotPaths , changeRange ):
371
423
assert depotPaths
372
- output = read_pipe_lines ( "p4 changes " + ' ' .join (["%s...%s" % (p , changeRange )
424
+ output = p4_read_pipe_lines ( " changes " + ' ' .join (["%s...%s" % (p , changeRange )
373
425
for p in depotPaths ]))
374
426
375
427
changes = []
@@ -517,7 +569,7 @@ class P4Submit(Command):
517
569
# remove lines in the Files section that show changes to files outside the depot path we're committing into
518
570
template = ""
519
571
inFilesSection = False
520
- for line in read_pipe_lines ( "p4 change -o" ):
572
+ for line in p4_read_pipe_lines ( " change -o" ):
521
573
if line .endswith ("\r \n " ):
522
574
line = line [:- 2 ] + "\n "
523
575
if inFilesSection :
@@ -552,7 +604,7 @@ class P4Submit(Command):
552
604
modifier = diff ['status' ]
553
605
path = diff ['src' ]
554
606
if modifier == "M" :
555
- system ( "p4 edit \" %s\" " % path )
607
+ p4_system ( " edit \" %s\" " % path )
556
608
if isModeExecChanged (diff ['src_mode' ], diff ['dst_mode' ]):
557
609
filesToChangeExecBit [path ] = diff ['dst_mode' ]
558
610
editedFiles .add (path )
@@ -567,8 +619,8 @@ class P4Submit(Command):
567
619
filesToAdd .remove (path )
568
620
elif modifier == "R" :
569
621
src , dest = diff ['src' ], diff ['dst' ]
570
- system ( "p4 integrate -Dt \" %s\" \" %s\" " % (src , dest ))
571
- system ( "p4 edit \" %s\" " % (dest ))
622
+ p4_system ( " integrate -Dt \" %s\" \" %s\" " % (src , dest ))
623
+ p4_system ( " edit \" %s\" " % (dest ))
572
624
if isModeExecChanged (diff ['src_mode' ], diff ['dst_mode' ]):
573
625
filesToChangeExecBit [dest ] = diff ['dst_mode' ]
574
626
os .unlink (dest )
@@ -592,7 +644,7 @@ class P4Submit(Command):
592
644
if response == "s" :
593
645
print "Skipping! Good luck with the next patches..."
594
646
for f in editedFiles :
595
- system ( "p4 revert \" %s\" " % f );
647
+ p4_system ( " revert \" %s\" " % f );
596
648
for f in filesToAdd :
597
649
system ("rm %s" % f )
598
650
return
@@ -615,10 +667,10 @@ class P4Submit(Command):
615
667
system (applyPatchCmd )
616
668
617
669
for f in filesToAdd :
618
- system ( "p4 add \" %s\" " % f )
670
+ p4_system ( " add \" %s\" " % f )
619
671
for f in filesToDelete :
620
- system ( "p4 revert \" %s\" " % f )
621
- system ( "p4 delete \" %s\" " % f )
672
+ p4_system ( " revert \" %s\" " % f )
673
+ p4_system ( " delete \" %s\" " % f )
622
674
623
675
# Set/clear executable bits
624
676
for f in filesToChangeExecBit .keys ():
@@ -634,7 +686,7 @@ class P4Submit(Command):
634
686
submitTemplate = self .prepareLogMessage (template , logMessage )
635
687
if os .environ .has_key ("P4DIFF" ):
636
688
del (os .environ ["P4DIFF" ])
637
- diff = read_pipe ( "p4 diff -du ..." )
689
+ diff = p4_read_pipe ( " diff -du ..." )
638
690
639
691
newdiff = ""
640
692
for newFile in filesToAdd :
@@ -672,7 +724,7 @@ class P4Submit(Command):
672
724
if self .isWindows :
673
725
submitTemplate = submitTemplate .replace ("\r \n " , "\n " )
674
726
675
- write_pipe ( "p4 submit -i" , submitTemplate )
727
+ p4_write_pipe ( " submit -i" , submitTemplate )
676
728
else :
677
729
fileName = "submit.txt"
678
730
file = open (fileName , "w+" )
@@ -719,7 +771,7 @@ class P4Submit(Command):
719
771
720
772
chdir (self .clientPath )
721
773
print "Syncronizing p4 checkout..."
722
- system ( "p4 sync ..." )
774
+ p4_system ( " sync ..." )
723
775
724
776
self .check ()
725
777
@@ -1404,7 +1456,7 @@ class P4Sync(Command):
1404
1456
if not gitBranchExists (self .refPrefix + "HEAD" ) and self .importIntoRemotes and gitBranchExists (self .branch ):
1405
1457
system ("git symbolic-ref %sHEAD %s" % (self .refPrefix , self .branch ))
1406
1458
1407
- if self .useClientSpec or gitConfig ("p4.useclientspec" ) == "true" :
1459
+ if self .useClientSpec or gitConfig ("git- p4.useclientspec" ) == "true" :
1408
1460
self .getClientSpec ()
1409
1461
1410
1462
# TODO: should always look at previous commits,
0 commit comments