git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH/RFC v2 1/2] git-p4: small improvements to user-preservation

From
Luke Diamand <luke@diamand.org>
Date
May 9, 2011, 06:40 UTC
Message-ID
<1304923203-26278-2-git-send-email-luke@diamand.org>
In-Reply-To
<1304923203-26278-1-git-send-email-luke@diamand.org>
. Slightly more paranoid checking of results from 'p4 change'
. Remove superfluous "-G"
. Don't modify the username if it is unchanged.
. Reword git-p4.txt to point out that the initial commit will
  be submitted with you as the author.
Signed-off-by: Luke Diamand <luke@diamand.org>
---
 contrib/fast-import/git-p4     |   16 +++++++++++-----
 contrib/fast-import/git-p4.txt |    9 +++++----
 2 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index 36e3d87..bd8c761 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -690,10 +690,15 @@ class P4Submit(Command, P4UserMap):
     def modifyChangelistUser(self, changelist, newUser):
         # fixup the user field of a changelist after it has been submitted.
         changes = p4CmdList("change -o %s" % changelist)
-        for c in changes:
-            if c.has_key('User'):
-                c['User'] = newUser
-        input = marshal.dumps(changes[0])
+        if len(changes) != 1:
+            die("Bad output from p4 change modifying %s to user %s" %
+                (changelist, newUser))
+
+        c = changes[0]
+        if c['User'] == newUser: return   # nothing to do
+        c['User'] = newUser
+        input = marshal.dumps(c)
+
         result = p4CmdList("change -f -i", stdin=input)
         for r in result:
             if r.has_key('code'):
@@ -707,7 +712,7 @@ class P4Submit(Command, P4UserMap):
     def canChangeChangelists(self):
         # check to see if we have p4 admin or super-user permissions, either of
         # which are required to modify changelists.
-        results = p4CmdList("-G protects %s" % self.depotPath)
+        results = p4CmdList("protects %s" % self.depotPath)
         for r in results:
             if r.has_key('perm'):
                 if r['perm'] == 'admin':
@@ -865,6 +870,7 @@ class P4Submit(Command, P4UserMap):
 
         if self.interactive:
             submitTemplate = self.prepareLogMessage(template, logMessage)
+
             if os.environ.has_key("P4DIFF"):
                 del(os.environ["P4DIFF"])
             diff = ""
diff --git a/contrib/fast-import/git-p4.txt b/contrib/fast-import/git-p4.txt
index b6986f0..d46b7a5 100644
--- a/contrib/fast-import/git-p4.txt
+++ b/contrib/fast-import/git-p4.txt
@@ -111,10 +111,11 @@ is not your current git branch you can also pass that as an argument:
 You can override the reference branch with the --origin=mysourcebranch option.
 
 The Perforce changelists will be created with the user who ran git-p4. If you
-use --preserve-user then git-p4 will attempt to create Perforce changelists
-with the Perforce user corresponding to the git commit author. You need to
-have sufficient permissions within Perforce, and the git users need to have
-Perforce accounts. Permissions can be granted using 'p4 protect'.
+use --preserve-user then git-p4 will modify the Perforce change's user field
+to match that of the git commit author after it has been submitted (the change
+will still initially be submitted with you as the author). You need to have
+sufficient permissions within Perforce, and the git users need to have Perforce
+accounts. Permissions can be granted using 'p4 protect'.
 
 If a submit fails you may have to "p4 resolve" and submit manually. You can
 continue importing the remaining changes with
-- 
1.7.1
Previous: Luke DiamandNext: Luke Diamand
Message 2 of 5 in “git-p4: user preservation improvements”
  1. 0/2 git-p4: user preservation improvementsLuke Diamand, May 9, 2011
  2. 1/2 git-p4: small improvements to user-preservationLuke Diamand, May 9, 2011
  3. 2/2 git-p4: warn if git authorship won't be retainedLuke Diamand, May 9, 2011
  4. Pete WyckoffMay 9, 2011
  5. Pete WyckoffMay 9, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.