From: Junio C Hamano <gitster@pobox.com>
To: Jovial Joe Jayarson <jovial7joe@hotmail.com>,
Derrick Stolee <derrickstolee@github.com>
Cc: git@vger.kernel.org, majordomo@vger.kernel.org
Subject: Re: Feature: Use $HOME instead of /home/username in ~/.gitconfig
Date: Fri, 23 Jun 2023 10:21:33 -0700 [thread overview]
Message-ID: <xmqqh6qyayci.fsf@gitster.g> (raw)
In-Reply-To: <OSZP286MB1968CC1BD59489496919D16B8F23A@OSZP286MB1968.JPNP286.PROD.OUTLOOK.COM> (Jovial Joe Jayarson's message of "Fri, 23 Jun 2023 13:52:39 +0530")
Jovial Joe Jayarson <jovial7joe@hotmail.com> writes:
> 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".
prev parent reply other threads:[~2023-06-23 17:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-23 8:22 Feature: Use $HOME instead of /home/username in ~/.gitconfig Jovial Joe Jayarson
2023-06-23 17:21 ` Junio C Hamano [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqh6qyayci.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=derrickstolee@github.com \
--cc=git@vger.kernel.org \
--cc=jovial7joe@hotmail.com \
--cc=majordomo@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).