push.h 3.09 KB
Newer Older
1
/*
Edward Thomson committed
2
 * Copyright (C) the libgit2 contributors. All rights reserved.
3 4 5 6 7 8 9
 *
 * This file is part of libgit2, distributed under the GNU GPL v2 with
 * a Linking Exception. For full terms see the included COPYING file.
 */
#ifndef INCLUDE_push_h__
#define INCLUDE_push_h__

10 11
#include "common.h"

12
#include "git2.h"
13
#include "refspec.h"
14 15

typedef struct push_spec {
16
	struct git_refspec refspec;
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33

	git_oid loid;
	git_oid roid;
} push_spec;

typedef struct push_status {
	bool ok;

	char *ref;
	char *msg;
} push_status;

struct git_push {
	git_repository *repo;
	git_packbuilder *pb;
	git_remote *remote;
	git_vector specs;
34
	git_vector updates;
35 36 37 38 39
	bool report_status;

	/* report-status */
	bool unpack_ok;
	git_vector status;
40 41 42

	/* options */
	unsigned pb_parallelism;
43
	const git_strarray *custom_headers;
44 45
};

46 47 48 49 50 51 52
/**
 * Free the given push status object
 *
 * @param status The push status object
 */
void git_push_status_free(push_status *status);

53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
/**
 * Create a new push object
 *
 * @param out New push object
 * @param remote Remote instance
 *
 * @return 0 or an error code
 */
int git_push_new(git_push **out, git_remote *remote);

/**
 * Set options on a push object
 *
 * @param push The push object
 * @param opts The options to set on the push object
 *
 * @return 0 or an error code
 */
int git_push_set_options(
	git_push *push,
	const git_push_options *opts);

/**
 * Add a refspec to be pushed
 *
 * @param push The push object
 * @param refspec Refspec string
 *
 * @return 0 or an error code
 */
int git_push_add_refspec(git_push *push, const char *refspec);

/**
 * Update remote tips after a push
 *
 * @param push The push object
Ben Chatelain committed
89
 * @param callbacks the callbacks to use for this connection
90 91 92
 *
 * @return 0 or an error code
 */
93
int git_push_update_tips(git_push *push, const git_remote_callbacks *callbacks);
94 95 96 97 98 99 100 101 102 103 104 105

/**
 * Perform the push
 *
 * This function will return an error in case of a protocol error or
 * the server being unable to unpack the data we sent.
 *
 * The return value does not reflect whether the server accepted or
 * refused any reference updates. Use `git_push_status_foreach()` in
 * order to find out which updates were accepted or rejected.
 *
 * @param push The push object
Ben Chatelain committed
106
 * @param callbacks the callbacks to use for this connection
107 108 109
 *
 * @return 0 or an error code
 */
110
int git_push_finish(git_push *push, const git_remote_callbacks *callbacks);
111 112 113 114 115 116 117 118 119 120 121 122 123

/**
 * Invoke callback `cb' on each status entry
 *
 * For each of the updated references, we receive a status report in the
 * form of `ok refs/heads/master` or `ng refs/heads/master <msg>`.
 * `msg != NULL` means the reference has not been updated for the given
 * reason.
 *
 * Return a non-zero value from the callback to stop the loop.
 *
 * @param push The push object
 * @param cb The callback to call on each object
Ben Chatelain committed
124
 * @param data The payload passed to the callback
125 126 127 128 129 130 131 132 133 134 135 136 137 138
 *
 * @return 0 on success, non-zero callback return value, or error code
 */
int git_push_status_foreach(git_push *push,
			int (*cb)(const char *ref, const char *msg, void *data),
			void *data);

/**
 * Free the given push object
 *
 * @param push The push object
 */
void git_push_free(git_push *push);

139
#endif