@@ -563,6 +563,26 @@ class Command:
563563class P4UserMap :
564564 def __init__ (self ):
565565 self .userMapFromPerforceServer = False
566+ self .myP4UserId = None
567+
568+ def p4UserId (self ):
569+ if self .myP4UserId :
570+ return self .myP4UserId
571+
572+ results = p4CmdList ("user -o" )
573+ for r in results :
574+ if r .has_key ('User' ):
575+ self .myP4UserId = r ['User' ]
576+ return r ['User' ]
577+ die ("Could not find your p4 user id" )
578+
579+ def p4UserIsMe (self , p4User ):
580+ # return True if the given p4 user is actually me
581+ me = self .p4UserId ()
582+ if not p4User or p4User != me :
583+ return False
584+ else :
585+ return True
566586
567587 def getUserCacheFilename (self ):
568588 home = os .environ .get ("HOME" , os .environ .get ("USERPROFILE" ))
@@ -700,7 +720,6 @@ class P4Submit(Command, P4UserMap):
700720 self .verbose = False
701721 self .preserveUser = gitConfig ("git-p4.preserveUser" ).lower () == "true"
702722 self .isWindows = (platform .system () == "Windows" )
703- self .myP4UserId = None
704723
705724 def check (self ):
706725 if len (p4CmdList ("opened ..." )) > 0 :
@@ -799,7 +818,7 @@ class P4Submit(Command, P4UserMap):
799818 def canChangeChangelists (self ):
800819 # check to see if we have p4 admin or super-user permissions, either of
801820 # which are required to modify changelists.
802- results = p4CmdList ("protects %s" % self .depotPath )
821+ results = p4CmdList ([ "protects" , self .depotPath ] )
803822 for r in results :
804823 if r .has_key ('perm' ):
805824 if r ['perm' ] == 'admin' :
@@ -808,25 +827,6 @@ class P4Submit(Command, P4UserMap):
808827 return 1
809828 return 0
810829
811- def p4UserId (self ):
812- if self .myP4UserId :
813- return self .myP4UserId
814-
815- results = p4CmdList ("user -o" )
816- for r in results :
817- if r .has_key ('User' ):
818- self .myP4UserId = r ['User' ]
819- return r ['User' ]
820- die ("Could not find your p4 user id" )
821-
822- def p4UserIsMe (self , p4User ):
823- # return True if the given p4 user is actually me
824- me = self .p4UserId ()
825- if not p4User or p4User != me :
826- return False
827- else :
828- return True
829-
830830 def prepareSubmitTemplate (self ):
831831 # remove lines in the Files section that show changes to files outside the depot path we're committing into
832832 template = ""
@@ -1665,6 +1665,12 @@ class P4Sync(Command, P4UserMap):
16651665 if self .stream_file .has_key ('depotFile' ):
16661666 self .streamOneP4File (self .stream_file , self .stream_contents )
16671667
1668+ def make_email (self , userid ):
1669+ if userid in self .users :
1670+ return self .users [userid ]
1671+ else :
1672+ return "%s <a@b>" % userid
1673+
16681674 def commit (self , details , files , branch , branchPrefixes , parent = "" ):
16691675 epoch = details ["time" ]
16701676 author = details ["user" ]
@@ -1688,10 +1694,7 @@ class P4Sync(Command, P4UserMap):
16881694 committer = ""
16891695 if author not in self .users :
16901696 self .getUserMapFromPerforceServer ()
1691- if author in self .users :
1692- committer = "%s %s %s" % (self .users [author ], epoch , self .tz )
1693- else :
1694- committer = "%s <a@b> %s %s" % (author , epoch , self .tz )
1697+ committer = "%s %s %s" % (self .make_email (author ), epoch , self .tz )
16951698
16961699 self .gitStream .write ("committer %s\n " % committer )
16971700
@@ -1736,15 +1739,21 @@ class P4Sync(Command, P4UserMap):
17361739 self .gitStream .write ("from %s\n " % branch )
17371740
17381741 owner = labelDetails ["Owner" ]
1739- tagger = ""
1740- if author in self .users :
1741- tagger = "%s %s %s" % (self .users [owner ], epoch , self .tz )
1742+
1743+ # Try to use the owner of the p4 label, or failing that,
1744+ # the current p4 user id.
1745+ if owner :
1746+ email = self .make_email (owner )
17421747 else :
1743- tagger = "%s <a@b> %s %s" % (owner , epoch , self .tz )
1748+ email = self .make_email (self .p4UserId ())
1749+ tagger = "%s %s %s" % (email , epoch , self .tz )
1750+
17441751 self .gitStream .write ("tagger %s\n " % tagger )
1745- self .gitStream .write ("data <<EOT\n " )
1746- self .gitStream .write (labelDetails ["Description" ])
1747- self .gitStream .write ("EOT\n \n " )
1752+
1753+ description = labelDetails ["Description" ]
1754+ self .gitStream .write ("data %d\n " % len (description ))
1755+ self .gitStream .write (description )
1756+ self .gitStream .write ("\n " )
17481757
17491758 else :
17501759 if not self .silent :
@@ -1759,7 +1768,7 @@ class P4Sync(Command, P4UserMap):
17591768 def getLabels (self ):
17601769 self .labels = {}
17611770
1762- l = p4CmdList ("labels %s..." % ' ' . join ( self .depotPaths ) )
1771+ l = p4CmdList ([ "labels" ] + [ " %s..." % p for p in self .depotPaths ] )
17631772 if len (l ) > 0 and not self .silent :
17641773 print "Finding files belonging to labels in %s" % `self.depotPaths`
17651774
@@ -1801,7 +1810,7 @@ class P4Sync(Command, P4UserMap):
18011810 command = "branches"
18021811
18031812 for info in p4CmdList (command ):
1804- details = p4Cmd ("branch -o %s" % info ["branch" ])
1813+ details = p4Cmd ([ "branch" , "-o" , info ["branch" ] ])
18051814 viewIdx = 0
18061815 while details .has_key ("View%s" % viewIdx ):
18071816 paths = details ["View%s" % viewIdx ].split (" " )
@@ -1939,7 +1948,7 @@ class P4Sync(Command, P4UserMap):
19391948 sourceRef = self .gitRefForBranch (sourceBranch )
19401949 #print "source " + sourceBranch
19411950
1942- branchParentChange = int (p4Cmd ("changes -m 1 %s...@1,%s" % (sourceDepotPath , firstChange ))["change" ])
1951+ branchParentChange = int (p4Cmd ([ "changes" , "-m" , "1" , " %s...@1,%s" % (sourceDepotPath , firstChange )] )["change" ])
19431952 #print "branch parent: %s" % branchParentChange
19441953 gitParent = self .gitCommitByP4Change (sourceRef , branchParentChange )
19451954 if len (gitParent ) > 0 :
0 commit comments