{"thread":{"id":"61045","subject":"[PATCH] Fix git-p4 decode() missing an assignment","startedAt":"2024-03-04T08:54:19Z","lastAt":"2024-03-04T09:36:30Z","messageCount":2,"participants":["W Sero via GitGitGadget","Patrick Steinhardt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"489847","messageId":"pull.1683.git.git.1709542455728.gitgitgadget@gmail.com","threadId":"61045","inReplyTo":null,"subject":"[PATCH] Fix git-p4 decode() missing an assignment","fromName":"W Sero via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2024-03-04T08:54:15Z","receivedAt":"2024-03-04T08:54:19Z","isPatch":true,"sender":{"key":"name:W Sero","avatar":null},"body":"From: SaNeOr <sane0r@outlook.com>\n\nbugfix: When using git-p4 in the python2 environment,\nsome places decode() missing an assignment.\n\nSigned-off-by: W Sero <sane0r@outlook.com>\n---\n    Fix git-p4 decode_path() missing an assignment\n    \n    When using git-p4 in the python2 environment, some places decode( )\n    missing an assignment.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1683%2FSaNeOr%2Fmaster-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1683/SaNeOr/master-v1\nPull-Request: https://github.com/git/git/pull/1683\n\n git-p4.py | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/git-p4.py b/git-p4.py\nindex 28ab12c72b6..9fa4b9b104e 100755\n--- a/git-p4.py\n+++ b/git-p4.py\n@@ -307,7 +307,7 @@ def decode_path(path):\n         return path.decode(encoding, errors='replace') if isinstance(path, bytes) else path\n     else:\n         try:\n-            path.decode('ascii')\n+            path = path.decode('ascii')\n         except:\n             path = path.decode(encoding, errors='replace')\n             if verbose:\n@@ -3114,7 +3114,7 @@ def writeToGitStream(self, gitMode, relPath, contents):\n \n     def encodeWithUTF8(self, path):\n         try:\n-            path.decode('ascii')\n+            path = path.decode('ascii')\n         except:\n             encoding = 'utf8'\n             if gitConfig('git-p4.pathEncoding'):\n\nbase-commit: 0f9d4d28b7e6021b7e6db192b7bf47bd3a0d0d1d\n-- \ngitgitgadget\n"},{"id":"489854","messageId":"ZeWWGrbskLJHrQZL@tanuki","threadId":"61045","inReplyTo":"pull.1683.git.git.1709542455728.gitgitgadget@gmail.com","subject":"Re: [PATCH] Fix git-p4 decode() missing an assignment","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-03-04T09:36:26Z","receivedAt":"2024-03-04T09:36:30Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Mon, Mar 04, 2024 at 08:54:15AM +0000, W Sero via GitGitGadget wrote:\n> From: SaNeOr <sane0r@outlook.com>\n> \n> bugfix: When using git-p4 in the python2 environment,\n> some places decode() missing an assignment.\n> \n> Signed-off-by: W Sero <sane0r@outlook.com>\n> ---\n>     Fix git-p4 decode_path() missing an assignment\n>     \n>     When using git-p4 in the python2 environment, some places decode( )\n>     missing an assignment.\n> \n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1683%2FSaNeOr%2Fmaster-v1\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1683/SaNeOr/master-v1\n> Pull-Request: https://github.com/git/git/pull/1683\n> \n>  git-p4.py | 4 ++--\n>  1 file changed, 2 insertions(+), 2 deletions(-)\n> \n> diff --git a/git-p4.py b/git-p4.py\n> index 28ab12c72b6..9fa4b9b104e 100755\n> --- a/git-p4.py\n> +++ b/git-p4.py\n> @@ -307,7 +307,7 @@ def decode_path(path):\n>          return path.decode(encoding, errors='replace') if isinstance(path, bytes) else path\n>      else:\n>          try:\n> -            path.decode('ascii')\n> +            path = path.decode('ascii')\n\nIs this fixing an actual bug that you have encountered? I'm mostly\nasking because I think this actually works as inteded: we only try to\ndecode the path using the specified encoding in case where it is not\nrepresentable as ASCII. If it contained e.g. Unicode characters, then\nthis statement here would throw and we end up decoding in the `except`\nbranch. Otherwise, we know that the path only contains ASCII characters\nand thus we don't have to change it in the first place.\n\nWhether that complexity is sensible might be a different question. But\nit at least shouldn't result in any user visible bug, no?\n\nPatrick\n\n>          except:\n>              path = path.decode(encoding, errors='replace')\n>              if verbose:\n> @@ -3114,7 +3114,7 @@ def writeToGitStream(self, gitMode, relPath, contents):\n>  \n>      def encodeWithUTF8(self, path):\n>          try:\n> -            path.decode('ascii')\n> +            path = path.decode('ascii')\n>          except:\n>              encoding = 'utf8'\n>              if gitConfig('git-p4.pathEncoding'):\n> \n> base-commit: 0f9d4d28b7e6021b7e6db192b7bf47bd3a0d0d1d\n> -- \n> gitgitgadget\n> \n"}]}