Merge branch 'ls/p4-path-encoding'
authorJunio C Hamano <gitster@pobox.com>
Wed, 7 Oct 2015 20:38:19 +0000 (13:38 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 7 Oct 2015 20:38:19 +0000 (13:38 -0700)
"git p4" learned to reencode the pathname it uses to communicate
with the p4 depot with a new option.

* ls/p4-path-encoding:
git-p4: use replacement character for non UTF-8 characters in paths
git-p4: improve path encoding verbose output
git-p4: add config git-p4.pathEncoding

1  2 
git-p4.py
diff --combined git-p4.py
index 2677c89c064d7152451798d29d69b277ede3cbad,603045050c95ca1d5fb4843203f2a811e5c3e95a..215f556c13a72cf7b0cb49ae2a651d43a0b2623b
+++ b/git-p4.py
@@@ -1950,14 -1950,10 +1950,14 @@@ class View(object)
              if "unmap" in res:
                  # it will list all of them, but only one not unmap-ped
                  continue
 +            if gitConfigBool("core.ignorecase"):
 +                res['depotFile'] = res['depotFile'].lower()
              self.client_spec_path_cache[res['depotFile']] = self.convert_client_path(res["clientFile"])
  
          # not found files or unmap files set to ""
          for depotFile in fileArgs:
 +            if gitConfigBool("core.ignorecase"):
 +                depotFile = depotFile.lower()
              if depotFile not in self.client_spec_path_cache:
                  self.client_spec_path_cache[depotFile] = ""
  
             depot file should live.  Returns "" if the file should
             not be mapped in the client."""
  
 +        if gitConfigBool("core.ignorecase"):
 +            depot_path = depot_path.lower()
 +
          if depot_path in self.client_spec_path_cache:
              return self.client_spec_path_cache[depot_path]
  
@@@ -2220,6 -2213,16 +2220,16 @@@ class P4Sync(Command, P4UserMap)
              text = regexp.sub(r'$\1$', text)
              contents = [ text ]
  
+         try:
+             relPath.decode('ascii')
+         except:
+             encoding = 'utf8'
+             if gitConfig('git-p4.pathEncoding'):
+                 encoding = gitConfig('git-p4.pathEncoding')
+             relPath = relPath.decode(encoding, 'replace').encode('utf8', 'replace')
+             if self.verbose:
+                 print 'Path with non-ASCII characters detected. Used %s to encode: %s ' % (encoding, relPath)
          self.gitStream.write("M %s inline %s\n" % (git_mode, relPath))
  
          # total length...
          else:
              return "%s <a@b>" % userid
  
 -    # Stream a p4 tag
      def streamTag(self, gitStream, labelName, labelDetails, commit, epoch):
 +        """ Stream a p4 tag.
 +        commit is either a git commit, or a fast-import mark, ":<p4commit>"
 +        """
 +
          if verbose:
              print "writing tag %s for commit %s" % (labelName, commit)
          gitStream.write("tag %s\n" % labelName)
              self.clientSpecDirs.update_client_spec_path_cache(files)
  
          self.gitStream.write("commit %s\n" % branch)
 -#        gitStream.write("mark :%s\n" % details["change"])
 +        self.gitStream.write("mark :%s\n" % details["change"])
          self.committedChanges.add(int(details["change"]))
          committer = ""
          if author not in self.users:
              if change.has_key('change'):
                  # find the corresponding git commit; take the oldest commit
                  changelist = int(change['change'])
 -                gitCommit = read_pipe(["git", "rev-list", "--max-count=1",
 -                     "--reverse", ":/\[git-p4:.*change = %d\]" % changelist])
 -                if len(gitCommit) == 0:
 -                    print "could not find git commit for changelist %d" % changelist
 -                else:
 -                    gitCommit = gitCommit.strip()
 +                if changelist in self.committedChanges:
 +                    gitCommit = ":%d" % changelist       # use a fast-import mark
                      commitFound = True
 +                else:
 +                    gitCommit = read_pipe(["git", "rev-list", "--max-count=1",
 +                        "--reverse", ":/\[git-p4:.*change = %d\]" % changelist], ignore_error=True)
 +                    if len(gitCommit) == 0:
 +                        print "importing label %s: could not find git commit for changelist %d" % (name, changelist)
 +                    else:
 +                        commitFound = True
 +                        gitCommit = gitCommit.strip()
 +
 +                if commitFound:
                      # Convert from p4 time format
                      try:
                          tmwhen = time.strptime(labelDetails['Update'], "%Y/%m/%d %H:%M:%S")