push_util.h 2.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
#ifndef INCLUDE_cl_push_util_h__
#define INCLUDE_cl_push_util_h__

#include "git2/oid.h"

/* Constant for zero oid */
extern const git_oid OID_ZERO;

/**
 * Macro for initializing git_remote_callbacks to use test helpers that
 * record data in a record_callbacks_data instance.
 * @param data pointer to a record_callbacks_data instance
 */
14
#define RECORD_CALLBACKS_INIT(data) \
15
	{ GIT_REMOTE_CALLBACKS_VERSION, NULL, NULL, cred_acquire_cb, NULL, NULL, record_update_tips_cb, NULL, NULL, NULL, data }
16 17 18 19 20 21 22 23 24

typedef struct {
	char *name;
	git_oid *old_oid;
	git_oid *new_oid;
} updated_tip;

typedef struct {
	git_vector updated_tips;
25 26 27
	git_vector statuses;
	int pack_progress_calls;
	int transfer_progress_calls;
28 29 30 31 32 33 34
} record_callbacks_data;

typedef struct {
	const char *name;
	const git_oid *oid;
} expected_ref;

35 36 37 38 39 40 41 42 43
/* the results of a push status.  when used for expected values, msg may be NULL
 * to indicate that it should not be matched. */
typedef struct {
	char *ref;
	int success;
	char *msg;
} push_status;


44 45 46 47 48 49 50 51 52 53 54 55
void updated_tip_free(updated_tip *t);

void record_callbacks_data_clear(record_callbacks_data *data);

/**
 * Callback for git_remote_update_tips that records updates
 *
 * @param data (git_vector *) of updated_tip instances
 */
int record_update_tips_cb(const char *refname, const git_oid *a, const git_oid *b, void *data);

/**
56
 * Create a set of refspecs that deletes each of the inputs
57
 *
58 59 60
 * @param out the vector in which to store the refspecs
 * @param heads the remote heads
 * @param heads_len the size of the array
61
 */
62
int create_deletion_refspecs(git_vector *out, const git_remote_head **heads, size_t heads_len);
63 64 65 66 67 68 69 70 71 72 73 74 75

/**
 * Callback for git_remote_list that adds refspecs to vector
 *
 * @param head a ref on the remote
 * @param payload (git_vector *) of git_remote_head instances
 */
int record_ref_cb(git_remote_head *head, void *payload);

/**
 * Verifies that refs on remote stored by record_ref_cb match the expected
 * names, oids, and order.
 *
76 77
 * @param actual_refs actual refs in the remote
 * @param actual_refs_len length of actual_refs
78 79 80
 * @param expected_refs expected remote refs
 * @param expected_refs_len length of expected_refs
 */
81
void verify_remote_refs(const git_remote_head *actual_refs[], size_t actual_refs_len, const expected_ref expected_refs[], size_t expected_refs_len);
82 83

#endif /* INCLUDE_cl_push_util_h__ */