Skip to content

Commit 613d5eb

Browse files
committed
Push! By schu, phkelley, and congyiwu, et al
1 parent 6930212 commit 613d5eb

File tree

161 files changed

+3905
-344
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

161 files changed

+3905
-344
lines changed

include/git2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "git2/remote.h"
4141
#include "git2/clone.h"
4242
#include "git2/checkout.h"
43+
#include "git2/push.h"
4344

4445
#include "git2/attr.h"
4546
#include "git2/ignore.h"

include/git2/common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ GIT_BEGIN_DECL
8585
*/
8686
#define GIT_PATH_MAX 4096
8787

88+
/**
89+
* The string representation of the null object ID.
90+
*/
91+
#define GIT_OID_HEX_ZERO "0000000000000000000000000000000000000000"
92+
8893
/**
8994
* Return the version of the libgit2 library
9095
* being currently used.

include/git2/errors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ enum {
2929
GIT_EBAREREPO = -8,
3030
GIT_EORPHANEDHEAD = -9,
3131
GIT_EUNMERGED = -10,
32+
GIT_ENONFASTFORWARD = -11,
3233

3334
GIT_PASSTHROUGH = -30,
3435
GIT_ITEROVER = -31,

include/git2/object.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ GIT_EXTERN(const git_oid *) git_object_id(const git_object *obj);
9494
*/
9595
GIT_EXTERN(git_otype) git_object_type(const git_object *obj);
9696

97+
/**
98+
* Get the object type of an object id
99+
*
100+
* @param obj the repository object
101+
* @return the object's type
102+
*/
103+
GIT_EXTERN(int) git_object_oid2type(
104+
git_otype *type,
105+
git_repository *repo,
106+
const git_oid *oid);
107+
97108
/**
98109
* Get the repository that owns this object
99110
*

include/git2/push.h

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (C) 2009-2012 the libgit2 contributors
3+
*
4+
* This file is part of libgit2, distributed under the GNU GPL v2 with
5+
* a Linking Exception. For full terms see the included COPYING file.
6+
*/
7+
#ifndef INCLUDE_git_push_h__
8+
#define INCLUDE_git_push_h__
9+
10+
#include "common.h"
11+
12+
/**
13+
* @file git2/push.h
14+
* @brief Git push management functions
15+
* @defgroup git_push push management functions
16+
* @ingroup Git
17+
* @{
18+
*/
19+
GIT_BEGIN_DECL
20+
21+
/**
22+
* Create a new push object
23+
*
24+
* @param out New push object
25+
* @param remote Remote instance
26+
*
27+
* @return 0 or an error code
28+
*/
29+
GIT_EXTERN(int) git_push_new(git_push **out, git_remote *remote);
30+
31+
/**
32+
* Add a refspec to be pushed
33+
*
34+
* @param push The push object
35+
* @param refspec Refspec string
36+
*
37+
* @return 0 or an error code
38+
*/
39+
GIT_EXTERN(int) git_push_add_refspec(git_push *push, const char *refspec);
40+
41+
/**
42+
* Actually push all given refspecs
43+
*
44+
* @param push The push object
45+
*
46+
* @return 0 or an error code
47+
*/
48+
GIT_EXTERN(int) git_push_finish(git_push *push);
49+
50+
/**
51+
* Check if remote side successfully unpacked
52+
*
53+
* @param push The push object
54+
*
55+
* @return true if equal, false otherwise
56+
*/
57+
GIT_EXTERN(int) git_push_unpack_ok(git_push *push);
58+
59+
/**
60+
* Call callback `cb' on each status
61+
*
62+
* @param push The push object
63+
* @param cb The callback to call on each object
64+
*
65+
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
66+
*/
67+
GIT_EXTERN(int) git_push_status_foreach(git_push *push,
68+
int (*cb)(const char *ref, const char *msg, void *data),
69+
void *data);
70+
71+
/**
72+
* Free the given push object
73+
*
74+
* @param push The push object
75+
*/
76+
GIT_EXTERN(void) git_push_free(git_push *push);
77+
78+
/** @} */
79+
GIT_END_DECL
80+
#endif

include/git2/transport.h

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "indexer.h"
1111
#include "net.h"
12+
#include "types.h"
1213

1314
/**
1415
* @file git2/transport.h
@@ -102,8 +103,8 @@ typedef struct git_transport {
102103
git_headlist_cb list_cb,
103104
void *payload);
104105

105-
/* Reserved until push is implemented. */
106-
int (*push)(struct git_transport *transport);
106+
/* Executes the push whose context is in the git_push object. */
107+
int (*push)(struct git_transport *transport, git_push *push);
107108

108109
/* This function may be called after a successful call to connect(), when
109110
* the direction is FETCH. The function performs a negotiation to calculate
@@ -123,7 +124,7 @@ typedef struct git_transport {
123124
void *progress_payload);
124125

125126
/* Checks to see if the transport is connected */
126-
int (*is_connected)(struct git_transport *transport, int *connected);
127+
int (*is_connected)(struct git_transport *transport);
127128

128129
/* Reads the flags value previously passed into connect() */
129130
int (*read_flags)(struct git_transport *transport, int *flags);
@@ -145,10 +146,11 @@ typedef struct git_transport {
145146
* git:// or http://) and a transport object is returned to the caller.
146147
*
147148
* @param out The newly created transport (out)
149+
* @param owner The git_remote which will own this transport
148150
* @param url The URL to connect to
149151
* @return 0 or an error code
150152
*/
151-
GIT_EXTERN(int) git_transport_new(git_transport **out, const char *url);
153+
GIT_EXTERN(int) git_transport_new(git_transport **out, git_remote *owner, const char *url);
152154

153155
/**
154156
* Function which checks to see if a transport could be created for the
@@ -161,42 +163,48 @@ GIT_EXTERN(int) git_transport_new(git_transport **out, const char *url);
161163
GIT_EXTERN(int) git_transport_valid_url(const char *url);
162164

163165
/* Signature of a function which creates a transport */
164-
typedef int (*git_transport_cb)(git_transport **out, void *payload);
166+
typedef int (*git_transport_cb)(git_transport **out, git_remote *owner, void *param);
165167

166168
/* Transports which come with libgit2 (match git_transport_cb). The expected
167169
* value for "param" is listed in-line below. */
168170

169171
/**
170172
* Create an instance of the dummy transport.
171173
*
172-
* @param transport The newly created transport (out)
174+
* @param out The newly created transport (out)
175+
* @param owner The git_remote which will own this transport
173176
* @param payload You must pass NULL for this parameter.
174177
* @return 0 or an error code
175178
*/
176179
GIT_EXTERN(int) git_transport_dummy(
177-
git_transport **transport,
180+
git_transport **out,
181+
git_remote *owner,
178182
/* NULL */ void *payload);
179183

180184
/**
181185
* Create an instance of the local transport.
182186
*
183-
* @param transport The newly created transport (out)
187+
* @param out The newly created transport (out)
188+
* @param owner The git_remote which will own this transport
184189
* @param payload You must pass NULL for this parameter.
185190
* @return 0 or an error code
186191
*/
187192
GIT_EXTERN(int) git_transport_local(
188-
git_transport **transport,
193+
git_transport **out,
194+
git_remote *owner,
189195
/* NULL */ void *payload);
190196

191197
/**
192198
* Create an instance of the smart transport.
193199
*
194-
* @param transport The newly created transport (out)
200+
* @param out The newly created transport (out)
201+
* @param owner The git_remote which will own this transport
195202
* @param payload A pointer to a git_smart_subtransport_definition
196203
* @return 0 or an error code
197204
*/
198205
GIT_EXTERN(int) git_transport_smart(
199-
git_transport **transport,
206+
git_transport **out,
207+
git_remote *owner,
200208
/* (git_smart_subtransport_definition *) */ void *payload);
201209

202210
/*
@@ -221,6 +229,8 @@ GIT_EXTERN(int) git_transport_smart(
221229
typedef enum {
222230
GIT_SERVICE_UPLOADPACK_LS = 1,
223231
GIT_SERVICE_UPLOADPACK = 2,
232+
GIT_SERVICE_RECEIVEPACK_LS = 3,
233+
GIT_SERVICE_RECEIVEPACK = 4,
224234
} git_smart_service_t;
225235

226236
struct git_smart_subtransport;
@@ -255,6 +265,14 @@ typedef struct git_smart_subtransport {
255265
const char *url,
256266
git_smart_service_t action);
257267

268+
/* Subtransports are guaranteed a call to close() between
269+
* calls to action(), except for the following two "natural" progressions
270+
* of actions against a constant URL.
271+
*
272+
* 1. UPLOADPACK_LS -> UPLOADPACK
273+
* 2. RECEIVEPACK_LS -> RECEIVEPACK */
274+
int (* close)(struct git_smart_subtransport *transport);
275+
258276
void (* free)(struct git_smart_subtransport *transport);
259277
} git_smart_subtransport;
260278

include/git2/types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ typedef enum {
187187

188188
typedef struct git_refspec git_refspec;
189189
typedef struct git_remote git_remote;
190+
typedef struct git_push git_push;
190191

191192
typedef struct git_remote_head git_remote_head;
192193
typedef struct git_remote_callbacks git_remote_callbacks;

src/object.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,19 @@ int git_object_peel(
373373
git_object_free(deref);
374374
return -1;
375375
}
376+
377+
int git_object_oid2type(
378+
git_otype *type,
379+
git_repository *repo,
380+
const git_oid *oid)
381+
{
382+
git_object *obj;
383+
384+
if (git_object_lookup(&obj, repo, oid, GIT_OBJ_ANY) < 0)
385+
return -1;
386+
387+
*type = git_object_type(obj);
388+
389+
git_object_free(obj);
390+
return 0;
391+
}

src/pack-objects.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -604,12 +604,6 @@ static int write_pack(git_packbuilder *pb,
604604
return -1;
605605
}
606606

607-
static int send_pack_file(void *buf, size_t size, void *data)
608-
{
609-
gitno_socket *s = (gitno_socket *)data;
610-
return gitno_send(s, buf, size, 0);
611-
}
612-
613607
static int write_pack_buf(void *buf, size_t size, void *data)
614608
{
615609
git_buf *b = (git_buf *)data;
@@ -1233,12 +1227,6 @@ static int prepare_pack(git_packbuilder *pb)
12331227

12341228
#define PREPARE_PACK if (prepare_pack(pb) < 0) { return -1; }
12351229

1236-
int git_packbuilder_send(git_packbuilder *pb, gitno_socket *s)
1237-
{
1238-
PREPARE_PACK;
1239-
return write_pack(pb, &send_pack_file, s);
1240-
}
1241-
12421230
int git_packbuilder_foreach(git_packbuilder *pb, int (*cb)(void *buf, size_t size, void *payload), void *payload)
12431231
{
12441232
PREPARE_PACK;
@@ -1264,6 +1252,10 @@ static int cb_tree_walk(const char *root, const git_tree_entry *entry, void *pay
12641252
git_packbuilder *pb = payload;
12651253
git_buf buf = GIT_BUF_INIT;
12661254

1255+
/* A commit inside a tree represents a submodule commit and should be skipped. */
1256+
if(git_tree_entry_type(entry) == GIT_OBJ_COMMIT)
1257+
return 0;
1258+
12671259
git_buf_puts(&buf, root);
12681260
git_buf_puts(&buf, git_tree_entry_name(entry));
12691261

src/pack-objects.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ struct git_packbuilder {
8282
bool done;
8383
};
8484

85-
int git_packbuilder_send(git_packbuilder *pb, gitno_socket *s);
8685
int git_packbuilder_write_buf(git_buf *buf, git_packbuilder *pb);
8786

8887
#endif /* INCLUDE_pack_objects_h__ */

0 commit comments

Comments
 (0)