git-p4: small improvements to user-preservation
. Slightly more paranoid checking of results from 'p4 change' . Remove superfluous "-G" . Don't modify the username if it is unchanged. . Add a comment in the change template to show what is going to be done. Signed-off-by: Luke Diamand <luke@diamand.org> Acked-By: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Luke Diamand committed
May 7, 2011 at 11:19 UTC
ecdba36da6143bc00ade66b655bcff910f3e93b3
1 file changed
+14
-5
contrib/fast-import/git-p4
+14
-5
@@ -690,10 +690,15 @@ class P4Submit(Command, P4UserMap):
690
def modifyChangelistUser(self, changelist, newUser):
691
# fixup the user field of a changelist after it has been submitted.
692
changes = p4CmdList("change -o %s" % changelist)
693
- for c in changes:
694
- if c.has_key('User'):
695
- c['User'] = newUser
696
- input = marshal.dumps(changes[0])
693
+ if len(changes) != 1:
694
+ die("Bad output from p4 change modifying %s to user %s" %
695
+ (changelist, newUser))
696
+
697
+ c = changes[0]
698
+ if c['User'] == newUser: return # nothing to do
699
+ c['User'] = newUser
700
+ input = marshal.dumps(c)
701
+
702
result = p4CmdList("change -f -i", stdin=input)
703
for r in result:
704
if r.has_key('code'):
@@ -707,7 +712,7 @@ class P4Submit(Command, P4UserMap):
712
def canChangeChangelists(self):
713
# check to see if we have p4 admin or super-user permissions, either of
714
# which are required to modify changelists.
710
- results = p4CmdList("-G protects %s" % self.depotPath)
715
+ results = p4CmdList("protects %s" % self.depotPath)
716
for r in results:
717
if r.has_key('perm'):
718
if r['perm'] == 'admin':
@@ -865,6 +870,10 @@ class P4Submit(Command, P4UserMap):
870
871
if self.interactive:
872
submitTemplate = self.prepareLogMessage(template, logMessage)
873
+
874
+ if self.preserveUser:
875
+ submitTemplate = submitTemplate + ("\n######## Actual user %s, modified after commit\n" % p4User)
876
+
877
if os.environ.has_key("P4DIFF"):
878
del(os.environ["P4DIFF"])
879
diff = ""