{"action":"created","issue":{"url":"https://api.github.com/repos/git-for-windows/git/issues/49","labels_url":"https://api.github.com/repos/git-for-windows/git/issues/49/labels{/name}","comments_url":"https://api.github.com/repos/git-for-windows/git/issues/49/comments","events_url":"https://api.github.com/repos/git-for-windows/git/issues/49/events","html_url":"https://github.com/git-for-windows/git/issues/49","id":64713915,"number":49,"title":"Revisit the UTF-8 environment code","user":{"login":"dscho","id":127790,"avatar_url":"https://avatars.githubusercontent.com/u/127790?v=3","gravatar_id":"","url":"https://api.github.com/users/dscho","html_url":"https://github.com/dscho","followers_url":"https://api.github.com/users/dscho/followers","following_url":"https://api.github.com/users/dscho/following{/other_user}","gists_url":"https://api.github.com/users/dscho/gists{/gist_id}","starred_url":"https://api.github.com/users/dscho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dscho/subscriptions","organizations_url":"https://api.github.com/users/dscho/orgs","repos_url":"https://api.github.com/users/dscho/repos","events_url":"https://api.github.com/users/dscho/events{/privacy}","received_events_url":"https://api.github.com/users/dscho/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/git-for-windows/git/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/git-for-windows/git/labels/git","name":"git","color":"5319e7"}],"state":"open","locked":false,"assignee":{"login":"dscho","id":127790,"avatar_url":"https://avatars.githubusercontent.com/u/127790?v=3","gravatar_id":"","url":"https://api.github.com/users/dscho","html_url":"https://github.com/dscho","followers_url":"https://api.github.com/users/dscho/followers","following_url":"https://api.github.com/users/dscho/following{/other_user}","gists_url":"https://api.github.com/users/dscho/gists{/gist_id}","starred_url":"https://api.github.com/users/dscho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dscho/subscriptions","organizations_url":"https://api.github.com/users/dscho/orgs","repos_url":"https://api.github.com/users/dscho/repos","events_url":"https://api.github.com/users/dscho/events{/privacy}","received_events_url":"https://api.github.com/users/dscho/received_events","type":"User","site_admin":false},"milestone":null,"comments":6,"created_at":"2015-03-27T07:43:42Z","updated_at":"2015-04-09T23:13:54Z","closed_at":null,"body":"At the moment, Git for Windows' strategy is to convert the entire environment to UTF-8 wholesale at startup, and for performance reasons, keep the environment sorted so that lookups can be more efficient.\r\n\r\nAs has been found out recently the hard way, the underlying assumption that Git's own code is the exclusive user of the environment is not only fragile but incorrect: for example, cURL uses and modifies the environment as well.\r\n\r\nSo let's revisit the strategy to modify the environment. One viable option is to intercept both `getenv()` and `putenv()` in Git code to keep the *real* environment encoded in the current code page, but convert transparently from/to UTF-8 so that Git itself only sees Unicode values. This could be sped up considerably by testing whether the value in question is pure ASCII (which it will be in most cases) and skip the conversion altogether.\r\n\r\nIf necessary, the converted values could be held in a hash map, but for long-running Git processes this would require a last-recently-used eviction scheme, incurring quite a bit of complexity. So let's do that only if it turns out that the performance without this cache is not good enough.\r\n\r\nThe most important part of this ticket is to come up with a realistic benchmark. The best way in this developer's opinion would be to record all the calls to the environment conversion as well as to `getenv()` and `putenv()`, as performed by a complete test suite run, and condense those calls into a single benchmark program."},"comment":{"url":"https://api.github.com/repos/git-for-windows/git/issues/comments/91378607","html_url":"https://github.com/git-for-windows/git/issues/49#issuecomment-91378607","issue_url":"https://api.github.com/repos/git-for-windows/git/issues/49","id":91378607,"user":{"login":"kblees","id":1111200,"avatar_url":"https://avatars.githubusercontent.com/u/1111200?v=3","gravatar_id":"","url":"https://api.github.com/users/kblees","html_url":"https://github.com/kblees","followers_url":"https://api.github.com/users/kblees/followers","following_url":"https://api.github.com/users/kblees/following{/other_user}","gists_url":"https://api.github.com/users/kblees/gists{/gist_id}","starred_url":"https://api.github.com/users/kblees/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kblees/subscriptions","organizations_url":"https://api.github.com/users/kblees/orgs","repos_url":"https://api.github.com/users/kblees/repos","events_url":"https://api.github.com/users/kblees/events{/privacy}","received_events_url":"https://api.github.com/users/kblees/received_events","type":"User","site_admin":false},"created_at":"2015-04-09T23:13:54Z","updated_at":"2015-04-09T23:13:54Z","body":"> My only worry there was that allocation of the result might be an issue\r\n\r\nI'd convert on the stack (alloca()), then let strintern() decide whether it needs the value on the heap..."}}