Exemplo n.º 1
0
int for_each_replace_ref(each_ref_fn fn, void *cb_data)
{
	return do_for_each_ref(get_main_ref_store(),
			       git_replace_ref_base, fn,
			       strlen(git_replace_ref_base),
			       0, cb_data);
}
Exemplo n.º 2
0
char *resolve_refdup(const char *refname, int resolve_flags,
		     unsigned char *sha1, int *flags)
{
	return refs_resolve_refdup(get_main_ref_store(),
				   refname, resolve_flags,
				   sha1, flags);
}
Exemplo n.º 3
0
int refs_delete_ref(struct ref_store *refs, const char *msg,
		    const char *refname,
		    const unsigned char *old_sha1,
		    unsigned int flags)
{
	struct ref_transaction *transaction;
	struct strbuf err = STRBUF_INIT;

	if (ref_type(refname) == REF_TYPE_PSEUDOREF) {
		assert(refs == get_main_ref_store());
		return delete_pseudoref(refname, old_sha1);
	}

	transaction = ref_store_transaction_begin(refs, &err);
	if (!transaction ||
	    ref_transaction_delete(transaction, refname, old_sha1,
				   flags, msg, &err) ||
	    ref_transaction_commit(transaction, &err)) {
		error("%s", err.buf);
		ref_transaction_free(transaction);
		strbuf_release(&err);
		return 1;
	}
	ref_transaction_free(transaction);
	strbuf_release(&err);
	return 0;
}
Exemplo n.º 4
0
int other_head_refs(each_ref_fn fn, void *cb_data)
{
	struct worktree **worktrees, **p;
	int ret = 0;

	worktrees = get_worktrees(0);
	for (p = worktrees; *p; p++) {
		struct worktree *wt = *p;
		struct object_id oid;
		int flag;

		if (wt->is_current)
			continue;

		if (!refs_read_ref_full(get_main_ref_store(the_repository),
					worktree_ref(wt, "HEAD"),
					RESOLVE_REF_READING,
					&oid, &flag))
			ret = fn(worktree_ref(wt, "HEAD"), &oid, flag, cb_data);
		if (ret)
			break;
	}
	free_worktrees(worktrees);
	return ret;
}
Exemplo n.º 5
0
int update_ref(const char *msg, const char *refname,
	       const unsigned char *new_sha1,
	       const unsigned char *old_sha1,
	       unsigned int flags, enum action_on_err onerr)
{
	return refs_update_ref(get_main_ref_store(), msg, refname, new_sha1,
			       old_sha1, flags, onerr);
}
Exemplo n.º 6
0
int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data, unsigned int broken)
{
	unsigned int flag = 0;

	if (broken)
		flag = DO_FOR_EACH_INCLUDE_BROKEN;
	return do_for_each_ref(get_main_ref_store(),
			       prefix, fn, 0, flag, cb_data);
}
Exemplo n.º 7
0
int for_each_namespaced_ref(each_ref_fn fn, void *cb_data)
{
	struct strbuf buf = STRBUF_INIT;
	int ret;
	strbuf_addf(&buf, "%srefs/", get_git_namespace());
	ret = do_for_each_ref(get_main_ref_store(),
			      buf.buf, fn, 0, 0, cb_data);
	strbuf_release(&buf);
	return ret;
}
Exemplo n.º 8
0
int reflog_expire(const char *refname, const unsigned char *sha1,
		  unsigned int flags,
		  reflog_expiry_prepare_fn prepare_fn,
		  reflog_expiry_should_prune_fn should_prune_fn,
		  reflog_expiry_cleanup_fn cleanup_fn,
		  void *policy_cb_data)
{
	return refs_reflog_expire(get_main_ref_store(),
				  refname, sha1, flags,
				  prepare_fn, should_prune_fn,
				  cleanup_fn, policy_cb_data);
}
Exemplo n.º 9
0
int refs_update_ref(struct ref_store *refs, const char *msg,
		    const char *refname, const unsigned char *new_sha1,
		    const unsigned char *old_sha1, unsigned int flags,
		    enum action_on_err onerr)
{
	struct ref_transaction *t = NULL;
	struct strbuf err = STRBUF_INIT;
	int ret = 0;

	if (ref_type(refname) == REF_TYPE_PSEUDOREF) {
		assert(refs == get_main_ref_store());
		ret = write_pseudoref(refname, new_sha1, old_sha1, &err);
	} else {
		t = ref_store_transaction_begin(refs, &err);
		if (!t ||
		    ref_transaction_update(t, refname, new_sha1, old_sha1,
					   flags, msg, &err) ||
		    ref_transaction_commit(t, &err)) {
			ret = 1;
			ref_transaction_free(t);
		}
	}
	if (ret) {
		const char *str = "update_ref failed for ref '%s': %s";

		switch (onerr) {
		case UPDATE_REFS_MSG_ON_ERR:
			error(str, refname, err.buf);
			break;
		case UPDATE_REFS_DIE_ON_ERR:
			die(str, refname, err.buf);
			break;
		case UPDATE_REFS_QUIET_ON_ERR:
			break;
		}
		strbuf_release(&err);
		return 1;
	}
	strbuf_release(&err);
	if (t)
		ref_transaction_free(t);
	return 0;
}
Exemplo n.º 10
0
struct ref_store *get_submodule_ref_store(const char *submodule)
{
	struct strbuf submodule_sb = STRBUF_INIT;
	struct ref_store *refs;
	int ret;

	if (!submodule || !*submodule) {
		/*
		 * FIXME: This case is ideally not allowed. But that
		 * can't happen until we clean up all the callers.
		 */
		return get_main_ref_store();
	}

	refs = lookup_submodule_ref_store(submodule);
	if (refs)
		return refs;

	strbuf_addstr(&submodule_sb, submodule);
	ret = is_nonbare_repository_dir(&submodule_sb);
	strbuf_release(&submodule_sb);
	if (!ret)
		return NULL;

	ret = submodule_to_gitdir(&submodule_sb, submodule);
	if (ret) {
		strbuf_release(&submodule_sb);
		return NULL;
	}

	/* assume that add_submodule_odb() has been called */
	refs = ref_store_init(submodule_sb.buf,
			      REF_STORE_READ | REF_STORE_ODB);
	register_submodule_ref_store(refs, submodule);

	strbuf_release(&submodule_sb);
	return refs;
}
Exemplo n.º 11
0
struct ref_transaction *ref_transaction_begin(struct strbuf *err)
{
	return ref_store_transaction_begin(get_main_ref_store(), err);
}
Exemplo n.º 12
0
int delete_ref(const char *msg, const char *refname,
	       const unsigned char *old_sha1, unsigned int flags)
{
	return refs_delete_ref(get_main_ref_store(), msg, refname,
			       old_sha1, flags);
}
Exemplo n.º 13
0
int for_each_remote_ref(each_ref_fn fn, void *cb_data)
{
	return refs_for_each_remote_ref(get_main_ref_store(), fn, cb_data);
}
Exemplo n.º 14
0
int rename_ref(const char *oldref, const char *newref, const char *logmsg)
{
	return refs_rename_ref(get_main_ref_store(), oldref, newref, logmsg);
}
Exemplo n.º 15
0
int delete_reflog(const char *refname)
{
	return refs_delete_reflog(get_main_ref_store(), refname);
}
Exemplo n.º 16
0
int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data)
{
	return refs_for_each_ref_in(get_main_ref_store(), prefix, fn, cb_data);
}
Exemplo n.º 17
0
int reflog_exists(const char *refname)
{
	return refs_reflog_exists(get_main_ref_store(), refname);
}
Exemplo n.º 18
0
int for_each_reflog_ent(const char *refname, each_reflog_ent_fn fn,
			void *cb_data)
{
	return refs_for_each_reflog_ent(get_main_ref_store(), refname,
					fn, cb_data);
}
Exemplo n.º 19
0
int create_symref(const char *ref_target, const char *refs_heads_master,
		  const char *logmsg)
{
	return refs_create_symref(get_main_ref_store(), ref_target,
				  refs_heads_master, logmsg);
}
Exemplo n.º 20
0
int peel_ref(const char *refname, unsigned char *sha1)
{
	return refs_peel_ref(get_main_ref_store(), refname, sha1);
}
Exemplo n.º 21
0
int delete_refs(struct string_list *refnames, unsigned int flags)
{
	return refs_delete_refs(get_main_ref_store(), refnames, flags);
}
Exemplo n.º 22
0
int safe_create_reflog(const char *refname, int force_create,
		       struct strbuf *err)
{
	return refs_create_reflog(get_main_ref_store(), refname,
				  force_create, err);
}
Exemplo n.º 23
0
/* backend functions */
int refs_init_db(struct strbuf *err)
{
	struct ref_store *refs = get_main_ref_store();

	return refs->be->init_db(refs, err);
}