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

Re: Feature: Use $HOME instead of /home/username in ~/.gitconfig

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 23, 2023, 17:21 UTC
Message-ID
<xmqqh6qyayci.fsf@gitster.g>
In-Reply-To
<OSZP286MB1968CC1BD59489496919D16B8F23A@OSZP286MB1968.JPNP286.PROD.OUTLOOK.COM>
Jovial Joe Jayarson <jovial7joe@hotmail.com> writes:
Show 7 quoted lines
> I'm sharing my `.dotfiles` across systems, so I'd prefer
> `/home/username` be replaced with `$HOME` or even with `~/`.
>
> ```ini
> [maintenance]
>     repo = $HOME/.znap/repos/asdf
> ```

It probably is closer to our norm to use ~/ or ~username/ in our configuration files. $VAR syntax is unlikely to fly, as it will imply allowing arbitrary environment variables, whose security implications we would rather not have to worry about.

On the execution side, builtin/for-each-repo.c:run_command_on_repo() already knows to call interpolate_path() on the supplied pathname, which comes from the configuration variable (internally) specified, which is "maintenance.repo", so setting the variable to "~jjj/path" should already make it work, I would imagine (note: I am not a user of the feature).

The registration side is messier, though.

The path to your current repository is discovered, and then it gets canonicalized by going through strbuf_realpath(). This happens all inside builtin/gc.c:get_maintpath() and it is why the configuration variables store the absolute names. It also makes duplicate detection simpler to store the absolute names (otherwise, you'd need to compare each existing key after canonicalizing it with canonicalized new candidate repository, in order to avoid duplicates).

Turning "~jjj/hello.git" into "/home/jjj/hello.git" (or further into "/mnt/home3/jjj/hello.git", if "/home/jjj" is a symbolic link to "/mnt/home3/jjj") is easy, but there is no standard way to reverse it from "/mnt/home3/jjj/hello.git", which would be what get_maintpath() would be seeing.

If (and I do not know how) you manage to find a way for get_maintpath() to turn "/mnt/home3/jjj/hello.git" into "~jjj/hello.git", then there are a few changes needed:

 * builtin/gc.c:maintenance_register() has a loop to avoid
   duplicates; before entering the loop, pass "maintpath" to
   interpolate_path() and then strbuf_realpath() to canonicalize it
   (and call it $canon_maintpath).  In the loop, run the same
   canonicalization for each existing path (in item->string), and
   compare it with $canon_maintpath, to detect duplicates.  If the
   repository is not currently registered, use "maintpath" (not
   $canon_maintpath) to register.
 * builtin/gc.c:maintenance_unregister() has as loop to see if the
   "maintpath" exists, and then remove all associated values.  This
   will have to be modified heavily, to account for the directory
   aliases you are now introducing.  When get_maintpath() says that
   you are in "~jjj/hello.git" and unregistering the repository, you
   would need to catch all "maintenance.repo" configuration whose
   values are one of "~jjj/hello.git", "/home/jjj/hello.git", or
   "/mnt/home3/jjj/hello.git".
Previous: Jovial Joe Jayarson
Message 2 of 2 in “Feature: Use $HOME instead of /home/username in ~/.gitconfig”
  1. Jovial Joe JayarsonJun 23, 2023
  2. Junio C HamanoJun 23, 2023

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.