Re: [PATCH v4 06/15] files-backend: remove the use of git_path()
- From
Michael Haggerty <mhagger@alum.mit.edu>
- Date
- Feb 20, 2017, 11:34 UTC
- Message-ID
- <1d750672-441d-14ae-21e9-d7bdd47a50a4@alum.mit.edu>
- In-Reply-To
- <20170218133303.3682-7-pclouds@gmail.com>
On 02/18/2017 02:32 PM, Nguyễn Thái Ngọc Duy wrote:
Show 23 quoted lines
> Given $GIT_DIR and $GIT_COMMON_DIR, files-backend is now in charge of
> deciding what goes where. The end goal is to pass $GIT_DIR only. A
> refs "view" of a linked worktree is a logical ref store that combines
> two files backends together.
>
> (*) Not entirely true since strbuf_git_path_submodule() still does path
> translation underneath. But that's for another patch.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
> refs/files-backend.c | 37 +++++++++++++++++++++++++++++++++----
> 1 file changed, 33 insertions(+), 4 deletions(-)
>
> diff --git a/refs/files-backend.c b/refs/files-backend.c
> index b599ddf92..dbcaf9bda 100644
> --- a/refs/files-backend.c
> +++ b/refs/files-backend.c
> @@ -924,6 +924,9 @@ struct files_ref_store {
> */
> const char *submodule;
>
> + struct strbuf gitdir;
> + struct strbuf gitcommondir;Is there a reason for these to be `strbuf`s rather than `const char *`? (One reason would be if you planned to use the `len` field, but I don't think you do so.)
Show 23 quoted lines
> @@ -937,15 +940,33 @@ static void files_path(struct files_ref_store *refs, struct strbuf *sb,
> {
> struct strbuf tmp = STRBUF_INIT;
> va_list vap;
> + const char *ref;
>
> va_start(vap, fmt);
> strbuf_vaddf(&tmp, fmt, vap);
> va_end(vap);
> - if (refs->submodule)
> + if (refs->submodule) {
> strbuf_git_path_submodule(sb, refs->submodule,
> "%s", tmp.buf);
> - else
> - strbuf_git_path(sb, "%s", tmp.buf);
> + } else if (!strcmp(tmp.buf, "packed-refs") ||
> + !strcmp(tmp.buf, "logs")) { /* non refname path */
> + strbuf_addf(sb, "%s/%s", refs->gitcommondir.buf, tmp.buf);
> + } else if (skip_prefix(tmp.buf, "logs/", &ref)) { /* reflog */
> + if (is_per_worktree_ref(ref))
> + strbuf_addf(sb, "%s/%s", refs->gitdir.buf, tmp.buf);
> + else
> + strbuf_addf(sb, "%s/%s", refs->gitcommondir.buf, tmp.buf);This code would also be simpler if there were separate functions for packed-refs, loose references, and reflogs.
> [...]
Michael