Ejemplo n.º 1
0
static int copy_common(transaction_node *node, git_transaction *tx, const git_signature *sig, const char *msg)
{
	if (sig && git_signature__pdup(&node->sig, sig, &tx->pool) < 0)
		return -1;

	if (!node->sig) {
		git_signature *tmp;
		int error;

		if (git_reference__log_signature(&tmp, tx->repo) < 0)
			return -1;

		/* make sure the sig we use is in our pool */
		error = git_signature__pdup(&node->sig, tmp, &tx->pool);
		git_signature_free(tmp);
		if (error < 0)
			return error;
	}

	if (msg) {
		node->message = git_pool_strdup(&tx->pool, msg);
		GITERR_CHECK_ALLOC(node->message);
	}

	return 0;
}
Ejemplo n.º 2
0
int git_transaction_lock_ref(git_transaction *tx, const char *refname)
{
	int error;
	transaction_node *node;

	assert(tx && refname);

	node = git_pool_mallocz(&tx->pool, sizeof(transaction_node));
	GITERR_CHECK_ALLOC(node);

	node->name = git_pool_strdup(&tx->pool, refname);
	GITERR_CHECK_ALLOC(node->name);

	if ((error = git_refdb_lock(&node->payload, tx->db, refname)) < 0)
		return error;

	git_strmap_insert(tx->locks, node->name, node, error);
	if (error < 0) 
		goto cleanup;

	return 0;

cleanup:
	git_refdb_unlock(tx->db, node->payload, false, false, NULL, NULL, NULL);

	return error;
}
Ejemplo n.º 3
0
static int dup_reflog(git_reflog **out, const git_reflog *in, git_pool *pool)
{
	git_reflog *reflog;
	git_reflog_entry *entries;
	size_t len, i;

	reflog = git_pool_mallocz(pool, sizeof(git_reflog));
	GITERR_CHECK_ALLOC(reflog);

	reflog->ref_name = git_pool_strdup(pool, in->ref_name);
	GITERR_CHECK_ALLOC(reflog->ref_name);

	len = in->entries.length;
	reflog->entries.length = len;
	reflog->entries.contents = git_pool_mallocz(pool, len * sizeof(void *));
	GITERR_CHECK_ALLOC(reflog->entries.contents);

	entries = git_pool_mallocz(pool, len * sizeof(git_reflog_entry));
	GITERR_CHECK_ALLOC(entries);

	for (i = 0; i < len; i++) {
		const git_reflog_entry *src;
		git_reflog_entry *tgt;

		tgt = &entries[i];
		reflog->entries.contents[i] = tgt;

		src = git_vector_get(&in->entries, i);
		git_oid_cpy(&tgt->oid_old, &src->oid_old);
		git_oid_cpy(&tgt->oid_cur, &src->oid_cur);

		tgt->msg = git_pool_strdup(pool, src->msg);
		GITERR_CHECK_ALLOC(tgt->msg);

		if (git_signature__pdup(&tgt->committer, src->committer, pool) < 0)
			return -1;
	}


	*out = reflog;
	return 0;
}
Ejemplo n.º 4
0
int git_signature__pdup(git_signature **dest, const git_signature *source, git_pool *pool)
{
	git_signature *signature;

	if (source == NULL)
		return 0;

	signature = git_pool_mallocz(pool, sizeof(git_signature));
	GITERR_CHECK_ALLOC(signature);

	signature->name = git_pool_strdup(pool, source->name);
	GITERR_CHECK_ALLOC(signature->name);

	signature->email = git_pool_strdup(pool, source->email);
	GITERR_CHECK_ALLOC(signature->email);

	signature->when.time = source->when.time;
	signature->when.offset = source->when.offset;

	*dest = signature;

	return 0;
}
Ejemplo n.º 5
0
int git_transaction_set_symbolic_target(git_transaction *tx, const char *refname, const char *target, const git_signature *sig, const char *msg)
{
	int error;
	transaction_node *node;

	assert(tx && refname && target);

	if ((error = find_locked(&node, tx, refname)) < 0)
		return error;

	if ((error = copy_common(node, tx, sig, msg)) < 0)
		return error;

	node->target.symbolic = git_pool_strdup(&tx->pool, target);
	GITERR_CHECK_ALLOC(node->target.symbolic);
	node->ref_type = GIT_REF_SYMBOLIC;

	return 0;
}
Ejemplo n.º 6
0
static int checkout_action_wd_only(
    checkout_data *data,
    git_iterator *workdir,
    const git_index_entry *wd,
    git_vector *pathspec)
{
    bool remove = false;
    git_checkout_notify_t notify = GIT_CHECKOUT_NOTIFY_NONE;

    if (!git_pathspec_match_path(
                pathspec, wd->path,
                (data->strategy & GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH) != 0,
                git_iterator_ignore_case(workdir), NULL))
        return 0;

    /* check if item is tracked in the index but not in the checkout diff */
    if (data->index != NULL) {
        if (wd->mode != GIT_FILEMODE_TREE) {
            int error;

            if ((error = git_index_find(NULL, data->index, wd->path)) == 0) {
                notify = GIT_CHECKOUT_NOTIFY_DIRTY;
                remove = ((data->strategy & GIT_CHECKOUT_FORCE) != 0);
            } else if (error != GIT_ENOTFOUND)
                return error;
        } else {
            /* for tree entries, we have to see if there are any index
             * entries that are contained inside that tree
             */
            size_t pos = git_index__prefix_position(data->index, wd->path);
            const git_index_entry *e = git_index_get_byindex(data->index, pos);

            if (e != NULL && data->diff->pfxcomp(e->path, wd->path) == 0) {
                notify = GIT_CHECKOUT_NOTIFY_DIRTY;
                remove = ((data->strategy & GIT_CHECKOUT_FORCE) != 0);
            }
        }
    }

    if (notify != GIT_CHECKOUT_NOTIFY_NONE)
        /* found in index */;
    else if (git_iterator_current_is_ignored(workdir)) {
        notify = GIT_CHECKOUT_NOTIFY_IGNORED;
        remove = ((data->strategy & GIT_CHECKOUT_REMOVE_IGNORED) != 0);
    }
    else {
        notify = GIT_CHECKOUT_NOTIFY_UNTRACKED;
        remove = ((data->strategy & GIT_CHECKOUT_REMOVE_UNTRACKED) != 0);
    }

    if (checkout_notify(data, notify, NULL, wd))
        return GIT_EUSER;

    if (remove) {
        char *path = git_pool_strdup(&data->pool, wd->path);
        GITERR_CHECK_ALLOC(path);

        if (git_vector_insert(&data->removes, path) < 0)
            return -1;
    }

    return 0;
}
Ejemplo n.º 7
0
char *git_pool_strdup_safe(git_pool *pool, const char *str)
{
	return str ? git_pool_strdup(pool, str) : NULL;
}