path: convert do_git_path to take a 'struct repository'
In preparation to adding 'git_path' like functions which operate on a 'struct repository' convert 'do_git_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
f9a8a47e3951581e09d1f97ebe70f0e3f75c63af
1 file changed
+28
-14
path.c
+28
-14
@@ -371,33 +371,47 @@ void report_linked_checkout_garbage(void)
371
strbuf_release(&sb);
372
}
373
374
-static void adjust_git_path(struct strbuf *buf, int git_dir_len)
374
+static void adjust_git_path(const struct repository *repo,
375
+ struct strbuf *buf, int git_dir_len)
376
{
377
const char *base = buf->buf + git_dir_len;
378
if (is_dir_file(base, "info", "grafts"))
379
strbuf_splice(buf, 0, buf->len,
379
- get_graft_file(), strlen(get_graft_file()));
380
+ repo->graft_file, strlen(repo->graft_file));
381
else if (!strcmp(base, "index"))
382
strbuf_splice(buf, 0, buf->len,
382
- get_index_file(), strlen(get_index_file()));
383
+ repo->index_file, strlen(repo->index_file));
384
else if (dir_prefix(base, "objects"))
384
- replace_dir(buf, git_dir_len + 7, get_object_directory());
385
+ replace_dir(buf, git_dir_len + 7, repo->objectdir);
386
else if (git_hooks_path && dir_prefix(base, "hooks"))
387
replace_dir(buf, git_dir_len + 5, git_hooks_path);
387
- else if (the_repository->different_commondir)
388
- update_common_dir(buf, git_dir_len, get_git_common_dir());
388
+ else if (repo->different_commondir)
389
+ update_common_dir(buf, git_dir_len, repo->commondir);
390
}
391
391
-static void do_git_path(const struct worktree *wt, struct strbuf *buf,
392
+static void strbuf_worktree_gitdir(struct strbuf *buf,
393
+ const struct repository *repo,
394
+ const struct worktree *wt)
395
+{
396
+ if (!wt)
397
+ strbuf_addstr(buf, repo->gitdir);
398
+ else if (!wt->id)
399
+ strbuf_addstr(buf, repo->commondir);
400
+ else
401
+ strbuf_git_common_path(buf, repo, "worktrees/%s", wt->id);
402
+}
403
+
404
+static void do_git_path(const struct repository *repo,
405
+ const struct worktree *wt, struct strbuf *buf,
406
const char *fmt, va_list args)
407
{
408
int gitdir_len;
395
- strbuf_addstr(buf, get_worktree_git_dir(wt));
409
+ strbuf_worktree_gitdir(buf, repo, wt);
410
if (buf->len && !is_dir_sep(buf->buf[buf->len - 1]))
411
strbuf_addch(buf, '/');
412
gitdir_len = buf->len;
413
strbuf_vaddf(buf, fmt, args);
400
- adjust_git_path(buf, gitdir_len);
414
+ adjust_git_path(repo, buf, gitdir_len);
415
strbuf_cleanup_path(buf);
416
}
417
@@ -406,7 +420,7 @@ char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
420
va_list args;
421
strbuf_reset(buf);
422
va_start(args, fmt);
409
- do_git_path(NULL, buf, fmt, args);
423
+ do_git_path(the_repository, NULL, buf, fmt, args);
424
va_end(args);
425
return buf->buf;
426
}
@@ -415,7 +429,7 @@ void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
429
{
430
va_list args;
431
va_start(args, fmt);
418
- do_git_path(NULL, sb, fmt, args);
432
+ do_git_path(the_repository, NULL, sb, fmt, args);
433
va_end(args);
434
}
435
@@ -424,7 +438,7 @@ const char *git_path(const char *fmt, ...)
438
struct strbuf *pathname = get_pathname();
439
va_list args;
440
va_start(args, fmt);
427
- do_git_path(NULL, pathname, fmt, args);
441
+ do_git_path(the_repository, NULL, pathname, fmt, args);
442
va_end(args);
443
return pathname->buf;
444
}
@@ -434,7 +448,7 @@ char *git_pathdup(const char *fmt, ...)
448
struct strbuf path = STRBUF_INIT;
449
va_list args;
450
va_start(args, fmt);
437
- do_git_path(NULL, &path, fmt, args);
451
+ do_git_path(the_repository, NULL, &path, fmt, args);
452
va_end(args);
453
return strbuf_detach(&path, NULL);
454
}
@@ -465,7 +479,7 @@ const char *worktree_git_path(const struct worktree *wt, const char *fmt, ...)
479
struct strbuf *pathname = get_pathname();
480
va_list args;
481
va_start(args, fmt);
468
- do_git_path(wt, pathname, fmt, args);
482
+ do_git_path(the_repository, wt, pathname, fmt, args);
483
va_end(args);
484
return pathname->buf;
485
}