Browse Source

path: convert strbuf_git_common_path to take a 'struct repository'

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Brandon Williams 8 years ago committed by Junio C Hamano
parent
commit
b337172c83
  1. 13
      path.c
  2. 8
      path.h
  3. 3
      worktree.c

13
path.c

@ -524,11 +524,12 @@ int strbuf_git_path_submodule(struct strbuf *buf, const char *path,
return err; return err;
} }


static void do_git_common_path(struct strbuf *buf, static void do_git_common_path(const struct repository *repo,
struct strbuf *buf,
const char *fmt, const char *fmt,
va_list args) va_list args)
{ {
strbuf_addstr(buf, get_git_common_dir()); strbuf_addstr(buf, repo->commondir);
if (buf->len && !is_dir_sep(buf->buf[buf->len - 1])) if (buf->len && !is_dir_sep(buf->buf[buf->len - 1]))
strbuf_addch(buf, '/'); strbuf_addch(buf, '/');
strbuf_vaddf(buf, fmt, args); strbuf_vaddf(buf, fmt, args);
@ -540,16 +541,18 @@ const char *git_common_path(const char *fmt, ...)
struct strbuf *pathname = get_pathname(); struct strbuf *pathname = get_pathname();
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
do_git_common_path(pathname, fmt, args); do_git_common_path(the_repository, pathname, fmt, args);
va_end(args); va_end(args);
return pathname->buf; return pathname->buf;
} }


void strbuf_git_common_path(struct strbuf *sb, const char *fmt, ...) void strbuf_git_common_path(struct strbuf *sb,
const struct repository *repo,
const char *fmt, ...)
{ {
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
do_git_common_path(sb, fmt, args); do_git_common_path(repo, sb, fmt, args);
va_end(args); va_end(args);
} }



8
path.h

@ -1,6 +1,8 @@
#ifndef PATH_H #ifndef PATH_H
#define PATH_H #define PATH_H


struct repository;

/* /*
* Return a statically allocated filename, either generically (mkpath), in * Return a statically allocated filename, either generically (mkpath), in
* the repository directory (git_path), or in a submodule's repository * the repository directory (git_path), or in a submodule's repository
@ -17,8 +19,10 @@ extern char *mksnpath(char *buf, size_t n, const char *fmt, ...)
__attribute__((format (printf, 3, 4))); __attribute__((format (printf, 3, 4)));
extern void strbuf_git_path(struct strbuf *sb, const char *fmt, ...) extern void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
__attribute__((format (printf, 2, 3))); __attribute__((format (printf, 2, 3)));
extern void strbuf_git_common_path(struct strbuf *sb, const char *fmt, ...) extern void strbuf_git_common_path(struct strbuf *sb,
__attribute__((format (printf, 2, 3))); const struct repository *repo,
const char *fmt, ...)
__attribute__((format (printf, 3, 4)));
extern char *git_path_buf(struct strbuf *buf, const char *fmt, ...) extern char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
__attribute__((format (printf, 2, 3))); __attribute__((format (printf, 2, 3)));
extern int strbuf_git_path_submodule(struct strbuf *sb, const char *path, extern int strbuf_git_path_submodule(struct strbuf *sb, const char *path,

3
worktree.c

@ -1,4 +1,5 @@
#include "cache.h" #include "cache.h"
#include "repository.h"
#include "refs.h" #include "refs.h"
#include "strbuf.h" #include "strbuf.h"
#include "worktree.h" #include "worktree.h"
@ -76,7 +77,7 @@ static struct worktree *get_linked_worktree(const char *id)
if (!id) if (!id)
die("Missing linked worktree name"); die("Missing linked worktree name");


strbuf_git_common_path(&path, "worktrees/%s/gitdir", id); strbuf_git_common_path(&path, the_repository, "worktrees/%s/gitdir", id);
if (strbuf_read_file(&worktree_path, path.buf, 0) <= 0) if (strbuf_read_file(&worktree_path, path.buf, 0) <= 0)
/* invalid gitdir file */ /* invalid gitdir file */
goto done; goto done;

Loading…
Cancel
Save