Skip to content

python3 support and improved tests#95

Open
Jwink3101 wants to merge 11 commits into
jedbrown:masterfrom
Jwink3101:master
Open

python3 support and improved tests#95
Jwink3101 wants to merge 11 commits into
jedbrown:masterfrom
Jwink3101:master

Conversation

@Jwink3101
Copy link
Copy Markdown

This is take II at adding python3 support. First, the test is updated to use a binary file (the downfall of the last attempt) and then git-fat is updated to handle python 3. There is also a new test runner to more carefully test python2 and 3 support by changing the shebang and bash path inside the test.

Insomuch as the tests have good coverage, everything passes in python2 and 3. I have not tested 2.6 since it was already broken. I have also not tested on Windows

Copy link
Copy Markdown
Owner

@jedbrown jedbrown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me; thanks. Just one comment. (Sorry about delayed review.)

Comment thread test-retroactive.sh Outdated
@leggewie leggewie mentioned this pull request Apr 6, 2021
MateuszKrawczuk added a commit to CybrixSystems/git-fat that referenced this pull request May 7, 2026
  Applies the strategy from upstream PR jedbrown#95: introduce
  `touni()`/`tobytes()` helpers plus `from __future__ import unicode_literals`,
  then convert bytes/str only at I/O boundaries (subprocess output,
  filter stdin/stdout, rsync stdin). The encode/decode logic itself stays
  unchanged.

  - drop the explicit Python 3 rejection guard
  - open fat object files in binary mode (rb/wb)
  - use sys.stdin.buffer / sys.stdout.buffer in clean/smudge filters
  - feed bytes to Popen.communicate() in push/pull
  - decode rev-parse, ls-files, cat-file, git config output to str
  - in cmd_index_filter, decode hash-object stdout before %-formatting
    (avoids the latent "b'...'" bug present in PR jedbrown#95)

  test.sh writes binary content to a.fat and asserts via base64 to catch
  text-mode regressions. .gitignore covers TEST_py* and fat-test*/ used
  by upstream's run_test.py.

  Verified end-to-end on Python 3.12: clean/smudge filters, push, clone,
  pull, verify (with a corrupted object), status --all, and the
  retroactive flow (find + index-filter + filter-branch).

Signed-off-by: Mateusz Krawczuk <mateusz.krawczuk@cybrixsystems.com>
MateuszKrawczuk pushed a commit to CybrixSystems/git-fat that referenced this pull request May 7, 2026
Adds Python 3 support to git-fat while remaining compatible with
Python 2.7. Introduces touni()/tobytes() helpers and unicode_literals,
then converts bytes/str only at I/O boundaries (subprocess output,
filter stdin/stdout, rsync stdin) so the encode/decode logic itself
stays unchanged.

- drop the explicit Python 3 rejection guard
- open fat object files in binary mode (rb/wb)
- use sys.stdin.buffer / sys.stdout.buffer in clean/smudge filters
- feed bytes to Popen.communicate() in push/pull
- decode rev-parse, ls-files, cat-file, git config output to str

test.sh writes binary content to a.fat and asserts via base64 to catch
text-mode regressions; .gitignore covers the new TEST_py* / fat-test*/
test directories.

Verified end-to-end on Python 3.12: clean/smudge filters, push, clone,
pull, verify (with a corrupted object), status --all, and the
retroactive flow (find + index-filter + filter-branch).

Originally posted as jedbrown#95 by Jwink3101.
Link: jedbrown#95

[mkrawczuk: skip run_test.py; wrap stdout in touni() before
 %-formatting in cmd_index_filter manage_gitattributes path to avoid
 the latent "b'...'" bug; minor message wording]

Signed-off-by: Mateusz Krawczuk <mateusz.krawczuk@cybrixsystems.com>
MateuszKrawczuk pushed a commit to CybrixSystems/git-fat that referenced this pull request May 7, 2026
Adds Python 3 support to git-fat. Originally based on Jwink3101's PR
jedbrown#95 (touni()/tobytes() helpers at I/O boundaries),
then trimmed to drop Python 2 compatibility entirely (the team has no
py2 users) and extended with the Windows binary-mode handling from
Jed Brown's jed/python3-win32-compat branch so collaborators can run
git-fat under Git for Windows without CRLF corruption of fat objects.

- drop the explicit Python 3 rejection guard
- open fat object files in binary mode (rb/wb)
- new get_binary_stdio() helper used by clean/smudge filters; on
  win32 it calls msvcrt.setmode(fd, O_BINARY) on the underlying file
  descriptors so the C runtime stops translating CRLF
- feed bytes to Popen.communicate() in push/pull
- decode rev-parse, ls-files, cat-file, git config output to str
- defensive bytes->str decode in verbose_stderr (avoids "b'/path/...'"
  in diagnostics, especially under Windows where getfilesystemencoding()
  is mbcs/cp1252 rather than utf-8)
- gen_large_blobs: numlarge counter starts at 0 (cosmetic, diagnostic)

test.sh writes binary content to a.fat and asserts via base64 to catch
text-mode regressions; .gitignore covers TEST_py* and fat-test*/.

Verified end-to-end on Python 3.12 (Linux): clean/smudge filters,
push, clone, pull, verify (with a corrupted object), status --all,
and the retroactive flow (find + index-filter + filter-branch).
Windows path is not exercised locally; the win32-only branch in
get_binary_stdio() is small and inspectable.

Originally posted as jedbrown#95 by Jwink3101.
Link: jedbrown#95
Link: https://github.com/jedbrown/git-fat/tree/jed/python3-win32-compat

[mkrawczuk: drop py2 compatibility (no __future__, no unicode alias,
 no check_output backport, no io.open import); switch shebang to
 python3; add Windows-only msvcrt.setmode binary mode in
 get_binary_stdio() (on top of Jwink3101's sys.stdin.buffer pattern,
 inspired by Jed Brown commit 3534426); add defensive bytes decoding
 in verbose_stderr (Jed commit eadb17b); fix numlarge off-by-one
 (Jed commit b700297); wrap stdout in touni() before %-formatting in
 cmd_index_filter manage_gitattributes path to avoid the latent
 "b'...'" bug in PR jedbrown#95]

Signed-off-by: Mateusz Krawczuk <mateusz.krawczuk@cybrixsystems.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants