Output one file from the P4 stream. This is a helper for streamP4Files().
(self, file, contents)
| 3125 | return path |
| 3126 | |
| 3127 | def streamOneP4File(self, file, contents): |
| 3128 | """Output one file from the P4 stream. |
| 3129 | |
| 3130 | This is a helper for streamP4Files(). |
| 3131 | """ |
| 3132 | |
| 3133 | file_path = file['depotFile'] |
| 3134 | relPath = self.stripRepoPath(decode_path(file_path), self.branchPrefixes) |
| 3135 | |
| 3136 | if verbose: |
| 3137 | if 'fileSize' in self.stream_file: |
| 3138 | size = int(self.stream_file['fileSize']) |
| 3139 | else: |
| 3140 | # Deleted files don't get a fileSize apparently |
| 3141 | size = 0 |
| 3142 | sys.stdout.write('\r%s --> %s (%s)\n' % ( |
| 3143 | file_path, relPath, format_size_human_readable(size))) |
| 3144 | sys.stdout.flush() |
| 3145 | |
| 3146 | type_base, type_mods = split_p4_type(file["type"]) |
| 3147 | |
| 3148 | git_mode = "100644" |
| 3149 | if "x" in type_mods: |
| 3150 | git_mode = "100755" |
| 3151 | if type_base == "symlink": |
| 3152 | git_mode = "120000" |
| 3153 | # p4 print on a symlink sometimes contains "target\n"; |
| 3154 | # if it does, remove the newline |
| 3155 | data = ''.join(decode_text_stream(c) for c in contents) |
| 3156 | if not data: |
| 3157 | # Some version of p4 allowed creating a symlink that pointed |
| 3158 | # to nothing. This causes p4 errors when checking out such |
| 3159 | # a change, and errors here too. Work around it by ignoring |
| 3160 | # the bad symlink; hopefully a future change fixes it. |
| 3161 | print("\nIgnoring empty symlink in %s" % file_path) |
| 3162 | return |
| 3163 | elif data[-1] == '\n': |
| 3164 | contents = [data[:-1]] |
| 3165 | else: |
| 3166 | contents = [data] |
| 3167 | |
| 3168 | if type_base == "utf16": |
| 3169 | # p4 delivers different text in the python output to -G |
| 3170 | # than it does when using "print -o", or normal p4 client |
| 3171 | # operations. utf16 is converted to ascii or utf8, perhaps. |
| 3172 | # But ascii text saved as -t utf16 is completely mangled. |
| 3173 | # Invoke print -o to get the real contents. |
| 3174 | # |
| 3175 | # On windows, the newlines will always be mangled by print, so put |
| 3176 | # them back too. This is not needed to the cygwin windows version, |
| 3177 | # just the native "NT" type. |
| 3178 | # |
| 3179 | try: |
| 3180 | text = p4_read_pipe(['print', '-q', '-o', '-', '%s@%s' % (decode_path(file['depotFile']), file['change'])], raw=True) |
| 3181 | except Exception as e: |
| 3182 | if 'Translation of file content failed' in str(e): |
| 3183 | type_base = 'binary' |
| 3184 | else: |
no test coverage detected