From 9c82357be74bc5404038ec3c16706b1805843556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Fri, 17 Jun 2011 18:13:14 +0200 Subject: Add a remotes API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Martín Nieto --- include/git2/branch.h | 9 ++++++++ include/git2/refspec.h | 22 +++++++++++++++++++ include/git2/remote.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/git2/types.h | 3 +++ 4 files changed, 92 insertions(+) create mode 100644 include/git2/branch.h create mode 100644 include/git2/refspec.h create mode 100644 include/git2/remote.h (limited to 'include/git2') 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/refspec.h b/include/git2/refspec.h new file mode 100644 index 000000000..d45364f71 --- /dev/null +++ b/include/git2/refspec.h @@ -0,0 +1,22 @@ +#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); + +#endif diff --git a/include/git2/remote.h b/include/git2/remote.h new file mode 100644 index 000000000..8edb743d8 --- /dev/null +++ b/include/git2/remote.h @@ -0,0 +1,58 @@ +#ifndef INCLUDE_git_remote_h__ +#define INCLUDE_git_remote_h__ + +#include "git2/common.h" +#include "git2/repository.h" +#include "git2/refspec.h" + +/** + * 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); + +/** + * 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/types.h b/include/git2/types.h index 499ba98ad..963156f85 100644 --- a/include/git2/types.h +++ b/include/git2/types.h @@ -167,6 +167,9 @@ 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; + /** @} */ GIT_END_DECL -- cgit v1.2.1 From f8f3feb0d3e98542b6f7a4ac214a65e7f9950d5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Tue, 21 Jun 2011 02:13:51 +0200 Subject: Add a to-do list for remotes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Martín Nieto --- include/git2/remote.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include/git2') diff --git a/include/git2/remote.h b/include/git2/remote.h index 8edb743d8..ccc130578 100644 --- a/include/git2/remote.h +++ b/include/git2/remote.h @@ -5,6 +5,14 @@ #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 * -- cgit v1.2.1 From 63f91e1ce856da0a6cfd7ec70f24b087a30ef358 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Wed, 22 Jun 2011 16:52:30 +0200 Subject: Add git.git's fnmatch, which is really GNU's and the git__fnmatch wrapper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the strings match, git__fnmatch returns GIT_SUCCESS and GIT_ENOMATCH on failure to match. MSVC fixes: Added a test for _MSC_VER and (in that case) defined HAVE_STRING_H to 1 so it doesn't try to include which doesn't exist in the MSVC world. Moved the function declarations to use the modern inline ones so MSVC doesn't have a fit. Added casts everywhere so MSVC doesn't crap its pants. Signed-off-by: Carlos Martín Nieto --- include/git2/errors.h | 3 +++ include/git2/refspec.h | 10 ++++++++++ 2 files changed, 13 insertions(+) (limited to 'include/git2') diff --git a/include/git2/errors.h b/include/git2/errors.h index 09b1f26bb..334b9edab 100644 --- a/include/git2/errors.h +++ b/include/git2/errors.h @@ -125,6 +125,9 @@ typedef enum { /** Skip and passthrough the given ODB backend */ GIT_EPASSTHROUGH = -30, + + /** The path pattern and string did not match */ + GIT_ENOMATCH = -31, } git_error; /** diff --git a/include/git2/refspec.h b/include/git2/refspec.h index d45364f71..8523d5ab6 100644 --- a/include/git2/refspec.h +++ b/include/git2/refspec.h @@ -19,4 +19,14 @@ const char *git_refspec_src(const git_refspec *refspec); */ 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); + #endif -- cgit v1.2.1 From 92cb6aa929f60eaea66359c8e3258de821a0a965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Thu, 23 Jun 2011 15:41:29 +0200 Subject: Add git_refspec_transform MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Martín Nieto --- include/git2/refspec.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'include/git2') diff --git a/include/git2/refspec.h b/include/git2/refspec.h index 8523d5ab6..0cbe42ff7 100644 --- a/include/git2/refspec.h +++ b/include/git2/refspec.h @@ -29,4 +29,14 @@ const char *git_refspec_dst(const git_refspec *refspec); */ 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 -- cgit v1.2.1 From 8f866daee5a0a43702f349c7fa46d3274542650c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Mon, 16 May 2011 22:07:08 +0200 Subject: Lay down the fundations for the network code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Martín Nieto --- include/git2/net.h | 33 ++++++++++++++++++++++++++++ include/git2/transport.h | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ include/git2/types.h | 11 ++++++++++ 3 files changed, 100 insertions(+) create mode 100644 include/git2/net.h create mode 100644 include/git2/transport.h (limited to 'include/git2') diff --git a/include/git2/net.h b/include/git2/net.h new file mode 100644 index 000000000..869309f9d --- /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" + +/* + * 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. + */ + +enum git_net_direction { + INTENT_PUSH, + INTENT_PULL +}; + +/* + * 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/transport.h b/include/git2/transport.h new file mode 100644 index 000000000..dfbc1a84c --- /dev/null +++ b/include/git2/transport.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. + */ +#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_get(git_transport *transport, const char *url); + +GIT_EXTERN(int) git_transport_connect(git_transport *transport, git_net_direction direction); +/* +GIT_EXTERN(const git_vector *) git_transport_get_refs(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 963156f85..69aa28955 100644 --- a/include/git2/types.h +++ b/include/git2/types.h @@ -167,9 +167,20 @@ 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_headarray git_headarray; + /** @} */ GIT_END_DECL -- cgit v1.2.1 From d6258debbe05e3892466722f897ae932e8e7d8aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Sat, 25 Jun 2011 15:10:09 +0200 Subject: Implement ls-remote on local drive MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Martín Nieto --- include/git2/net.h | 2 +- include/git2/transport.h | 10 ++++++---- include/git2/types.h | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) (limited to 'include/git2') diff --git a/include/git2/net.h b/include/git2/net.h index 869309f9d..67e8a44e5 100644 --- a/include/git2/net.h +++ b/include/git2/net.h @@ -27,7 +27,7 @@ struct git_remote_head { struct git_headarray { unsigned int len; - struct git_remote_head *heads; + struct git_remote_head **heads; }; #endif diff --git a/include/git2/transport.h b/include/git2/transport.h index dfbc1a84c..a12b11b34 100644 --- a/include/git2/transport.h +++ b/include/git2/transport.h @@ -43,12 +43,14 @@ GIT_BEGIN_DECL * @param tranport the transport for the url * @param url the url of the repo */ -GIT_EXTERN(int) git_transport_get(git_transport *transport, const char *url); +GIT_EXTERN(int) git_transport_new(git_transport **transport, git_repository *repo, const char *url); GIT_EXTERN(int) git_transport_connect(git_transport *transport, git_net_direction direction); -/* -GIT_EXTERN(const git_vector *) git_transport_get_refs(git_transport *transport); -*/ + +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); /** @} */ diff --git a/include/git2/types.h b/include/git2/types.h index 69aa28955..8e0659127 100644 --- a/include/git2/types.h +++ b/include/git2/types.h @@ -179,6 +179,7 @@ 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; /** @} */ -- cgit v1.2.1 From f7fc68df832439c3e2355ab747fa05a8b46aa8d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Fri, 27 May 2011 12:50:07 +0200 Subject: Lay the foundations for pkt-line parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This are the types I intend to use for pkt-line parsing and (later) creation. git_pkt serves as a base pointer type and once you know what type it is you can use the real one (command, tip list, etc.) Signed-off-by: Carlos Martín Nieto --- include/git2/pkt.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/git2/types.h | 6 ++++++ 2 files changed, 57 insertions(+) create mode 100644 include/git2/pkt.h (limited to 'include/git2') diff --git a/include/git2/pkt.h b/include/git2/pkt.h new file mode 100644 index 000000000..4a0767e27 --- /dev/null +++ b/include/git2/pkt.h @@ -0,0 +1,51 @@ +/* + * 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_HEAD, + 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_head { + enum git_pkt_type type; + git_remote_head head; +}; diff --git a/include/git2/types.h b/include/git2/types.h index 8e0659127..94f42db62 100644 --- a/include/git2/types.h +++ b/include/git2/types.h @@ -182,6 +182,12 @@ 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_head git_pkt_head; + /** @} */ GIT_END_DECL -- cgit v1.2.1 From b31803f3106f657a6cc6b8c4fd69e017edad2af8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Sat, 28 May 2011 11:59:10 +0200 Subject: pkt-line: parse other-ref lines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add support for parsing other-ref lines. Signed-off-by: Carlos Martín Nieto --- include/git2/pkt.h | 4 ++-- include/git2/types.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'include/git2') diff --git a/include/git2/pkt.h b/include/git2/pkt.h index 4a0767e27..680dcc618 100644 --- a/include/git2/pkt.h +++ b/include/git2/pkt.h @@ -28,7 +28,7 @@ enum git_pkt_type { GIT_PKT_CMD, GIT_PKT_FLUSH, - GIT_PKT_HEAD, + GIT_PKT_REF, GIT_PKT_HAVE, }; @@ -45,7 +45,7 @@ struct git_pkt_cmd { }; /* This is a pkt-line with some info in it */ -struct git_pkt_head { +struct git_pkt_ref { enum git_pkt_type type; git_remote_head head; }; diff --git a/include/git2/types.h b/include/git2/types.h index 94f42db62..ef80435c4 100644 --- a/include/git2/types.h +++ b/include/git2/types.h @@ -186,7 +186,7 @@ typedef struct git_headarray git_headarray; 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_head git_pkt_head; +typedef struct git_pkt_ref git_pkt_ref; /** @} */ GIT_END_DECL -- cgit v1.2.1 From 8b9e8de5ce2fa4da75bf5b27a73f6d74140c6eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Wed, 8 Jun 2011 10:51:32 +0200 Subject: pkt-line: read capabilities MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Try to read the server capabilities and add them to the git_pkt_ref struct. Signed-off-by: Carlos Martín Nieto --- include/git2/pkt.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include/git2') diff --git a/include/git2/pkt.h b/include/git2/pkt.h index 680dcc618..0b933abff 100644 --- a/include/git2/pkt.h +++ b/include/git2/pkt.h @@ -48,4 +48,5 @@ struct git_pkt_cmd { struct git_pkt_ref { enum git_pkt_type type; git_remote_head head; + char *capabilities; }; -- cgit v1.2.1 From 6a9597c5b57456dfe02e4b5ba94ef437907fe1f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Wed, 8 Jun 2011 19:11:38 +0200 Subject: Add function to generate a request MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add git_pkt_gen_proto to crete a request from an url. Signed-off-by: Carlos Martín Nieto --- include/git2/net.h | 2 ++ include/git2/pkt.h | 5 +++++ 2 files changed, 7 insertions(+) (limited to 'include/git2') diff --git a/include/git2/net.h b/include/git2/net.h index 67e8a44e5..fb09eb508 100644 --- a/include/git2/net.h +++ b/include/git2/net.h @@ -5,6 +5,8 @@ #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 diff --git a/include/git2/pkt.h b/include/git2/pkt.h index 0b933abff..8ba3c2ac9 100644 --- a/include/git2/pkt.h +++ b/include/git2/pkt.h @@ -50,3 +50,8 @@ struct git_pkt_ref { git_remote_head head; char *capabilities; }; + +/** + * Create a git protocol request. + */ +int git_pkt_gen_proto(char **out, int *outlen, const char *url); -- cgit v1.2.1 From ecb6ca0e1f908c1480a602e8cca16bd8916b8a99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Wed, 8 Jun 2011 13:09:47 +0200 Subject: Implement the git TCP transport up to ls-remote MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Martín Nieto --- include/git2/pkt.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include/git2') diff --git a/include/git2/pkt.h b/include/git2/pkt.h index 8ba3c2ac9..7d61d4d38 100644 --- a/include/git2/pkt.h +++ b/include/git2/pkt.h @@ -55,3 +55,4 @@ struct git_pkt_ref { * Create a git protocol request. */ int git_pkt_gen_proto(char **out, int *outlen, const char *url); +int git_pkt_parse_line(git_pkt **head, const char *line, const char **out); -- cgit v1.2.1 From be9fe679fc86a8f233b0a6fc6078894edcb8661e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Wed, 8 Jun 2011 23:38:22 +0200 Subject: Implement and use git_pkt_free MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A git_pkt object can be one of several structs. Add this function for convenience and clarity. Signed-off-by: Carlos Martín Nieto --- include/git2/pkt.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include/git2') diff --git a/include/git2/pkt.h b/include/git2/pkt.h index 7d61d4d38..d0ffa5569 100644 --- a/include/git2/pkt.h +++ b/include/git2/pkt.h @@ -56,3 +56,4 @@ struct git_pkt_ref { */ int git_pkt_gen_proto(char **out, int *outlen, const char *url); int git_pkt_parse_line(git_pkt **head, const char *line, const char **out); +void git_pkt_free(git_pkt *pkt); -- cgit v1.2.1 From 7632e2494a5b8bfea41e7fbfaa0fc324e2178932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Mon, 13 Jun 2011 23:01:12 +0200 Subject: Correctly handle network input Add a parameter to git_pkt_parse_line to tell it how much data you have in your buffer. If the buffer is too short, it returns an error saying so. Adapt the git transport to use this and fix the offset calculation. Add the GIT_ESHORTBUFFER error code. --- include/git2/errors.h | 3 +++ include/git2/pkt.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'include/git2') diff --git a/include/git2/errors.h b/include/git2/errors.h index 334b9edab..03c74e822 100644 --- a/include/git2/errors.h +++ b/include/git2/errors.h @@ -128,6 +128,9 @@ typedef enum { /** 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/pkt.h b/include/git2/pkt.h index d0ffa5569..79c582828 100644 --- a/include/git2/pkt.h +++ b/include/git2/pkt.h @@ -55,5 +55,5 @@ struct git_pkt_ref { * Create a git protocol request. */ int git_pkt_gen_proto(char **out, int *outlen, const char *url); -int git_pkt_parse_line(git_pkt **head, const char *line, const char **out); +int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, unsigned int len); void git_pkt_free(git_pkt *pkt); -- cgit v1.2.1 From c4d0fa85b1032690a89989bf15f984b3840b3eee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Thu, 16 Jun 2011 01:54:19 +0200 Subject: Implement and use git_pkt_send_request MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes it easier to send a requqest for an URL. It assumes there is a socket where the string should go out to. Make git_pkt_gen_proto accept a command parameter, which defaults to git-upload-pack Signed-off-by: Carlos Martín Nieto --- include/git2/pkt.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include/git2') diff --git a/include/git2/pkt.h b/include/git2/pkt.h index 79c582828..7a91ed490 100644 --- a/include/git2/pkt.h +++ b/include/git2/pkt.h @@ -54,6 +54,7 @@ struct git_pkt_ref { /** * Create a git protocol request. */ -int git_pkt_gen_proto(char **out, int *outlen, const char *url); +int git_pkt_gen_proto(char **out, int *outlen, const char *cmd, const char *url); +int git_pkt_send_request(int socket, const char *cmd, const char *url); int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, unsigned int len); void git_pkt_free(git_pkt *pkt); -- cgit v1.2.1 From cbf742ac4e7daccae10fd60d0651242c49663bd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Sun, 26 Jun 2011 19:40:02 +0200 Subject: Use (s)size_t MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Martín Nieto --- include/git2/pkt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/git2') diff --git a/include/git2/pkt.h b/include/git2/pkt.h index 7a91ed490..bcd5c81d1 100644 --- a/include/git2/pkt.h +++ b/include/git2/pkt.h @@ -56,5 +56,5 @@ struct git_pkt_ref { */ int git_pkt_gen_proto(char **out, int *outlen, const char *cmd, const char *url); int git_pkt_send_request(int socket, const char *cmd, const char *url); -int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, unsigned int len); +int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_t len); void git_pkt_free(git_pkt *pkt); -- cgit v1.2.1 From fd6790210f646a61c750058261d29f6a68485e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Thu, 16 Jun 2011 02:17:49 +0200 Subject: Move git_pkt_{gen_proto,send_request} to transport_git.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is where they really belong. Remvoe the prefix and make them static. Signed-off-by: Carlos Martín Nieto --- include/git2/pkt.h | 5 ----- 1 file changed, 5 deletions(-) (limited to 'include/git2') diff --git a/include/git2/pkt.h b/include/git2/pkt.h index bcd5c81d1..59826da8a 100644 --- a/include/git2/pkt.h +++ b/include/git2/pkt.h @@ -51,10 +51,5 @@ struct git_pkt_ref { char *capabilities; }; -/** - * Create a git protocol request. - */ -int git_pkt_gen_proto(char **out, int *outlen, const char *cmd, const char *url); -int git_pkt_send_request(int socket, const char *cmd, const char *url); int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_t len); void git_pkt_free(git_pkt *pkt); -- cgit v1.2.1 From 4e913309b92138cdc6ff31fbce4e8afa2ab5458e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Fri, 17 Jun 2011 16:38:21 +0200 Subject: Move transports to an inheritance model MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rather than an 'private' pointer, make the private structures inherit from the generic git_transport struct. This way, we only have to worry about one memory allocation instead of two. The structures are so simple that this may even make the code use less memory overall. Signed-off-by: Carlos Martín Nieto --- include/git2/pkt.h | 1 + include/git2/types.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'include/git2') diff --git a/include/git2/pkt.h b/include/git2/pkt.h index 59826da8a..0b17b3eed 100644 --- a/include/git2/pkt.h +++ b/include/git2/pkt.h @@ -52,4 +52,5 @@ struct git_pkt_ref { }; 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/types.h b/include/git2/types.h index ef80435c4..dae96cf22 100644 --- a/include/git2/types.h +++ b/include/git2/types.h @@ -177,7 +177,7 @@ 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 int (*git_transport_cb)(git_transport **transport); typedef struct git_remote_head git_remote_head; typedef struct git_headarray git_headarray; -- cgit v1.2.1 From ce90a407c7b873780456b182d82d3ba26adbd182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Wed, 22 Jun 2011 15:34:37 +0200 Subject: Remove the repo param from git_transport_new MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Martín Nieto --- include/git2/transport.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/git2') diff --git a/include/git2/transport.h b/include/git2/transport.h index a12b11b34..01883f2ca 100644 --- a/include/git2/transport.h +++ b/include/git2/transport.h @@ -43,7 +43,7 @@ GIT_BEGIN_DECL * @param tranport the transport for the url * @param url the url of the repo */ -GIT_EXTERN(int) git_transport_new(git_transport **transport, git_repository *repo, const char *url); +GIT_EXTERN(int) git_transport_new(git_transport **transport, const char *url); GIT_EXTERN(int) git_transport_connect(git_transport *transport, git_net_direction direction); -- cgit v1.2.1 From 9ba49bb5c861651c5136ad6678fc1570801ddec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Thu, 23 Jun 2011 03:04:23 +0200 Subject: Add git_remote_connect and git_remote_ls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These allow you to implement git-ls-remote when given a reference name and a repository. Signed-off-by: Carlos Martín Nieto --- include/git2/remote.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'include/git2') diff --git a/include/git2/remote.h b/include/git2/remote.h index ccc130578..9a988f36c 100644 --- a/include/git2/remote.h +++ b/include/git2/remote.h @@ -56,6 +56,27 @@ GIT_EXTERN(const git_refspec *) git_remote_fetchspec(struct git_remote *remote); 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, git_net_direction dir); + +/** + * 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 * -- cgit v1.2.1 From 0ac2726fdf945792028e59105d8630a91c5d3663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Mon, 27 Jun 2011 20:23:47 +0200 Subject: Slim down git_transport MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove the unused repo and private pointers and make the direction a flag, as it can only have two states. Change the connect signature to use an int instead of git_net_direction and remove that enum. Signed-off-by: Carlos Martín Nieto --- include/git2/net.h | 6 ++---- include/git2/remote.h | 2 +- include/git2/transport.h | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) (limited to 'include/git2') diff --git a/include/git2/net.h b/include/git2/net.h index fb09eb508..4bef90509 100644 --- a/include/git2/net.h +++ b/include/git2/net.h @@ -13,10 +13,8 @@ * gets called. */ -enum git_net_direction { - INTENT_PUSH, - INTENT_PULL -}; +#define GIT_DIR_FETCH 0 +#define GIT_DIR_PUSH 1 /* * This is what we give out on ->ls() diff --git a/include/git2/remote.h b/include/git2/remote.h index 9a988f36c..03e459569 100644 --- a/include/git2/remote.h +++ b/include/git2/remote.h @@ -64,7 +64,7 @@ GIT_EXTERN(const git_refspec *) git_remote_fetchspec(struct git_remote *remote); * @param remote the remote to connect to * @return GIT_SUCCESS or an error code */ -GIT_EXTERN(int) git_remote_connect(struct git_remote *remote, git_net_direction dir); +GIT_EXTERN(int) git_remote_connect(struct git_remote *remote, int direction); /** * Get a list of refs at the remote diff --git a/include/git2/transport.h b/include/git2/transport.h index 01883f2ca..982b081f8 100644 --- a/include/git2/transport.h +++ b/include/git2/transport.h @@ -45,7 +45,7 @@ GIT_BEGIN_DECL */ GIT_EXTERN(int) git_transport_new(git_transport **transport, const char *url); -GIT_EXTERN(int) git_transport_connect(git_transport *transport, git_net_direction direction); +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); -- cgit v1.2.1