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>
Brandon Williams committed
Jun 22, 2017 at 11:43 UTC
b337172c834b854903fb523416b53fe354b6e2a5
3 files changed
+16
-8
path.c
+8
-5
@@ -524,11 +524,12 @@ int strbuf_git_path_submodule(struct strbuf *buf, const char *path,
524
return err;
525
}
526
527
-static void do_git_common_path(struct strbuf *buf,
527
+static void do_git_common_path(const struct repository *repo,
528
+ struct strbuf *buf,
529
const char *fmt,
530
va_list args)
531
{
531
- strbuf_addstr(buf, get_git_common_dir());
532
+ strbuf_addstr(buf, repo->commondir);
533
if (buf->len && !is_dir_sep(buf->buf[buf->len - 1]))
534
strbuf_addch(buf, '/');
535
strbuf_vaddf(buf, fmt, args);
@@ -540,16 +541,18 @@ const char *git_common_path(const char *fmt, ...)
541
struct strbuf *pathname = get_pathname();
542
va_list args;
543
va_start(args, fmt);
543
- do_git_common_path(pathname, fmt, args);
544
+ do_git_common_path(the_repository, pathname, fmt, args);
545
va_end(args);
546
return pathname->buf;
547
}
548
548
-void strbuf_git_common_path(struct strbuf *sb, const char *fmt, ...)
549
+void strbuf_git_common_path(struct strbuf *sb,
550
+ const struct repository *repo,
551
+ const char *fmt, ...)
552
{
553
va_list args;
554
va_start(args, fmt);
552
- do_git_common_path(sb, fmt, args);
555
+ do_git_common_path(repo, sb, fmt, args);
556
va_end(args);
557
}
558
path.h
+6
-2
@@ -1,6 +1,8 @@
1
#ifndef PATH_H
2
#define PATH_H
3
4
+struct repository;
5
+
6
/*
7
* Return a statically allocated filename, either generically (mkpath), in
8
* 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, ...)
19
__attribute__((format (printf, 3, 4)));
20
extern void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
21
__attribute__((format (printf, 2, 3)));
20
-extern void strbuf_git_common_path(struct strbuf *sb, const char *fmt, ...)
21
- __attribute__((format (printf, 2, 3)));
22
+extern void strbuf_git_common_path(struct strbuf *sb,
23
+ const struct repository *repo,
24
+ const char *fmt, ...)
25
+ __attribute__((format (printf, 3, 4)));
26
extern char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
27
__attribute__((format (printf, 2, 3)));
28
extern int strbuf_git_path_submodule(struct strbuf *sb, const char *path,
worktree.c
+2
-1
@@ -1,4 +1,5 @@
1
#include "cache.h"
2
+#include "repository.h"
3
#include "refs.h"
4
#include "strbuf.h"
5
#include "worktree.h"
@@ -76,7 +77,7 @@ static struct worktree *get_linked_worktree(const char *id)
77
if (!id)
78
die("Missing linked worktree name");
79
79
- strbuf_git_common_path(&path, "worktrees/%s/gitdir", id);
80
+ strbuf_git_common_path(&path, the_repository, "worktrees/%s/gitdir", id);
81
if (strbuf_read_file(&worktree_path, path.buf, 0) <= 0)
82
/* invalid gitdir file */
83
goto done;