@@ -16,6 +16,41 @@ from sets import Set;
1616
1717verbose = False
1818
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+
1954def chdir (dir ):
2055 if os .name == 'nt' :
2156 os .environ ['PWD' ]= dir
@@ -39,6 +74,10 @@ def write_pipe(c, str):
3974
4075 return val
4176
77+ def p4_write_pipe (c , str ):
78+ real_cmd = p4_build_cmd (c )
79+ return write_pipe (c , str )
80+
4281def read_pipe (c , ignore_error = False ):
4382 if verbose :
4483 sys .stderr .write ('Reading pipe: %s\n ' % c )
@@ -50,6 +89,9 @@ def read_pipe(c, ignore_error=False):
5089
5190 return val
5291
92+ def p4_read_pipe (c , ignore_error = False ):
93+ real_cmd = p4_build_cmd (c )
94+ return read_pipe (real_cmd , ignore_error )
5395
5496def read_pipe_lines (c ):
5597 if verbose :
@@ -62,12 +104,22 @@ def read_pipe_lines(c):
62104
63105 return val
64106
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+
65112def system (cmd ):
66113 if verbose :
67114 sys .stderr .write ("executing %s\n " % cmd )
68115 if os .system (cmd ) != 0 :
69116 die ("command failed: %s" % cmd )
70117
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+
71123def isP4Exec (kind ):
72124 """Determine if a Perforce 'kind' should have execute permission
73125
@@ -89,12 +141,12 @@ def setP4ExecBit(file, mode):
89141 if p4Type [- 1 ] == "+" :
90142 p4Type = p4Type [0 :- 1 ]
91143
92- system ( "p4 reopen -t %s %s" % (p4Type , file ))
144+ p4_system ( " reopen -t %s %s" % (p4Type , file ))
93145
94146def getP4OpenedType (file ):
95147 # Returns the perforce file type for the given file.
96148
97- result = read_pipe ( "p4 opened %s" % file )
149+ result = p4_read_pipe ( " opened %s" % file )
98150 match = re .match (".*\((.+)\)\r ?$" , result )
99151 if match :
100152 return match .group (1 )
@@ -150,7 +202,7 @@ def isModeExecChanged(src_mode, dst_mode):
150202 return isModeExec (src_mode ) != isModeExec (dst_mode )
151203
152204def p4CmdList (cmd , stdin = None , stdin_mode = 'w+b' ):
153- cmd = "p4 -G %s" % cmd
205+ cmd = p4_build_cmd ( " -G %s" % ( cmd ))
154206 if verbose :
155207 sys .stderr .write ("Opening pipe: %s\n " % cmd )
156208
@@ -369,7 +421,7 @@ def originP4BranchesExist():
369421
370422def p4ChangesForPaths (depotPaths , changeRange ):
371423 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 )
373425 for p in depotPaths ]))
374426
375427 changes = []
@@ -517,7 +569,7 @@ class P4Submit(Command):
517569 # remove lines in the Files section that show changes to files outside the depot path we're committing into
518570 template = ""
519571 inFilesSection = False
520- for line in read_pipe_lines ( "p4 change -o" ):
572+ for line in p4_read_pipe_lines ( " change -o" ):
521573 if line .endswith ("\r \n " ):
522574 line = line [:- 2 ] + "\n "
523575 if inFilesSection :
@@ -552,7 +604,7 @@ class P4Submit(Command):
552604 modifier = diff ['status' ]
553605 path = diff ['src' ]
554606 if modifier == "M" :
555- system ( "p4 edit \" %s\" " % path )
607+ p4_system ( " edit \" %s\" " % path )
556608 if isModeExecChanged (diff ['src_mode' ], diff ['dst_mode' ]):
557609 filesToChangeExecBit [path ] = diff ['dst_mode' ]
558610 editedFiles .add (path )
@@ -567,8 +619,8 @@ class P4Submit(Command):
567619 filesToAdd .remove (path )
568620 elif modifier == "R" :
569621 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 ))
572624 if isModeExecChanged (diff ['src_mode' ], diff ['dst_mode' ]):
573625 filesToChangeExecBit [dest ] = diff ['dst_mode' ]
574626 os .unlink (dest )
@@ -592,7 +644,7 @@ class P4Submit(Command):
592644 if response == "s" :
593645 print "Skipping! Good luck with the next patches..."
594646 for f in editedFiles :
595- system ( "p4 revert \" %s\" " % f );
647+ p4_system ( " revert \" %s\" " % f );
596648 for f in filesToAdd :
597649 system ("rm %s" % f )
598650 return
@@ -615,10 +667,10 @@ class P4Submit(Command):
615667 system (applyPatchCmd )
616668
617669 for f in filesToAdd :
618- system ( "p4 add \" %s\" " % f )
670+ p4_system ( " add \" %s\" " % f )
619671 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 )
622674
623675 # Set/clear executable bits
624676 for f in filesToChangeExecBit .keys ():
@@ -634,7 +686,7 @@ class P4Submit(Command):
634686 submitTemplate = self .prepareLogMessage (template , logMessage )
635687 if os .environ .has_key ("P4DIFF" ):
636688 del (os .environ ["P4DIFF" ])
637- diff = read_pipe ( "p4 diff -du ..." )
689+ diff = p4_read_pipe ( " diff -du ..." )
638690
639691 newdiff = ""
640692 for newFile in filesToAdd :
@@ -672,7 +724,7 @@ class P4Submit(Command):
672724 if self .isWindows :
673725 submitTemplate = submitTemplate .replace ("\r \n " , "\n " )
674726
675- write_pipe ( "p4 submit -i" , submitTemplate )
727+ p4_write_pipe ( " submit -i" , submitTemplate )
676728 else :
677729 fileName = "submit.txt"
678730 file = open (fileName , "w+" )
@@ -719,7 +771,7 @@ class P4Submit(Command):
719771
720772 chdir (self .clientPath )
721773 print "Syncronizing p4 checkout..."
722- system ( "p4 sync ..." )
774+ p4_system ( " sync ..." )
723775
724776 self .check ()
725777
@@ -1404,7 +1456,7 @@ class P4Sync(Command):
14041456 if not gitBranchExists (self .refPrefix + "HEAD" ) and self .importIntoRemotes and gitBranchExists (self .branch ):
14051457 system ("git symbolic-ref %sHEAD %s" % (self .refPrefix , self .branch ))
14061458
1407- if self .useClientSpec or gitConfig ("p4.useclientspec" ) == "true" :
1459+ if self .useClientSpec or gitConfig ("git- p4.useclientspec" ) == "true" :
14081460 self .getClientSpec ()
14091461
14101462 # TODO: should always look at previous commits,
0 commit comments