@@ -563,6 +563,26 @@ class Command:
563
563
class P4UserMap :
564
564
def __init__ (self ):
565
565
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
566
586
567
587
def getUserCacheFilename (self ):
568
588
home = os .environ .get ("HOME" , os .environ .get ("USERPROFILE" ))
@@ -700,7 +720,6 @@ class P4Submit(Command, P4UserMap):
700
720
self .verbose = False
701
721
self .preserveUser = gitConfig ("git-p4.preserveUser" ).lower () == "true"
702
722
self .isWindows = (platform .system () == "Windows" )
703
- self .myP4UserId = None
704
723
705
724
def check (self ):
706
725
if len (p4CmdList ("opened ..." )) > 0 :
@@ -808,25 +827,6 @@ class P4Submit(Command, P4UserMap):
808
827
return 1
809
828
return 0
810
829
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
-
830
830
def prepareSubmitTemplate (self ):
831
831
# remove lines in the Files section that show changes to files outside the depot path we're committing into
832
832
template = ""
@@ -1664,6 +1664,12 @@ class P4Sync(Command, P4UserMap):
1664
1664
if self .stream_file .has_key ('depotFile' ):
1665
1665
self .streamOneP4File (self .stream_file , self .stream_contents )
1666
1666
1667
+ def make_email (self , userid ):
1668
+ if userid in self .users :
1669
+ return self .users [userid ]
1670
+ else :
1671
+ return "%s <a@b>" % userid
1672
+
1667
1673
def commit (self , details , files , branch , branchPrefixes , parent = "" ):
1668
1674
epoch = details ["time" ]
1669
1675
author = details ["user" ]
@@ -1687,10 +1693,7 @@ class P4Sync(Command, P4UserMap):
1687
1693
committer = ""
1688
1694
if author not in self .users :
1689
1695
self .getUserMapFromPerforceServer ()
1690
- if author in self .users :
1691
- committer = "%s %s %s" % (self .users [author ], epoch , self .tz )
1692
- else :
1693
- committer = "%s <a@b> %s %s" % (author , epoch , self .tz )
1696
+ committer = "%s %s %s" % (self .make_email (author ), epoch , self .tz )
1694
1697
1695
1698
self .gitStream .write ("committer %s\n " % committer )
1696
1699
@@ -1735,11 +1738,15 @@ class P4Sync(Command, P4UserMap):
1735
1738
self .gitStream .write ("from %s\n " % branch )
1736
1739
1737
1740
owner = labelDetails ["Owner" ]
1738
- tagger = ""
1739
- if author in self .users :
1740
- tagger = "%s %s %s" % (self .users [owner ], epoch , self .tz )
1741
+
1742
+ # Try to use the owner of the p4 label, or failing that,
1743
+ # the current p4 user id.
1744
+ if owner :
1745
+ email = self .make_email (owner )
1741
1746
else :
1742
- tagger = "%s <a@b> %s %s" % (owner , epoch , self .tz )
1747
+ email = self .make_email (self .p4UserId ())
1748
+ tagger = "%s %s %s" % (email , epoch , self .tz )
1749
+
1743
1750
self .gitStream .write ("tagger %s\n " % tagger )
1744
1751
1745
1752
description = labelDetails ["Description" ]
0 commit comments