diff options
Diffstat (limited to 'include/git2')
| -rw-r--r-- | include/git2/branch.h | 9 | ||||
| -rw-r--r-- | include/git2/errors.h | 6 | ||||
| -rw-r--r-- | include/git2/net.h | 33 | ||||
| -rw-r--r-- | include/git2/pkt.h | 56 | ||||
| -rw-r--r-- | include/git2/refspec.h | 42 | ||||
| -rw-r--r-- | include/git2/remote.h | 87 | ||||
| -rw-r--r-- | include/git2/transport.h | 58 | ||||
| -rw-r--r-- | include/git2/types.h | 21 |
8 files changed, 312 insertions, 0 deletions
diff --git a/include/git2/branch.h b/include/git2/branch.h new file mode 100644 index 000000000..456b7d1ac --- /dev/null +++ b/include/git2/branch.h @@ -0,0 +1,9 @@ +#ifndef INCLUDE_branch_h__ +#define INCLUDE_branch_h__ + +struct git_branch { + char *remote; /* TODO: Make this a git_remote */ + char *merge; +}; + +#endif diff --git a/include/git2/errors.h b/include/git2/errors.h index 253cb6ae2..710ac244b 100644 --- a/include/git2/errors.h +++ b/include/git2/errors.h @@ -125,6 +125,12 @@ typedef enum { /** Skip and passthrough the given ODB backend */ GIT_EPASSTHROUGH = -30, + + /** The path pattern and string did not match */ + GIT_ENOMATCH = -31, + + /** The buffer is too short to satisfy the request */ + GIT_ESHORTBUFFER = -32, } git_error; /** diff --git a/include/git2/net.h b/include/git2/net.h new file mode 100644 index 000000000..4bef90509 --- /dev/null +++ b/include/git2/net.h @@ -0,0 +1,33 @@ +#ifndef INCLUDE_net_h__ +#define INCLUDE_net_h__ + +#include "common.h" +#include "oid.h" +#include "types.h" + +#define GIT_DEFAULT_PORT "9418" + +/* + * We need this because we need to know whether we should call + * git-upload-pack or git-receive-pack on the remote end when get_refs + * gets called. + */ + +#define GIT_DIR_FETCH 0 +#define GIT_DIR_PUSH 1 + +/* + * This is what we give out on ->ls() + */ + +struct git_remote_head { + git_oid oid; + char *name; +}; + +struct git_headarray { + unsigned int len; + struct git_remote_head **heads; +}; + +#endif diff --git a/include/git2/pkt.h b/include/git2/pkt.h new file mode 100644 index 000000000..0b17b3eed --- /dev/null +++ b/include/git2/pkt.h @@ -0,0 +1,56 @@ +/* + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, + * as published by the Free Software Foundation. + * + * In addition to the permissions in the GNU General Public License, + * the authors give you unlimited permission to link the compiled + * version of this file into combinations with other programs, + * and to distribute those combinations without any restriction + * coming from the use of this file. (The General Public License + * restrictions do apply in other respects; for example, they cover + * modification of the file, and distribution when not linked into + * a combined executable.) + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "git2/net.h" + +enum git_pkt_type { + GIT_PKT_CMD, + GIT_PKT_FLUSH, + GIT_PKT_REF, + GIT_PKT_HAVE, +}; + +/* This would be a flush pkt */ +struct git_pkt { + enum git_pkt_type type; +}; + +struct git_pkt_cmd { + enum git_pkt_type type; + char *cmd; + char *path; + char *host; +}; + +/* This is a pkt-line with some info in it */ +struct git_pkt_ref { + enum git_pkt_type type; + git_remote_head head; + char *capabilities; +}; + +int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_t len); +int git_pkt_send_flush(int s); +void git_pkt_free(git_pkt *pkt); diff --git a/include/git2/refspec.h b/include/git2/refspec.h new file mode 100644 index 000000000..0cbe42ff7 --- /dev/null +++ b/include/git2/refspec.h @@ -0,0 +1,42 @@ +#ifndef INCLUDE_git_refspec_h__ +#define INCLUDE_git_refspec_h__ + +#include "git2/types.h" + +/** + * Get the source specifier + * + * @param refspec the refspec + * @return the refspec's source specifier + */ +const char *git_refspec_src(const git_refspec *refspec); + +/** + * Get the destination specifier + * + * @param refspec the refspec + * @return the refspec's destination specifier + */ +const char *git_refspec_dst(const git_refspec *refspec); + +/** + * Match a refspec's source descriptor with a reference name + * + * @param refspec the refspec + * @param refname the name of the reference to check + * @return GIT_SUCCESS on successful match; GIT_ENOMACH on match + * failure or an error code on other failure + */ +int git_refspec_src_match(const git_refspec *refspec, const char *refname); + +/** + * Transform a reference to its target following the refspec's rules + * + * @param out where to store the target name + * @param in the source reference + * @param spec the refspec + * @param len the length of the out buffer + * @preturn GIT_SUCCESS, GIT_ESHORTBUFFER or another error + */ +int git_refspec_transform(char *out, size_t outlen, const git_refspec *spec, const char *name); +#endif diff --git a/include/git2/remote.h b/include/git2/remote.h new file mode 100644 index 000000000..03e459569 --- /dev/null +++ b/include/git2/remote.h @@ -0,0 +1,87 @@ +#ifndef INCLUDE_git_remote_h__ +#define INCLUDE_git_remote_h__ + +#include "git2/common.h" +#include "git2/repository.h" +#include "git2/refspec.h" + +/* + * TODO: This functions still need to be implemented: + * - _listcb/_foreach + * - _add + * - _rename + * - _del (needs support from config) + */ + +/** + * Get the information for a particular remote + * + * @param out pointer to the new remote object + * @param cfg the repository's configuration + * @param name the remote's name + * @return 0 on success; error value otherwise + */ +GIT_EXTERN(int) git_remote_get(struct git_remote **out, struct git_config *cfg, const char *name); + +/** + * Get the remote's name + * + * @param remote the remote + * @return a pointer to the name + */ +GIT_EXTERN(const char *) git_remote_name(struct git_remote *remote); + +/** + * Get the remote's url + * + * @param remote the remote + * @return a pointer to the url + */ +GIT_EXTERN(const char *) git_remote_url(struct git_remote *remote); + +/** + * Get the fetch refspec + * + * @param remote the remote + * @return a pointer to the fetch refspec or NULL if it doesn't exist + */ +GIT_EXTERN(const git_refspec *) git_remote_fetchspec(struct git_remote *remote); + +/** + * Get the push refspec + * + * @param remote the remote + * @return a pointer to the push refspec or NULL if it doesn't exist + */ + +GIT_EXTERN(const git_refspec *) git_remote_fetchspec(struct git_remote *remote); + +/** + * Open a connection to a remote + * + * The transport is selected based on the URL + * + * @param remote the remote to connect to + * @return GIT_SUCCESS or an error code + */ +GIT_EXTERN(int) git_remote_connect(struct git_remote *remote, int direction); + +/** + * Get a list of refs at the remote + * + * The remote (or more exactly its transport) must be connected. + * + * @param refs where to store the refs + * @param remote the remote + * @return GIT_SUCCESS or an error code + */ +GIT_EXTERN(int) git_remote_ls(git_remote *remote, git_headarray *refs); + +/** + * Free the memory associated with a remote + * + * @param remote the remote to free + */ +GIT_EXTERN(void) git_remote_free(struct git_remote *remote); + +#endif diff --git a/include/git2/transport.h b/include/git2/transport.h new file mode 100644 index 000000000..982b081f8 --- /dev/null +++ b/include/git2/transport.h @@ -0,0 +1,58 @@ +/* + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, + * as published by the Free Software Foundation. + * + * In addition to the permissions in the GNU General Public License, + * the authors give you unlimited permission to link the compiled + * version of this file into combinations with other programs, + * and to distribute those combinations without any restriction + * coming from the use of this file. (The General Public License + * restrictions do apply in other respects; for example, they cover + * modification of the file, and distribution when not linked into + * a combined executable.) + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ +#ifndef INCLUDE_git_transport_h__ +#define INCLUDE_git_transport_h__ + +#include "common.h" +#include "types.h" +#include "net.h" + +/** + * @file git2/transport.h + * @brief Git protocol transport abstraction + * @defgroup git_transport Git protocol transport abstraction + * @ingroup Git + * @{ + */ +GIT_BEGIN_DECL + +/** + * Get the appropriate transport for an URL. + * @param tranport the transport for the url + * @param url the url of the repo + */ +GIT_EXTERN(int) git_transport_new(git_transport **transport, const char *url); + +GIT_EXTERN(int) git_transport_connect(git_transport *transport, int direction); + +GIT_EXTERN(int) git_transport_ls(git_transport *transport, git_headarray *array); +GIT_EXTERN(int) git_transport_close(git_transport *transport); +GIT_EXTERN(void) git_transport_free(git_transport *transport); + +GIT_EXTERN(int) git_transport_add(git_transport *transport, const char *prefix); + +/** @} */ +GIT_END_DECL +#endif diff --git a/include/git2/types.h b/include/git2/types.h index 85cf4ef78..bc1b8a6c7 100644 --- a/include/git2/types.h +++ b/include/git2/types.h @@ -167,6 +167,27 @@ typedef enum { GIT_REF_LISTALL = GIT_REF_OID|GIT_REF_SYMBOLIC|GIT_REF_PACKED, } git_rtype; + +typedef struct git_refspec git_refspec; +typedef struct git_remote git_remote; + +/** A transport to use */ +typedef struct git_transport git_transport; + +/** Whether to push or pull */ +typedef enum git_net_direction git_net_direction; + +typedef int (*git_transport_cb)(git_transport **transport); + +typedef struct git_remote_head git_remote_head; +typedef struct git_headarray git_headarray; + +/* Several types of packets */ +typedef enum git_pkt_type git_pkt_type; +typedef struct git_pkt git_pkt; +typedef struct git_pkt_cmd git_pkt_cmd; +typedef struct git_pkt_ref git_pkt_ref; + /** @} */ GIT_END_DECL |
