{"thread":{"id":"59901","subject":"Feature: Use $HOME instead of /home/username in ~/.gitconfig","startedAt":"2023-06-23T08:23:32Z","lastAt":"2023-06-23T17:23:21Z","messageCount":2,"participants":["Jovial Joe Jayarson","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"478723","messageId":"OSZP286MB1968CC1BD59489496919D16B8F23A@OSZP286MB1968.JPNP286.PROD.OUTLOOK.COM","threadId":"59901","inReplyTo":null,"subject":"Feature: Use $HOME instead of /home/username in ~/.gitconfig","fromName":"Jovial Joe Jayarson","fromEmail":"jovial7joe@hotmail.com","sentAt":"2023-06-23T08:22:39Z","receivedAt":"2023-06-23T08:23:32Z","isPatch":false,"sender":{"key":"jovial7joe@hotmail.com","avatar":null},"body":"Hi,\n\nCurrently the `[maintenance]` section of `~/.gitconfig` has something\nlike:\n\n```ini\n[maintenance]\n    repo = /home/username/.znap/repos/asdf\n```\n\nI'm sharing my `.dotfiles` across systems, so I'd prefer\n`/home/username` be replaced with `$HOME` or even with `~/`.\n\n```ini\n[maintenance]\n    repo = $HOME/.znap/repos/asdf\n```\n\nI'd be happy to make a patch, if somebody let me know where, in this\nhuge repository: https://github.com/git/git\n\nThanks,\nJoe\n"},{"id":"478736","messageId":"xmqqh6qyayci.fsf@gitster.g","threadId":"59901","inReplyTo":"OSZP286MB1968CC1BD59489496919D16B8F23A@OSZP286MB1968.JPNP286.PROD.OUTLOOK.COM","subject":"Re: Feature: Use $HOME instead of /home/username in ~/.gitconfig","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-06-23T17:21:33Z","receivedAt":"2023-06-23T17:23:21Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jovial Joe Jayarson <jovial7joe@hotmail.com> writes:\n\n> I'm sharing my `.dotfiles` across systems, so I'd prefer\n> `/home/username` be replaced with `$HOME` or even with `~/`.\n>\n> ```ini\n> [maintenance]\n>     repo = $HOME/.znap/repos/asdf\n> ```\n\nIt probably is closer to our norm to use ~/ or ~username/ in our\nconfiguration files.  $VAR syntax is unlikely to fly, as it will\nimply allowing arbitrary environment variables, whose security\nimplications we would rather not have to worry about.\n\nOn the execution side, builtin/for-each-repo.c:run_command_on_repo()\nalready knows to call interpolate_path() on the supplied pathname,\nwhich comes from the configuration variable (internally) specified,\nwhich is \"maintenance.repo\", so setting the variable to \"~jjj/path\"\nshould already make it work, I would imagine (note: I am not a user\nof the feature).\n\nThe registration side is messier, though.\n\nThe path to your current repository is discovered, and then it gets\ncanonicalized by going through strbuf_realpath().  This happens all\ninside builtin/gc.c:get_maintpath() and it is why the configuration\nvariables store the absolute names.  It also makes duplicate detection\nsimpler to store the absolute names (otherwise, you'd need to compare\neach existing key after canonicalizing it with canonicalized new\ncandidate repository, in order to avoid duplicates).\n\nTurning \"~jjj/hello.git\" into \"/home/jjj/hello.git\" (or further into\n\"/mnt/home3/jjj/hello.git\", if \"/home/jjj\" is a symbolic link to\n\"/mnt/home3/jjj\") is easy, but there is no standard way to reverse\nit from \"/mnt/home3/jjj/hello.git\", which would be what get_maintpath()\nwould be seeing.\n\nIf (and I do not know how) you manage to find a way for get_maintpath()\nto turn \"/mnt/home3/jjj/hello.git\" into \"~jjj/hello.git\", then there\nare a few changes needed:\n\n * builtin/gc.c:maintenance_register() has a loop to avoid\n   duplicates; before entering the loop, pass \"maintpath\" to\n   interpolate_path() and then strbuf_realpath() to canonicalize it\n   (and call it $canon_maintpath).  In the loop, run the same\n   canonicalization for each existing path (in item->string), and\n   compare it with $canon_maintpath, to detect duplicates.  If the\n   repository is not currently registered, use \"maintpath\" (not\n   $canon_maintpath) to register.\n\n * builtin/gc.c:maintenance_unregister() has as loop to see if the\n   \"maintpath\" exists, and then remove all associated values.  This\n   will have to be modified heavily, to account for the directory\n   aliases you are now introducing.  When get_maintpath() says that\n   you are in \"~jjj/hello.git\" and unregistering the repository, you\n   would need to catch all \"maintenance.repo\" configuration whose\n   values are one of \"~jjj/hello.git\", \"/home/jjj/hello.git\", or\n   \"/mnt/home3/jjj/hello.git\".\n\n\n"}]}