Code

Merge branch 'ld/git-p4-branches-and-labels'
authorJunio C Hamano <gitster@pobox.com>
Wed, 1 Feb 2012 06:01:14 +0000 (22:01 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Feb 2012 06:01:14 +0000 (22:01 -0800)
* ld/git-p4-branches-and-labels:
  git-p4: label import fails with multiple labels at the same changelist
  git-p4: add test for p4 labels
  git-p4: importing labels should cope with missing owner
  git-p4: cope with labels with empty descriptions
  git-p4: handle p4 branches and labels containing shell chars

1  2 
contrib/fast-import/git-p4

index e11e15bad0ca6c552ffe9093af71afebe6e4323d,bcb0e6cd234aadd83aef22eaad268aa0f3d0abfd..27e06c1e9b2844d617a14c782d2e5fa7ec8a42d5
@@@ -563,6 -563,26 +563,26 @@@ class Command
  class P4UserMap:
      def __init__(self):
          self.userMapFromPerforceServer = False
+         self.myP4UserId = None
+     def p4UserId(self):
+         if self.myP4UserId:
+             return self.myP4UserId
+         results = p4CmdList("user -o")
+         for r in results:
+             if r.has_key('User'):
+                 self.myP4UserId = r['User']
+                 return r['User']
+         die("Could not find your p4 user id")
+     def p4UserIsMe(self, p4User):
+         # return True if the given p4 user is actually me
+         me = self.p4UserId()
+         if not p4User or p4User != me:
+             return False
+         else:
+             return True
  
      def getUserCacheFilename(self):
          home = os.environ.get("HOME", os.environ.get("USERPROFILE"))
@@@ -700,7 -720,6 +720,6 @@@ class P4Submit(Command, P4UserMap)
          self.verbose = False
          self.preserveUser = gitConfig("git-p4.preserveUser").lower() == "true"
          self.isWindows = (platform.system() == "Windows")
-         self.myP4UserId = None
  
      def check(self):
          if len(p4CmdList("opened ...")) > 0:
      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("protects %s" % self.depotPath)
+         results = p4CmdList(["protects", self.depotPath])
          for r in results:
              if r.has_key('perm'):
                  if r['perm'] == 'admin':
                      return 1
          return 0
  
-     def p4UserId(self):
-         if self.myP4UserId:
-             return self.myP4UserId
-         results = p4CmdList("user -o")
-         for r in results:
-             if r.has_key('User'):
-                 self.myP4UserId = r['User']
-                 return r['User']
-         die("Could not find your p4 user id")
-     def p4UserIsMe(self, p4User):
-         # return True if the given p4 user is actually me
-         me = self.p4UserId()
-         if not p4User or p4User != me:
-             return False
-         else:
-             return True
      def prepareSubmitTemplate(self):
          # remove lines in the Files section that show changes to files outside the depot path we're committing into
          template = ""
@@@ -1207,8 -1207,8 +1207,8 @@@ class View(object)
                  die("Can't handle * wildcards in view: %s" % self.path)
              triple_dot_index = self.path.find("...")
              if triple_dot_index >= 0:
 -                if not self.path.endswith("..."):
 -                    die("Can handle ... wildcard only at end of path: %s" %
 +                if triple_dot_index != len(self.path) - 3:
 +                    die("Can handle only single ... wildcard, at end: %s" %
                          self.path)
                  self.ends_triple_dot = True
  
              if self.exclude:
                  c = "-"
              return "View.Mapping: %s%s -> %s" % \
 -                   (c, self.depot_side, self.client_side)
 +                   (c, self.depot_side.path, self.client_side.path)
  
          def map_depot_to_client(self, depot_path):
              """Calculate the client path if using this mapping on the
              else:
                  # This mapping matched; no need to search any further.
                  # But, the mapping could be rejected if the client path
 -                # has already been claimed by an earlier mapping.
 +                # has already been claimed by an earlier mapping (i.e.
 +                # one later in the list, which we are walking backwards).
                  already_mapped_in_client = False
                  for f in paths_filled:
                      # this is View.Path.match
@@@ -1665,6 -1664,12 +1665,12 @@@ class P4Sync(Command, P4UserMap)
              if self.stream_file.has_key('depotFile'):
                  self.streamOneP4File(self.stream_file, self.stream_contents)
  
+     def make_email(self, userid):
+         if userid in self.users:
+             return self.users[userid]
+         else:
+             return "%s <a@b>" % userid
      def commit(self, details, files, branch, branchPrefixes, parent = ""):
          epoch = details["time"]
          author = details["user"]
          committer = ""
          if author not in self.users:
              self.getUserMapFromPerforceServer()
-         if author in self.users:
-             committer = "%s %s %s" % (self.users[author], epoch, self.tz)
-         else:
-             committer = "%s <a@b> %s %s" % (author, epoch, self.tz)
+         committer = "%s %s %s" % (self.make_email(author), epoch, self.tz)
  
          self.gitStream.write("committer %s\n" % committer)
  
                      self.gitStream.write("from %s\n" % branch)
  
                      owner = labelDetails["Owner"]
-                     tagger = ""
-                     if author in self.users:
-                         tagger = "%s %s %s" % (self.users[owner], epoch, self.tz)
+                     # Try to use the owner of the p4 label, or failing that,
+                     # the current p4 user id.
+                     if owner:
+                         email = self.make_email(owner)
                      else:
-                         tagger = "%s <a@b> %s %s" % (owner, epoch, self.tz)
+                         email = self.make_email(self.p4UserId())
+                     tagger = "%s %s %s" % (email, epoch, self.tz)
                      self.gitStream.write("tagger %s\n" % tagger)
-                     self.gitStream.write("data <<EOT\n")
-                     self.gitStream.write(labelDetails["Description"])
-                     self.gitStream.write("EOT\n\n")
+                     description = labelDetails["Description"]
+                     self.gitStream.write("data %d\n" % len(description))
+                     self.gitStream.write(description)
+                     self.gitStream.write("\n")
  
                  else:
                      if not self.silent:
      def getLabels(self):
          self.labels = {}
  
-         l = p4CmdList("labels %s..." % ' '.join (self.depotPaths))
+         l = p4CmdList(["labels"] + ["%s..." % p for p in self.depotPaths])
          if len(l) > 0 and not self.silent:
              print "Finding files belonging to labels in %s" % `self.depotPaths`
  
              command = "branches"
  
          for info in p4CmdList(command):
-             details = p4Cmd("branch -o %s" % info["branch"])
+             details = p4Cmd(["branch", "-o", info["branch"]])
              viewIdx = 0
              while details.has_key("View%s" % viewIdx):
                  paths = details["View%s" % viewIdx].split(" ")
          sourceRef = self.gitRefForBranch(sourceBranch)
          #print "source " + sourceBranch
  
-         branchParentChange = int(p4Cmd("changes -m 1 %s...@1,%s" % (sourceDepotPath, firstChange))["change"])
+         branchParentChange = int(p4Cmd(["changes", "-m", "1", "%s...@1,%s" % (sourceDepotPath, firstChange)])["change"])
          #print "branch parent: %s" % branchParentChange
          gitParent = self.gitCommitByP4Change(sourceRef, branchParentChange)
          if len(gitParent) > 0: