Merge branch 'nd/worktree-kill-parse-ref'

"git gc" did not interact well with "git worktree"-managed
per-worktree refs.

* nd/worktree-kill-parse-ref:
  refs: kill set_worktree_head_symref()
  worktree.c: kill parse_ref() in favor of refs_resolve_ref_unsafe()
  refs: introduce get_worktree_ref_store()
  refs: add REFS_STORE_ALL_CAPS
  refs.c: make submodule ref store hashmap generic
  environment.c: fix potential segfault by get_git_common_dir()
This commit is contained in:
Junio C Hamano
2017-05-16 11:51:51 +09:00
10 changed files with 180 additions and 177 deletions

View File

@ -2240,50 +2240,6 @@ static int files_create_symref(struct ref_store *ref_store,
return ret;
}
int set_worktree_head_symref(const char *gitdir, const char *target, const char *logmsg)
{
/*
* FIXME: this obviously will not work well for future refs
* backends. This function needs to die.
*/
struct files_ref_store *refs =
files_downcast(get_main_ref_store(),
REF_STORE_WRITE,
"set_head_symref");
static struct lock_file head_lock;
struct ref_lock *lock;
struct strbuf head_path = STRBUF_INIT;
const char *head_rel;
int ret;
strbuf_addf(&head_path, "%s/HEAD", absolute_path(gitdir));
if (hold_lock_file_for_update(&head_lock, head_path.buf,
LOCK_NO_DEREF) < 0) {
struct strbuf err = STRBUF_INIT;
unable_to_lock_message(head_path.buf, errno, &err);
error("%s", err.buf);
strbuf_release(&err);
strbuf_release(&head_path);
return -1;
}
/* head_rel will be "HEAD" for the main tree, "worktrees/wt/HEAD" for
linked trees */
head_rel = remove_leading_path(head_path.buf,
absolute_path(get_git_common_dir()));
/* to make use of create_symref_locked(), initialize ref_lock */
lock = xcalloc(1, sizeof(struct ref_lock));
lock->lk = &head_lock;
lock->ref_name = xstrdup(head_rel);
ret = create_symref_locked(refs, lock, head_rel, target, logmsg);
unlock_ref(lock); /* will free lock */
strbuf_release(&head_path);
return ret;
}
static int files_reflog_exists(struct ref_store *ref_store,
const char *refname)
{