Re: [PATCH v4] Expand ~ and ~user in core.excludesfile, commit.template
- From
Jeff King <peff@peff.net>
- Date
- Aug 30, 2008, 06:02 UTC
- Message-ID
- <20080830060159.GA6826@coredump.intra.peff.net>
- In-Reply-To
- <quack.20080829T0229.lthhc94rwyr_-_@roar.cs.berkeley.edu>
On Fri, Aug 29, 2008 at 02:29:00AM -0700, Karl Chen wrote:
Show 7 quoted lines
> core.excludesfile:: > In addition to '.gitignore' (per-directory) and > '.git/info/exclude', git looks into this file for patterns > - of files which are not meant to be tracked. See > + of files which are not meant to be tracked. "~" and "~user" > + are expanded to the user's home directory. See > linkgit:gitignore[5].
How about:
A leading "~" or "~user" is expanded to the home directory of the current user or "user", as in the shell.
Specifically:
1. We obviously handle only leading cases, so /path/to/~file~with~tildes
is ok. 2. It was a little unclear to me whether both "~" and "~user" expande
to the same thing. I.e., can one use this for arbitrary "user" (and
the answer of course is yes).Show 11 quoted lines
> +char *expand_user_path(char *buf, const char *path, int bufsz)
> +{
> + if (path == NULL)
> + return NULL;
> +
> + if (path[0] != '~')
> + return concatstr(buf, path, NULL, bufsz);
> +
> + const char *username = path + 1;
> + size_t username_len = strchrnul(username, '/') - username;
> + struct passwd *pw = getpw_str(username, username_len);Declaration after statement (we try to remain portable to non-C99 systems).
Other than that, I think the patch is fine (though I am not opposed to the improvements Junio has mentioned).
-Peff