Read the content of the file from specific commit. This method uses `git cat-files` to read the file content from git index to enable support of smudge filters (fixes Issue #74). Git applies smudge filters to some commands like `archive`, `diff`, `checkout` and `cat-
(self, commit)
| 709 | ]) |
| 710 | |
| 711 | def git_read_file(self, commit): |
| 712 | """Read the content of the file from specific commit. |
| 713 | |
| 714 | This method uses `git cat-files` to read the file content from git |
| 715 | index to enable support of smudge filters (fixes Issue #74). Git |
| 716 | applies smudge filters to some commands like `archive`, `diff`, |
| 717 | `checkout` and `cat-file` only, but not to commands like `show`. |
| 718 | |
| 719 | Arguments: |
| 720 | commit (string): The identifier of the commit to read file from. |
| 721 | |
| 722 | Returns: |
| 723 | Promise: A promise to read the content of a file from git index. |
| 724 | |
| 725 | The Promise resolves with the number of bytes written to the cache |
| 726 | in case of success. |
| 727 | |
| 728 | The Promise resolves with PromiseError if the cache file could not |
| 729 | be created, opened or written data to, if git failed to run or |
| 730 | returned a none-zero exit code other than 128 (file not found). |
| 731 | """ |
| 732 | if not self._git_temp_file: |
| 733 | self._git_temp_file = TempFile(mode='wb') |
| 734 | |
| 735 | try: |
| 736 | proc = self.popen([ |
| 737 | self._git_binary, |
| 738 | '-c', 'core.autocrlf=input', |
| 739 | '-c', 'core.eol=lf', |
| 740 | '-c', 'core.safecrlf=false', |
| 741 | 'cat-file', |
| 742 | # smudge filters are supported with git 2.11.0+ only |
| 743 | '--filters' if self._git_version >= (2, 11, 0) else '-p', |
| 744 | ':'.join((commit, self._git_path)) |
| 745 | ], stdout=self._git_temp_file.open()) |
| 746 | |
| 747 | except Exception as error: |
| 748 | self._git_temp_file.close() |
| 749 | return Promise.resolve(PromiseError(str(error))) |
| 750 | |
| 751 | def poll(proc, resolve): |
| 752 | """Poll the process and resolve promise if finished.""" |
| 753 | try: |
| 754 | returncode = proc.poll() |
| 755 | if returncode is None: |
| 756 | # git is still busy, come here later again |
| 757 | set_timeout(functools.partial(poll, proc, resolve), 50) |
| 758 | return None |
| 759 | |
| 760 | # file is still open for writing at this point |
| 761 | with self._git_temp_file as file: |
| 762 | if returncode == 0: |
| 763 | # resolve with the number of bytes got from git cat-file |
| 764 | return resolve(file.tell()) |
| 765 | elif returncode == 128: |
| 766 | # resolve with 0 bytes if file was not found in repo. |
| 767 | return resolve(0) |
| 768 | return resolve(PromiseError("git returned error %d: %s" % ( |
no test coverage detected