print error message when p4 print fails (eg. due to permission problems)
[gitweb.git] / contrib / fast-import / git-p4
index cc0b7013dabe75d6b354ff7de9af77fed3847d0f..35c24c93e3e0705e6861838684c42853d5322e2d 100755 (executable)
@@ -173,13 +173,18 @@ class P4Debug(Command):
     def __init__(self):
         Command.__init__(self)
         self.options = [
-            optparse.make_option("--verbose", dest="verbose", action="store_true"),
+            optparse.make_option("--verbose", dest="verbose", action="store_true",
+                                 default=False),
             ]
         self.description = "A tool to debug the output of p4 -G."
         self.needsGit = False
+        self.verbose = False
 
     def run(self, args):
+        j = 0
         for output in p4CmdList(" ".join(args)):
+            print 'Element: %d' % j
+            j += 1
             print output
         return True
 
@@ -676,24 +681,33 @@ class P4Sync(Command):
 
     ## Should move this out, doesn't use SELF.
     def readP4Files(self, files):
-        specs = [(f['path'] + "#" + f['rev'], f)  for f in files
+        files = [f for f in files
                  if f['action'] != 'delete']
 
-        if not specs:
+        if not files:
             return
 
-        filedata = p4CmdList('print %s' % ' '.join(['"%s"' % path
-                                                for (path, info) in specs]))
+        filedata = p4CmdList('print %s' % ' '.join(['"%s#%s"' % (f['path'],
+                                                                 f['rev'])
+                                                    for f in files]))
 
         j = 0;
         contents = {}
-        while filedata[j:]:
+        while j < len(filedata):
             stat = filedata[j]
-            text = filedata[j+1]
-            j += 2
+            j += 1
+            text = ''
+            while j < len(filedata) and filedata[j]['code'] in ('text',
+                                                                'binary'):
+                text += filedata[j]['data']
+                j += 1
+
+
+            if not stat.has_key('depotFile'):
+                sys.stderr.write("p4 print fails with: %s\n" % repr(stat))
+                continue
 
-            assert stat['code'] == 'stat' and text['code'] == 'text'
-            contents[stat['depotFile']] = text['data']
+            contents[stat['depotFile']] = text
 
         for f in files:
             assert not f.has_key('data')
@@ -765,7 +779,7 @@ class P4Sync(Command):
                 if self.isWindows and file["type"].endswith("text"):
                     data = data.replace("\r\n", "\n")
 
-                self.gitStream.write("M %s inline %s\n" % (mode, relPath))
+                self.gitStream.write("M %d inline %s\n" % (mode, relPath))
                 self.gitStream.write("data %s\n" % len(data))
                 self.gitStream.write(data)
                 self.gitStream.write("\n")
@@ -1031,7 +1045,6 @@ class P4Sync(Command):
 
             p4Change = 0
             for branch in self.p4BranchesInGit:
-                print self.p4BranchesInGit
                 logMsg =  extractLogMessageFromGitCommit(self.refPrefix + branch)
 
                 settings = extractSettingsGitLog(logMsg)