git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 6/8] git-remote-testpy: hash bytes explicitly

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 17, 2013, 20:36 UTC
Message-ID
<7vtxqftulq.fsf@alter.siamese.dyndns.org>
In-Reply-To
<66c42ff65eddde494f40d0a582e89a081b4ab8e8.1358448207.git.john@keeping.me.uk>
John Keeping <john@keeping.me.uk> writes:
Show 8 quoted lines
> Under Python 3 'hasher.update(...)' must take a byte string and not a
> unicode string.  Explicitly encode the argument to this method as UTF-8
> so that this code works under Python 3.
>
> This moves the required Python version forward to 2.0.
>
> Signed-off-by: John Keeping <john@keeping.me.uk>
> ---
Hmph.  So what happens when the path is _not_ encoded in UTF-8?

Is the repo.hash (and local.hash that gets a copy of it) something that needs to stay the same across multiple invocations of this remote helper, and between the currently shipped Git and the version of Git after applying this patch? If that is not the case, and if this is used only to get a randomly-looking 40-byte hexadecimal string, then a lossy attempt to .encode('utf-8') and falling back to replace or ignore bytes in the original that couldn't be interpreted as part of a UTF-8 string would be OK, but doesn't .encode('utf-8') throw an exception if not told to 'ignore' or something?

Show 29 quoted lines
>  git-remote-testpy.py | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/git-remote-testpy.py b/git-remote-testpy.py
> index d94a66a..f8dc196 100644
> --- a/git-remote-testpy.py
> +++ b/git-remote-testpy.py
> @@ -31,9 +31,9 @@ from git_remote_helpers.git.exporter import GitExporter
>  from git_remote_helpers.git.importer import GitImporter
>  from git_remote_helpers.git.non_local import NonLocalGit
>  
> -if sys.hexversion < 0x01050200:
> -    # os.makedirs() is the limiter
> -    sys.stderr.write("git-remote-testgit: requires Python 1.5.2 or later.\n")
> +if sys.hexversion < 0x02000000:
> +    # string.encode() is the limiter
> +    sys.stderr.write("git-remote-testgit: requires Python 2.0 or later.\n")
>      sys.exit(1)
>  
>  def get_repo(alias, url):
> @@ -45,7 +45,7 @@ def get_repo(alias, url):
>      repo.get_head()
>  
>      hasher = _digest()
> -    hasher.update(repo.path)
> +    hasher.update(repo.path.encode('utf-8'))
>      repo.hash = hasher.hexdigest()
>  
>      repo.get_base_path = lambda base: os.path.join(
Previous: John KeepingNext: Junio C Hamano
Message 43 of 53 in “Initial support for Python 3”
  1. 0/8 Initial support for Python 3John Keeping, Jan 12, 2013
  2. 1/8 git_remote_helpers: Allow building with Python 3John Keeping, Jan 12, 2013
  3. 2/8 git_remote_helpers: fix input when running under Python 3John Keeping, Jan 12, 2013
  4. Michael HaggertyJan 13, 2013
  5. John KeepingJan 13, 2013
  6. Michael HaggertyJan 14, 2013
  7. John KeepingJan 14, 2013
  8. 2/8 git_remote_helpers: fix input when running under Python 3John Keeping, Jan 15, 2013
  9. Junio C HamanoJan 15, 2013
  10. John KeepingJan 15, 2013
  11. Junio C HamanoJan 15, 2013
  12. 2/8 git_remote_helpers: fix input when running under Python 3John Keeping, Jan 15, 2013
  13. Pete WyckoffJan 16, 2013
  14. John KeepingJan 16, 2013
  15. Pete WyckoffJan 17, 2013
  16. 3/8 git_remote_helpers: Force rebuild if python version changesJohn Keeping, Jan 12, 2013
  17. Pete WyckoffJan 12, 2013
  18. John KeepingJan 13, 2013
  19. Pete WyckoffJan 13, 2013
  20. John KeepingJan 13, 2013
  21. John KeepingJan 15, 2013
  22. Pete WyckoffJan 17, 2013
  23. 4/8 git_remote_helpers: Use 2to3 if building with Python 3John Keeping, Jan 12, 2013
  24. 5/8 svn-fe: allow svnrdump_sim.py to run with Python 3John Keeping, Jan 12, 2013
  25. 6/8 git-remote-testpy: hash bytes explicitlyJohn Keeping, Jan 12, 2013
  26. 7/8 git-remote-testpy: don't do unbuffered text I/OJohn Keeping, Jan 12, 2013
  27. 8/8 git-remote-testpy: call print as a functionJohn Keeping, Jan 12, 2013
  28. Pete WyckoffJan 12, 2013
  29. John KeepingJan 13, 2013
  30. John KeepingJan 13, 2013
  31. Pete WyckoffJan 13, 2013
  32. John KeepingJan 13, 2013
  33. 0/8 Initial Python 3 supportJohn Keeping, Jan 17, 2013
  34. 1/8 git_remote_helpers: allow building with Python 3John Keeping, Jan 17, 2013
  35. 2/8 git_remote_helpers: fix input when running under Python 3John Keeping, Jan 17, 2013
  36. 3/8 git_remote_helpers: force rebuild if python version changesJohn Keeping, Jan 17, 2013
  37. 4/8 git_remote_helpers: use 2to3 if building with Python 3John Keeping, Jan 17, 2013
  38. Sverre RabbelierJan 18, 2013
  39. John KeepingJan 18, 2013
  40. Sverre RabbelierJan 19, 2013
  41. 5/8 svn-fe: allow svnrdump_sim.py to run with Python 3John Keeping, Jan 17, 2013
  42. 6/8 git-remote-testpy: hash bytes explicitlyJohn Keeping, Jan 17, 2013
  43. Junio C HamanoJan 17, 2013
  44. Junio C HamanoJan 17, 2013
  45. John KeepingJan 17, 2013
  46. John KeepingJan 17, 2013
  47. Junio C HamanoJan 17, 2013
  48. John KeepingJan 17, 2013
  49. Junio C HamanoJan 17, 2013
  50. 7/8 git-remote-testpy: don't do unbuffered text I/OJohn Keeping, Jan 17, 2013
  51. Sverre RabbelierJan 18, 2013
  52. 8/8 git-remote-testpy: call print as a functionJohn Keeping, Jan 17, 2013
  53. Sverre RabbelierJan 18, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.