Commit f9f2344b by Vicent Martí

Merge pull request #632 from arrbee/win64-cleanup

Code clean up, including fixing warnings on Windows 64-bit build
parents 4795807a 26515e73
...@@ -33,6 +33,17 @@ GIT_BEGIN_DECL ...@@ -33,6 +33,17 @@ GIT_BEGIN_DECL
GIT_EXTERN(int) git_reference_lookup(git_reference **reference_out, git_repository *repo, const char *name); GIT_EXTERN(int) git_reference_lookup(git_reference **reference_out, git_repository *repo, const char *name);
/** /**
* Lookup a reference by name and resolve immediately to OID.
*
* @param oid Pointer to oid to be filled in
* @param repo The repository in which to look up the reference
* @param name The long name for the reference
* @return 0 on success, -1 if name could not be resolved
*/
GIT_EXTERN(int) git_reference_name_to_oid(
git_oid *out, git_repository *repo, const char *name);
/**
* Create a new symbolic reference. * Create a new symbolic reference.
* *
* The reference will be created in the repository and written * The reference will be created in the repository and written
...@@ -304,6 +315,15 @@ GIT_EXTERN(int) git_reference_reload(git_reference *ref); ...@@ -304,6 +315,15 @@ GIT_EXTERN(int) git_reference_reload(git_reference *ref);
*/ */
GIT_EXTERN(void) git_reference_free(git_reference *ref); GIT_EXTERN(void) git_reference_free(git_reference *ref);
/**
* Compare two references.
*
* @param ref1 The first git_reference
* @param ref2 The second git_reference
* @return GIT_SUCCESS if the same, else a stable but meaningless ordering.
*/
GIT_EXTERN(int) git_reference_cmp(git_reference *ref1, git_reference *ref2);
/** @} */ /** @} */
GIT_END_DECL GIT_END_DECL
#endif #endif
...@@ -46,7 +46,7 @@ static void net_set_error(const char *str) ...@@ -46,7 +46,7 @@ static void net_set_error(const char *str)
} }
#endif #endif
void gitno_buffer_setup(gitno_buffer *buf, char *data, unsigned int len, int fd) void gitno_buffer_setup(gitno_buffer *buf, char *data, unsigned int len, GIT_SOCKET fd)
{ {
memset(buf, 0x0, sizeof(gitno_buffer)); memset(buf, 0x0, sizeof(gitno_buffer));
memset(data, 0x0, len); memset(data, 0x0, len);
...@@ -60,17 +60,13 @@ int gitno_recv(gitno_buffer *buf) ...@@ -60,17 +60,13 @@ int gitno_recv(gitno_buffer *buf)
{ {
int ret; int ret;
ret = recv(buf->fd, buf->data + buf->offset, buf->len - buf->offset, 0); ret = p_recv(buf->fd, buf->data + buf->offset, buf->len - buf->offset, 0);
if (ret == 0) /* Orderly shutdown, so exit */
return 0;
if (ret < 0) { if (ret < 0) {
net_set_error("Error receiving data"); net_set_error("Error receiving socket data");
return -1; return -1;
} }
buf->offset += ret; buf->offset += ret;
return ret; return ret;
} }
...@@ -97,12 +93,12 @@ void gitno_consume_n(gitno_buffer *buf, size_t cons) ...@@ -97,12 +93,12 @@ void gitno_consume_n(gitno_buffer *buf, size_t cons)
buf->offset -= cons; buf->offset -= cons;
} }
int gitno_connect(const char *host, const char *port) GIT_SOCKET gitno_connect(const char *host, const char *port)
{ {
struct addrinfo *info, *p; struct addrinfo *info = NULL, *p;
struct addrinfo hints; struct addrinfo hints;
int ret; int ret;
GIT_SOCKET s; GIT_SOCKET s = INVALID_SOCKET;
memset(&hints, 0x0, sizeof(struct addrinfo)); memset(&hints, 0x0, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC; hints.ai_family = AF_UNSPEC;
...@@ -110,36 +106,30 @@ int gitno_connect(const char *host, const char *port) ...@@ -110,36 +106,30 @@ int gitno_connect(const char *host, const char *port)
if ((ret = getaddrinfo(host, port, &hints, &info)) < 0) { if ((ret = getaddrinfo(host, port, &hints, &info)) < 0) {
giterr_set(GITERR_NET, "Failed to resolve address for %s: %s", host, gai_strerror(ret)); giterr_set(GITERR_NET, "Failed to resolve address for %s: %s", host, gai_strerror(ret));
return -1; return INVALID_SOCKET;
} }
for (p = info; p != NULL; p = p->ai_next) { for (p = info; p != NULL; p = p->ai_next) {
s = socket(p->ai_family, p->ai_socktype, p->ai_protocol); s = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
#ifdef GIT_WIN32
if (s == INVALID_SOCKET) { if (s == INVALID_SOCKET) {
#else net_set_error("error creating socket");
if (s < 0) { break;
#endif
net_set_error("Error creating socket");
freeaddrinfo(info);
return -1;
} }
ret = connect(s, p->ai_addr, p->ai_addrlen); if (connect(s, p->ai_addr, (socklen_t)p->ai_addrlen) == 0)
/* If we can't connect, try the next one */ break;
if (ret < 0) {
close(s);
continue;
}
/* Return the socket */ /* If we can't connect, try the next one */
freeaddrinfo(info); gitno_close(s);
return s; s = INVALID_SOCKET;
} }
/* Oops, we couldn't connect to any address */ /* Oops, we couldn't connect to any address */
giterr_set(GITERR_OS, "Failed to connect to %s", host); if (s == INVALID_SOCKET && p == NULL)
return -1; giterr_set(GITERR_OS, "Failed to connect to %s", host);
freeaddrinfo(info);
return s;
} }
int gitno_send(GIT_SOCKET s, const char *msg, size_t len, int flags) int gitno_send(GIT_SOCKET s, const char *msg, size_t len, int flags)
...@@ -150,7 +140,7 @@ int gitno_send(GIT_SOCKET s, const char *msg, size_t len, int flags) ...@@ -150,7 +140,7 @@ int gitno_send(GIT_SOCKET s, const char *msg, size_t len, int flags)
while (off < len) { while (off < len) {
errno = 0; errno = 0;
ret = send(s, msg + off, len - off, flags); ret = p_send(s, msg + off, len - off, flags);
if (ret < 0) { if (ret < 0) {
net_set_error("Error sending data"); net_set_error("Error sending data");
return -1; return -1;
...@@ -159,7 +149,7 @@ int gitno_send(GIT_SOCKET s, const char *msg, size_t len, int flags) ...@@ -159,7 +149,7 @@ int gitno_send(GIT_SOCKET s, const char *msg, size_t len, int flags)
off += ret; off += ret;
} }
return off; return (int)off;
} }
...@@ -187,7 +177,7 @@ int gitno_select_in(gitno_buffer *buf, long int sec, long int usec) ...@@ -187,7 +177,7 @@ int gitno_select_in(gitno_buffer *buf, long int sec, long int usec)
FD_SET(buf->fd, &fds); FD_SET(buf->fd, &fds);
/* The select(2) interface is silly */ /* The select(2) interface is silly */
return select(buf->fd + 1, &fds, NULL, NULL, &tv); return select((int)buf->fd + 1, &fds, NULL, NULL, &tv);
} }
int gitno_extract_host_and_port(char **host, char **port, const char *url, const char *default_port) int gitno_extract_host_and_port(char **host, char **port, const char *url, const char *default_port)
...@@ -198,8 +188,8 @@ int gitno_extract_host_and_port(char **host, char **port, const char *url, const ...@@ -198,8 +188,8 @@ int gitno_extract_host_and_port(char **host, char **port, const char *url, const
slash = strchr(url, '/'); slash = strchr(url, '/');
if (slash == NULL) { if (slash == NULL) {
giterr_set(GITERR_NET, "Malformed URL: missing /"); giterr_set(GITERR_NET, "Malformed URL: missing /");
return -1; return -1;
} }
if (colon == NULL) { if (colon == NULL) {
......
...@@ -7,11 +7,7 @@ ...@@ -7,11 +7,7 @@
#ifndef INCLUDE_netops_h__ #ifndef INCLUDE_netops_h__
#define INCLUDE_netops_h__ #define INCLUDE_netops_h__
#ifndef GIT_WIN32 #include "posix.h"
typedef int GIT_SOCKET;
#else
typedef SOCKET GIT_SOCKET;
#endif
typedef struct gitno_buffer { typedef struct gitno_buffer {
char *data; char *data;
...@@ -20,12 +16,12 @@ typedef struct gitno_buffer { ...@@ -20,12 +16,12 @@ typedef struct gitno_buffer {
GIT_SOCKET fd; GIT_SOCKET fd;
} gitno_buffer; } gitno_buffer;
void gitno_buffer_setup(gitno_buffer *buf, char *data, unsigned int len, int fd); void gitno_buffer_setup(gitno_buffer *buf, char *data, unsigned int len, GIT_SOCKET fd);
int gitno_recv(gitno_buffer *buf); int gitno_recv(gitno_buffer *buf);
void gitno_consume(gitno_buffer *buf, const char *ptr); void gitno_consume(gitno_buffer *buf, const char *ptr);
void gitno_consume_n(gitno_buffer *buf, size_t cons); void gitno_consume_n(gitno_buffer *buf, size_t cons);
int gitno_connect(const char *host, const char *port); GIT_SOCKET gitno_connect(const char *host, const char *port);
int gitno_send(GIT_SOCKET s, const char *msg, size_t len, int flags); int gitno_send(GIT_SOCKET s, const char *msg, size_t len, int flags);
int gitno_close(GIT_SOCKET s); int gitno_close(GIT_SOCKET s);
int gitno_send_chunk_size(int s, size_t len); int gitno_send_chunk_size(int s, size_t len);
......
...@@ -212,7 +212,7 @@ static int packfile_load__cb(void *_data, git_buf *path) ...@@ -212,7 +212,7 @@ static int packfile_load__cb(void *_data, git_buf *path)
struct pack_backend *backend = (struct pack_backend *)_data; struct pack_backend *backend = (struct pack_backend *)_data;
struct git_pack_file *pack; struct git_pack_file *pack;
int error; int error;
size_t i; unsigned int i;
if (git__suffixcmp(path->ptr, ".idx") != 0) if (git__suffixcmp(path->ptr, ".idx") != 0)
return 0; /* not an index */ return 0; /* not an index */
...@@ -266,7 +266,7 @@ static int packfile_refresh_all(struct pack_backend *backend) ...@@ -266,7 +266,7 @@ static int packfile_refresh_all(struct pack_backend *backend)
static int pack_entry_find(struct git_pack_entry *e, struct pack_backend *backend, const git_oid *oid) static int pack_entry_find(struct git_pack_entry *e, struct pack_backend *backend, const git_oid *oid)
{ {
int error; int error;
size_t i; unsigned int i;
if ((error = packfile_refresh_all(backend)) < 0) if ((error = packfile_refresh_all(backend)) < 0)
return error; return error;
...@@ -298,7 +298,7 @@ static int pack_entry_find_prefix( ...@@ -298,7 +298,7 @@ static int pack_entry_find_prefix(
unsigned int len) unsigned int len)
{ {
int error; int error;
size_t i; unsigned int i;
unsigned found = 0; unsigned found = 0;
if ((error = packfile_refresh_all(backend)) < 0) if ((error = packfile_refresh_all(backend)) < 0)
...@@ -423,7 +423,7 @@ static int pack_backend__exists(git_odb_backend *backend, const git_oid *oid) ...@@ -423,7 +423,7 @@ static int pack_backend__exists(git_odb_backend *backend, const git_oid *oid)
static void pack_backend__free(git_odb_backend *_backend) static void pack_backend__free(git_odb_backend *_backend)
{ {
struct pack_backend *backend; struct pack_backend *backend;
size_t i; unsigned int i;
assert(_backend); assert(_backend);
......
...@@ -260,6 +260,8 @@ git_oid_shorten *git_oid_shorten_new(size_t min_length) ...@@ -260,6 +260,8 @@ git_oid_shorten *git_oid_shorten_new(size_t min_length)
{ {
git_oid_shorten *os; git_oid_shorten *os;
assert((size_t)((int)min_length) == min_length);
os = git__calloc(1, sizeof(git_oid_shorten)); os = git__calloc(1, sizeof(git_oid_shorten));
if (os == NULL) if (os == NULL)
return NULL; return NULL;
...@@ -270,7 +272,7 @@ git_oid_shorten *git_oid_shorten_new(size_t min_length) ...@@ -270,7 +272,7 @@ git_oid_shorten *git_oid_shorten_new(size_t min_length)
} }
os->node_count = 1; os->node_count = 1;
os->min_length = min_length; os->min_length = (int)min_length;
return os; return os;
} }
...@@ -328,7 +330,8 @@ void git_oid_shorten_free(git_oid_shorten *os) ...@@ -328,7 +330,8 @@ void git_oid_shorten_free(git_oid_shorten *os)
*/ */
int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid) int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid)
{ {
int i, is_leaf; int i;
bool is_leaf;
node_index idx; node_index idx;
if (os->full) if (os->full)
...@@ -338,7 +341,7 @@ int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid) ...@@ -338,7 +341,7 @@ int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid)
return os->min_length; return os->min_length;
idx = 0; idx = 0;
is_leaf = 0; is_leaf = false;
for (i = 0; i < GIT_OID_HEXSZ; ++i) { for (i = 0; i < GIT_OID_HEXSZ; ++i) {
int c = git__fromhex(text_oid[i]); int c = git__fromhex(text_oid[i]);
...@@ -368,11 +371,11 @@ int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid) ...@@ -368,11 +371,11 @@ int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid)
} }
idx = node->children[c]; idx = node->children[c];
is_leaf = 0; is_leaf = false;
if (idx < 0) { if (idx < 0) {
node->children[c] = idx = -idx; node->children[c] = idx = -idx;
is_leaf = 1; is_leaf = true;
} }
} }
......
...@@ -165,6 +165,7 @@ static int pack_index_open(struct git_pack_file *p) ...@@ -165,6 +165,7 @@ static int pack_index_open(struct git_pack_file *p)
{ {
char *idx_name; char *idx_name;
int error; int error;
size_t name_len, offset;
if (p->index_map.data) if (p->index_map.data)
return 0; return 0;
...@@ -172,7 +173,11 @@ static int pack_index_open(struct git_pack_file *p) ...@@ -172,7 +173,11 @@ static int pack_index_open(struct git_pack_file *p)
idx_name = git__strdup(p->pack_name); idx_name = git__strdup(p->pack_name);
GITERR_CHECK_ALLOC(idx_name); GITERR_CHECK_ALLOC(idx_name);
strcpy(idx_name + strlen(idx_name) - strlen(".pack"), ".idx"); name_len = strlen(idx_name);
offset = name_len - strlen(".pack");
assert(offset < name_len); /* make sure no underflow */
strncpy(idx_name + offset, ".idx", name_len - offset);
error = pack_index_check(idx_name, p); error = pack_index_check(idx_name, p);
git__free(idx_name); git__free(idx_name);
...@@ -501,7 +506,7 @@ git_off_t get_delta_base( ...@@ -501,7 +506,7 @@ git_off_t get_delta_base(
* *
***********************************************************/ ***********************************************************/
static struct git_pack_file *packfile_alloc(int extra) static struct git_pack_file *packfile_alloc(size_t extra)
{ {
struct git_pack_file *p = git__calloc(1, sizeof(*p) + extra); struct git_pack_file *p = git__calloc(1, sizeof(*p) + extra);
if (p != NULL) if (p != NULL)
......
...@@ -464,21 +464,22 @@ int git_path_find_dir(git_buf *dir, const char *path, const char *base) ...@@ -464,21 +464,22 @@ int git_path_find_dir(git_buf *dir, const char *path, const char *base)
return error; return error;
} }
int git_path_cmp(const char *name1, int len1, int isdir1, int git_path_cmp(
const char *name2, int len2, int isdir2) const char *name1, size_t len1, int isdir1,
const char *name2, size_t len2, int isdir2)
{ {
int len = len1 < len2 ? len1 : len2; size_t len = len1 < len2 ? len1 : len2;
int cmp; int cmp;
cmp = memcmp(name1, name2, len); cmp = memcmp(name1, name2, len);
if (cmp) if (cmp)
return cmp; return cmp;
if (len1 < len2) if (len1 < len2)
return ((!isdir1 && !isdir2) ? -1 : return (!isdir1 && !isdir2) ? -1 :
(isdir1 ? '/' - name2[len1] : name2[len1] - '/')); (isdir1 ? '/' - name2[len1] : name2[len1] - '/');
if (len1 > len2) if (len1 > len2)
return ((!isdir1 && !isdir2) ? 1 : return (!isdir1 && !isdir2) ? 1 :
(isdir2 ? name1[len2] - '/' : '/' - name1[len2])); (isdir2 ? name1[len2] - '/' : '/' - name1[len2]);
return 0; return 0;
} }
......
...@@ -204,8 +204,8 @@ extern int git_path_direach( ...@@ -204,8 +204,8 @@ extern int git_path_direach(
* Sort function to order two paths. * Sort function to order two paths.
*/ */
extern int git_path_cmp( extern int git_path_cmp(
const char *name1, int len1, int isdir1, const char *name1, size_t len1, int isdir1,
const char *name2, int len2, int isdir2); const char *name2, size_t len2, int isdir2);
/** /**
* Invoke callback up path directory by directory until the ceiling is * Invoke callback up path directory by directory until the ceiling is
......
...@@ -102,6 +102,7 @@ static int comment_pkt(git_pkt **out, const char *line, size_t len) ...@@ -102,6 +102,7 @@ static int comment_pkt(git_pkt **out, const char *line, size_t len)
*/ */
static int ref_pkt(git_pkt **out, const char *line, size_t len) static int ref_pkt(git_pkt **out, const char *line, size_t len)
{ {
int error;
git_pkt_ref *pkt; git_pkt_ref *pkt;
pkt = git__malloc(sizeof(git_pkt_ref)); pkt = git__malloc(sizeof(git_pkt_ref));
...@@ -109,14 +110,13 @@ static int ref_pkt(git_pkt **out, const char *line, size_t len) ...@@ -109,14 +110,13 @@ static int ref_pkt(git_pkt **out, const char *line, size_t len)
memset(pkt, 0x0, sizeof(git_pkt_ref)); memset(pkt, 0x0, sizeof(git_pkt_ref));
pkt->type = GIT_PKT_REF; pkt->type = GIT_PKT_REF;
if (git_oid_fromstr(&pkt->head.oid, line) < 0) { if ((error = git_oid_fromstr(&pkt->head.oid, line)) < 0)
giterr_set(GITERR_NET, "Error parsing pkt-line");
goto error_out; goto error_out;
}
/* Check for a bit of consistency */ /* Check for a bit of consistency */
if (line[GIT_OID_HEXSZ] != ' ') { if (line[GIT_OID_HEXSZ] != ' ') {
giterr_set(GITERR_NET, "Error parsing pkt-line"); giterr_set(GITERR_NET, "Error parsing pkt-line");
error = -1;
goto error_out; goto error_out;
} }
...@@ -138,30 +138,32 @@ static int ref_pkt(git_pkt **out, const char *line, size_t len) ...@@ -138,30 +138,32 @@ static int ref_pkt(git_pkt **out, const char *line, size_t len)
} }
*out = (git_pkt *)pkt; *out = (git_pkt *)pkt;
return 0; return 0;
error_out: error_out:
git__free(pkt); git__free(pkt);
return -1; return error;
} }
static int parse_len(const char *line) static int32_t parse_len(const char *line)
{ {
char num[PKT_LEN_SIZE + 1]; char num[PKT_LEN_SIZE + 1];
int i, len; int i, error;
int32_t len;
const char *num_end; const char *num_end;
memcpy(num, line, PKT_LEN_SIZE); memcpy(num, line, PKT_LEN_SIZE);
num[PKT_LEN_SIZE] = '\0'; num[PKT_LEN_SIZE] = '\0';
for (i = 0; i < PKT_LEN_SIZE; ++i) { for (i = 0; i < PKT_LEN_SIZE; ++i) {
if (!isxdigit(num[i])) if (!isxdigit(num[i])) {
return GIT_ENOTNUM; giterr_set(GITERR_NET, "Found invalid hex digit in length");
return -1;
}
} }
if (git__strtol32(&len, num, &num_end, 16) < 0) if ((error = git__strtol32(&len, num, &num_end, 16)) < 0)
return -1; return error;
return len; return len;
} }
...@@ -179,16 +181,20 @@ static int parse_len(const char *line) ...@@ -179,16 +181,20 @@ static int parse_len(const char *line)
* in ASCII hexadecimal (including itself) * in ASCII hexadecimal (including itself)
*/ */
int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_t bufflen) int git_pkt_parse_line(
git_pkt **head, const char *line, const char **out, size_t bufflen)
{ {
int ret = 0; int ret;
size_t len; int32_t len;
/* Not even enough for the length */ /* Not even enough for the length */
if (bufflen > 0 && bufflen < PKT_LEN_SIZE) if (bufflen > 0 && bufflen < PKT_LEN_SIZE) {
return GIT_ESHORTBUFFER; giterr_set(GITERR_NET, "Insufficient buffer data");
return -1;
}
if ((ret = parse_len(line)) < 0) { len = parse_len(line);
if (len < 0) {
/* /*
* If we fail to parse the length, it might be because the * If we fail to parse the length, it might be because the
* server is trying to send us the packfile already. * server is trying to send us the packfile already.
...@@ -198,18 +204,17 @@ int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_ ...@@ -198,18 +204,17 @@ int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_
return pack_pkt(head); return pack_pkt(head);
} }
giterr_set(GITERR_NET, "Error parsing pkt-line"); return (int)len;
return -1;
} }
len = ret;
/* /*
* If we were given a buffer length, then make sure there is * If we were given a buffer length, then make sure there is
* enough in the buffer to satisfy this line * enough in the buffer to satisfy this line
*/ */
if (bufflen > 0 && bufflen < len) if (bufflen > 0 && bufflen < (size_t)len) {
return GIT_ESHORTBUFFER; giterr_set(GITERR_NET, "Insufficient buffer data for packet length");
return -1;
}
line += PKT_LEN_SIZE; line += PKT_LEN_SIZE;
/* /*
...@@ -245,7 +250,7 @@ int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_ ...@@ -245,7 +250,7 @@ int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_
void git_pkt_free(git_pkt *pkt) void git_pkt_free(git_pkt *pkt)
{ {
if(pkt->type == GIT_PKT_REF) { if (pkt->type == GIT_PKT_REF) {
git_pkt_ref *p = (git_pkt_ref *) pkt; git_pkt_ref *p = (git_pkt_ref *) pkt;
git__free(p->head.name); git__free(p->head.name);
} }
...@@ -258,7 +263,7 @@ int git_pkt_buffer_flush(git_buf *buf) ...@@ -258,7 +263,7 @@ int git_pkt_buffer_flush(git_buf *buf)
return git_buf_put(buf, pkt_flush_str, strlen(pkt_flush_str)); return git_buf_put(buf, pkt_flush_str, strlen(pkt_flush_str));
} }
int git_pkt_send_flush(int s) int git_pkt_send_flush(GIT_SOCKET s)
{ {
return gitno_send(s, pkt_flush_str, strlen(pkt_flush_str), 0); return gitno_send(s, pkt_flush_str, strlen(pkt_flush_str), 0);
...@@ -268,12 +273,14 @@ static int buffer_want_with_caps(git_remote_head *head, git_transport_caps *caps ...@@ -268,12 +273,14 @@ static int buffer_want_with_caps(git_remote_head *head, git_transport_caps *caps
{ {
char capstr[20]; char capstr[20];
char oid[GIT_OID_HEXSZ +1] = {0}; char oid[GIT_OID_HEXSZ +1] = {0};
int len; unsigned int len;
if (caps->ofs_delta) if (caps->ofs_delta)
strcpy(capstr, GIT_CAP_OFS_DELTA); strncpy(capstr, GIT_CAP_OFS_DELTA, sizeof(capstr));
len = strlen("XXXXwant ") + GIT_OID_HEXSZ + 1 /* NUL */ + strlen(capstr) + 1 /* LF */; len = (unsigned int)
(strlen("XXXXwant ") + GIT_OID_HEXSZ + 1 /* NUL */ +
strlen(capstr) + 1 /* LF */);
git_buf_grow(buf, buf->size + len); git_buf_grow(buf, buf->size + len);
git_oid_fmt(oid, &head->oid); git_oid_fmt(oid, &head->oid);
...@@ -283,15 +290,14 @@ static int buffer_want_with_caps(git_remote_head *head, git_transport_caps *caps ...@@ -283,15 +290,14 @@ static int buffer_want_with_caps(git_remote_head *head, git_transport_caps *caps
static int send_want_with_caps(git_remote_head *head, git_transport_caps *caps, GIT_SOCKET fd) static int send_want_with_caps(git_remote_head *head, git_transport_caps *caps, GIT_SOCKET fd)
{ {
git_buf buf = GIT_BUF_INIT; git_buf buf = GIT_BUF_INIT;
int error; int ret;
if (buffer_want_with_caps(head, caps, &buf) < 0) if (buffer_want_with_caps(head, caps, &buf) < 0)
return -1; return -1;
error = gitno_send(fd, buf.ptr, buf.size, 0); ret = gitno_send(fd, buf.ptr, buf.size, 0);
git_buf_free(&buf); git_buf_free(&buf);
return ret;
return error;
} }
/* /*
...@@ -335,7 +341,7 @@ int git_pkt_buffer_wants(const git_vector *refs, git_transport_caps *caps, git_b ...@@ -335,7 +341,7 @@ int git_pkt_buffer_wants(const git_vector *refs, git_transport_caps *caps, git_b
return git_pkt_buffer_flush(buf); return git_pkt_buffer_flush(buf);
} }
int git_pkt_send_wants(const git_vector *refs, git_transport_caps *caps, int fd) int git_pkt_send_wants(const git_vector *refs, git_transport_caps *caps, GIT_SOCKET fd)
{ {
unsigned int i = 0; unsigned int i = 0;
char buf[sizeof(pkt_want_prefix) + GIT_OID_HEXSZ + 1]; char buf[sizeof(pkt_want_prefix) + GIT_OID_HEXSZ + 1];
...@@ -357,6 +363,7 @@ int git_pkt_send_wants(const git_vector *refs, git_transport_caps *caps, int fd) ...@@ -357,6 +363,7 @@ int git_pkt_send_wants(const git_vector *refs, git_transport_caps *caps, int fd)
if (send_want_with_caps(refs->contents[i], caps, fd) < 0) if (send_want_with_caps(refs->contents[i], caps, fd) < 0)
return -1; return -1;
/* Increase it here so it's correct whether we run this or not */ /* Increase it here so it's correct whether we run this or not */
i++; i++;
} }
...@@ -384,7 +391,7 @@ int git_pkt_buffer_have(git_oid *oid, git_buf *buf) ...@@ -384,7 +391,7 @@ int git_pkt_buffer_have(git_oid *oid, git_buf *buf)
return git_buf_printf(buf, "%s%s\n", pkt_have_prefix, oidhex); return git_buf_printf(buf, "%s%s\n", pkt_have_prefix, oidhex);
} }
int git_pkt_send_have(git_oid *oid, int fd) int git_pkt_send_have(git_oid *oid, GIT_SOCKET fd)
{ {
char buf[] = "0032have 0000000000000000000000000000000000000000\n"; char buf[] = "0032have 0000000000000000000000000000000000000000\n";
...@@ -398,7 +405,7 @@ int git_pkt_buffer_done(git_buf *buf) ...@@ -398,7 +405,7 @@ int git_pkt_buffer_done(git_buf *buf)
return git_buf_puts(buf, pkt_done_str); return git_buf_puts(buf, pkt_done_str);
} }
int git_pkt_send_done(int fd) int git_pkt_send_done(GIT_SOCKET fd)
{ {
return gitno_send(fd, pkt_done_str, strlen(pkt_done_str), 0); return gitno_send(fd, pkt_done_str, strlen(pkt_done_str), 0);
} }
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "common.h" #include "common.h"
#include "transport.h" #include "transport.h"
#include "buffer.h" #include "buffer.h"
#include "posix.h"
#include "git2/net.h" #include "git2/net.h"
enum git_pkt_type { enum git_pkt_type {
...@@ -65,13 +66,13 @@ typedef struct { ...@@ -65,13 +66,13 @@ typedef struct {
int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_t len); int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_t len);
int git_pkt_buffer_flush(git_buf *buf); int git_pkt_buffer_flush(git_buf *buf);
int git_pkt_send_flush(int s); int git_pkt_send_flush(GIT_SOCKET s);
int git_pkt_buffer_done(git_buf *buf); int git_pkt_buffer_done(git_buf *buf);
int git_pkt_send_done(int s); int git_pkt_send_done(GIT_SOCKET s);
int git_pkt_buffer_wants(const git_vector *refs, git_transport_caps *caps, git_buf *buf); int git_pkt_buffer_wants(const git_vector *refs, git_transport_caps *caps, git_buf *buf);
int git_pkt_send_wants(const git_vector *refs, git_transport_caps *caps, int fd); int git_pkt_send_wants(const git_vector *refs, git_transport_caps *caps, GIT_SOCKET fd);
int git_pkt_buffer_have(git_oid *oid, git_buf *buf); int git_pkt_buffer_have(git_oid *oid, git_buf *buf);
int git_pkt_send_have(git_oid *oid, int fd); int git_pkt_send_have(git_oid *oid, GIT_SOCKET fd);
void git_pkt_free(git_pkt *pkt); void git_pkt_free(git_pkt *pkt);
#endif #endif
...@@ -58,7 +58,13 @@ int p_read(git_file fd, void *buf, size_t cnt) ...@@ -58,7 +58,13 @@ int p_read(git_file fd, void *buf, size_t cnt)
{ {
char *b = buf; char *b = buf;
while (cnt) { while (cnt) {
ssize_t r = read(fd, b, cnt); ssize_t r;
#ifdef GIT_WIN32
assert((size_t)((unsigned int)cnt) == cnt);
r = read(fd, b, (unsigned int)cnt);
#else
r = read(fd, b, cnt);
#endif
if (r < 0) { if (r < 0) {
if (errno == EINTR || errno == EAGAIN) if (errno == EINTR || errno == EAGAIN)
continue; continue;
...@@ -76,7 +82,13 @@ int p_write(git_file fd, const void *buf, size_t cnt) ...@@ -76,7 +82,13 @@ int p_write(git_file fd, const void *buf, size_t cnt)
{ {
const char *b = buf; const char *b = buf;
while (cnt) { while (cnt) {
ssize_t r = write(fd, b, cnt); ssize_t r;
#ifdef GIT_WIN32
assert((size_t)((unsigned int)cnt) == cnt);
r = write(fd, b, (unsigned int)cnt);
#else
r = write(fd, b, cnt);
#endif
if (r < 0) { if (r < 0) {
if (errno == EINTR || errno == EAGAIN) if (errno == EINTR || errno == EAGAIN)
continue; continue;
......
...@@ -54,6 +54,14 @@ extern int p_rename(const char *from, const char *to); ...@@ -54,6 +54,14 @@ extern int p_rename(const char *from, const char *to);
#define p_rmdir(p) rmdir(p) #define p_rmdir(p) rmdir(p)
#define p_chmod(p,m) chmod(p, m) #define p_chmod(p,m) chmod(p, m)
#define p_access(p,m) access(p,m) #define p_access(p,m) access(p,m)
#define p_recv(s,b,l,f) recv(s,b,l,f)
#define p_send(s,b,l,f) send(s,b,l,f)
typedef int GIT_SOCKET;
#define INVALID_SOCKET -1
#else
typedef SOCKET GIT_SOCKET;
#endif #endif
......
...@@ -17,14 +17,14 @@ int git_pqueue_init(git_pqueue *q, size_t n, git_pqueue_cmp cmppri) ...@@ -17,14 +17,14 @@ int git_pqueue_init(git_pqueue *q, size_t n, git_pqueue_cmp cmppri)
assert(q); assert(q);
/* Need to allocate n+1 elements since element 0 isn't used. */ /* Need to allocate n+1 elements since element 0 isn't used. */
if ((q->d = git__malloc((n + 1) * sizeof(void *))) == NULL) q->d = git__malloc((n + 1) * sizeof(void *));
return GIT_ENOMEM; GITERR_CHECK_ALLOC(q->d);
q->size = 1; q->size = 1;
q->avail = q->step = (n + 1); /* see comment above about n+1 */ q->avail = q->step = (n + 1); /* see comment above about n+1 */
q->cmppri = cmppri; q->cmppri = cmppri;
return GIT_SUCCESS; return 0;
} }
...@@ -102,8 +102,8 @@ int git_pqueue_insert(git_pqueue *q, void *d) ...@@ -102,8 +102,8 @@ int git_pqueue_insert(git_pqueue *q, void *d)
/* allocate more memory if necessary */ /* allocate more memory if necessary */
if (q->size >= q->avail) { if (q->size >= q->avail) {
newsize = q->size + q->step; newsize = q->size + q->step;
if ((tmp = git__realloc(q->d, sizeof(void *) * newsize)) == NULL) tmp = git__realloc(q->d, sizeof(void *) * newsize);
return GIT_ENOMEM; GITERR_CHECK_ALLOC(tmp);
q->d = tmp; q->d = tmp;
q->avail = newsize; q->avail = newsize;
...@@ -114,7 +114,7 @@ int git_pqueue_insert(git_pqueue *q, void *d) ...@@ -114,7 +114,7 @@ int git_pqueue_insert(git_pqueue *q, void *d)
q->d[i] = d; q->d[i] = d;
bubble_up(q, i); bubble_up(q, i);
return GIT_SUCCESS; return 0;
} }
......
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
#include <git2/tag.h> #include <git2/tag.h>
#include <git2/object.h> #include <git2/object.h>
#define MAX_NESTING_LEVEL 5 #define DEFAULT_NESTING_LEVEL 5
#define MAX_NESTING_LEVEL 10
enum { enum {
GIT_PACKREF_HAS_PEEL = 1, GIT_PACKREF_HAS_PEEL = 1,
...@@ -132,13 +133,13 @@ static int reference_read( ...@@ -132,13 +133,13 @@ static int reference_read(
static int loose_parse_symbolic(git_reference *ref, git_buf *file_content) static int loose_parse_symbolic(git_reference *ref, git_buf *file_content)
{ {
const unsigned int header_len = strlen(GIT_SYMREF); const unsigned int header_len = (unsigned int)strlen(GIT_SYMREF);
const char *refname_start; const char *refname_start;
char *eol; char *eol;
refname_start = (const char *)file_content->ptr; refname_start = (const char *)file_content->ptr;
if (file_content->size < (header_len + 1)) if (file_content->size < header_len + 1)
goto corrupt; goto corrupt;
/* /*
...@@ -729,11 +730,11 @@ static int packed_write(git_repository *repo) ...@@ -729,11 +730,11 @@ static int packed_write(git_repository *repo)
unsigned int i; unsigned int i;
git_buf pack_file_path = GIT_BUF_INIT; git_buf pack_file_path = GIT_BUF_INIT;
git_vector packing_list; git_vector packing_list;
size_t total_refs; unsigned int total_refs;
assert(repo && repo->references.packfile); assert(repo && repo->references.packfile);
total_refs = repo->references.packfile->key_count; total_refs = (unsigned int)repo->references.packfile->key_count;
if (git_vector_init(&packing_list, total_refs, packed_sort) < 0) if (git_vector_init(&packing_list, total_refs, packed_sort) < 0)
return -1; return -1;
...@@ -820,9 +821,9 @@ static int _reference_available_cb(const char *ref, void *data) ...@@ -820,9 +821,9 @@ static int _reference_available_cb(const char *ref, void *data)
d = (struct reference_available_t *)data; d = (struct reference_available_t *)data;
if (!d->old_ref || strcmp(d->old_ref, ref)) { if (!d->old_ref || strcmp(d->old_ref, ref)) {
int reflen = strlen(ref); size_t reflen = strlen(ref);
int newlen = strlen(d->new_ref); size_t newlen = strlen(d->new_ref);
int cmplen = reflen < newlen ? reflen : newlen; size_t cmplen = reflen < newlen ? reflen : newlen;
const char *lead = reflen < newlen ? d->new_ref : ref; const char *lead = reflen < newlen ? d->new_ref : ref;
if (!strncmp(d->new_ref, ref, cmplen) && lead[cmplen] == '/') { if (!strncmp(d->new_ref, ref, cmplen) && lead[cmplen] == '/') {
...@@ -1057,24 +1058,80 @@ int git_reference_delete(git_reference *ref) ...@@ -1057,24 +1058,80 @@ int git_reference_delete(git_reference *ref)
int git_reference_lookup(git_reference **ref_out, int git_reference_lookup(git_reference **ref_out,
git_repository *repo, const char *name) git_repository *repo, const char *name)
{ {
char normalized_name[GIT_REFNAME_MAX]; return git_reference_lookup_resolved(ref_out, repo, name, 0);
git_reference *ref = NULL; }
int result;
int git_reference_name_to_oid(
git_oid *out, git_repository *repo, const char *name)
{
int error;
git_reference *ref;
if ((error = git_reference_lookup_resolved(&ref, repo, name, -1)) < 0)
return error;
git_oid_cpy(out, git_reference_oid(ref));
git_reference_free(ref);
return 0;
}
int git_reference_lookup_resolved(
git_reference **ref_out,
git_repository *repo,
const char *name,
int max_nesting)
{
git_reference *scan;
int result, nesting;
assert(ref_out && repo && name); assert(ref_out && repo && name);
*ref_out = NULL; *ref_out = NULL;
if (normalize_name(normalized_name, sizeof(normalized_name), name, 0) < 0) if (max_nesting > MAX_NESTING_LEVEL)
return -1; max_nesting = MAX_NESTING_LEVEL;
else if (max_nesting < 0)
max_nesting = DEFAULT_NESTING_LEVEL;
if (reference_alloc(&ref, repo, normalized_name) < 0) scan = git__calloc(1, sizeof(git_reference));
return -1; GITERR_CHECK_ALLOC(scan);
result = reference_lookup(ref); scan->name = git__calloc(GIT_REFNAME_MAX + 1, sizeof(char));
if (result == 0) GITERR_CHECK_ALLOC(scan->name);
*ref_out = ref;
return result; if ((result = normalize_name(scan->name, GIT_REFNAME_MAX, name, 0)) < 0) {
git_reference_free(scan);
return result;
}
scan->target.symbolic = git__strdup(scan->name);
GITERR_CHECK_ALLOC(scan->target.symbolic);
scan->owner = repo;
scan->flags = GIT_REF_SYMBOLIC;
for (nesting = max_nesting;
nesting >= 0 && (scan->flags & GIT_REF_SYMBOLIC) != 0;
nesting--)
{
if (nesting != max_nesting)
strncpy(scan->name, scan->target.symbolic, GIT_REFNAME_MAX);
scan->mtime = 0;
if ((result = reference_lookup(scan)) < 0)
return result; /* lookup git_reference_free on scan already */
}
if ((scan->flags & GIT_REF_OID) == 0 && max_nesting != 0) {
giterr_set(GITERR_REFERENCE,
"Cannot resolve reference (>%u levels deep)", max_nesting);
git_reference_free(scan);
return -1;
}
*ref_out = scan;
return 0;
} }
/** /**
...@@ -1381,47 +1438,10 @@ rollback: ...@@ -1381,47 +1438,10 @@ rollback:
int git_reference_resolve(git_reference **ref_out, git_reference *ref) int git_reference_resolve(git_reference **ref_out, git_reference *ref)
{ {
int result, i = 0;
git_repository *repo;
assert(ref);
*ref_out = NULL;
repo = ref->owner;
/* If the reference is already resolved, we need to return a
* copy. Instead of duplicating `ref`, we look it up again to
* ensure the copy is out to date */
if (ref->flags & GIT_REF_OID) if (ref->flags & GIT_REF_OID)
return git_reference_lookup(ref_out, ref->owner, ref->name); return git_reference_lookup(ref_out, ref->owner, ref->name);
else
/* Otherwise, keep iterating until the reference is resolved */ return git_reference_lookup_resolved(ref_out, ref->owner, ref->target.symbolic, -1);
for (i = 0; i < MAX_NESTING_LEVEL; ++i) {
git_reference *new_ref;
result = git_reference_lookup(&new_ref, repo, ref->target.symbolic);
if (result < 0)
return result;
/* Free intermediate references, except for the original one
* we've received */
if (i > 0)
git_reference_free(ref);
ref = new_ref;
/* When the reference we've just looked up is an OID, we've
* successfully resolved the symbolic ref */
if (ref->flags & GIT_REF_OID) {
*ref_out = ref;
return 0;
}
}
giterr_set(GITERR_REFERENCE,
"Symbolic reference too nested (%d levels deep)", MAX_NESTING_LEVEL);
return -1;
} }
int git_reference_packall(git_repository *repo) int git_reference_packall(git_repository *repo)
...@@ -1649,3 +1669,20 @@ int git_reference__normalize_name_oid( ...@@ -1649,3 +1669,20 @@ int git_reference__normalize_name_oid(
{ {
return normalize_name(buffer_out, out_size, name, 1); return normalize_name(buffer_out, out_size, name, 1);
} }
#define GIT_REF_TYPEMASK (GIT_REF_OID | GIT_REF_SYMBOLIC)
int git_reference_cmp(git_reference *ref1, git_reference *ref2)
{
assert(ref1 && ref2);
/* let's put symbolic refs before OIDs */
if ((ref1->flags & GIT_REF_TYPEMASK) != (ref2->flags & GIT_REF_TYPEMASK))
return (ref1->flags & GIT_REF_SYMBOLIC) ? -1 : 1;
if (ref1->flags & GIT_REF_SYMBOLIC)
return strcmp(ref1->target.symbolic, ref2->target.symbolic);
return git_oid_cmp(&ref1->target.oid, &ref2->target.oid);
}
...@@ -55,4 +55,27 @@ void git_repository__refcache_free(git_refcache *refs); ...@@ -55,4 +55,27 @@ void git_repository__refcache_free(git_refcache *refs);
int git_reference__normalize_name(char *buffer_out, size_t out_size, const char *name); int git_reference__normalize_name(char *buffer_out, size_t out_size, const char *name);
int git_reference__normalize_name_oid(char *buffer_out, size_t out_size, const char *name); int git_reference__normalize_name_oid(char *buffer_out, size_t out_size, const char *name);
/**
* Lookup a reference by name and try to resolve to an OID.
*
* You can control how many dereferences this will attempt to resolve the
* reference with the `max_deref` parameter, or pass -1 to use a sane
* default. If you pass 0 for `max_deref`, this will not attempt to resolve
* the reference. For any value of `max_deref` other than 0, not
* successfully resolving the reference will be reported as an error.
* The generated reference must be freed by the user.
*
* @param reference_out Pointer to the looked-up reference
* @param repo The repository to look up the reference
* @param name The long name for the reference (e.g. HEAD, ref/heads/master, refs/tags/v0.1.0, ...)
* @param max_deref Maximum number of dereferences to make of symbolic refs, 0 means simple lookup, < 0 means use default reasonable value
* @return 0 on success or < 0 on error; not being able to resolve the reference is an error unless 0 was passed for max_deref
*/
int git_reference_lookup_resolved(
git_reference **reference_out,
git_repository *repo,
const char *name,
int max_deref);
#endif #endif
...@@ -183,21 +183,20 @@ static int find_ceiling_dir_offset( ...@@ -183,21 +183,20 @@ static int find_ceiling_dir_offset(
char buf[GIT_PATH_MAX + 1]; char buf[GIT_PATH_MAX + 1];
char buf2[GIT_PATH_MAX + 1]; char buf2[GIT_PATH_MAX + 1];
const char *ceil, *sep; const char *ceil, *sep;
int len, max_len = -1; size_t len, max_len = 0, min_len;
int min_len;
assert(path); assert(path);
min_len = git_path_root(path) + 1; min_len = (size_t)(git_path_root(path) + 1);
if (ceiling_directories == NULL || min_len == 0) if (ceiling_directories == NULL || min_len == 0)
return min_len; return (int)min_len;
for (sep = ceil = ceiling_directories; *sep; ceil = sep + 1) { for (sep = ceil = ceiling_directories; *sep; ceil = sep + 1) {
for (sep = ceil; *sep && *sep != GIT_PATH_LIST_SEPARATOR; sep++); for (sep = ceil; *sep && *sep != GIT_PATH_LIST_SEPARATOR; sep++);
len = sep - ceil; len = sep - ceil;
if (len == 0 || len >= (int)sizeof(buf) || git_path_root(ceil) == -1) if (len == 0 || len >= sizeof(buf) || git_path_root(ceil) == -1)
continue; continue;
strncpy(buf, ceil, len); strncpy(buf, ceil, len);
...@@ -218,7 +217,7 @@ static int find_ceiling_dir_offset( ...@@ -218,7 +217,7 @@ static int find_ceiling_dir_offset(
} }
} }
return max_len <= min_len ? min_len : max_len; return (int)(max_len <= min_len ? min_len : max_len);
} }
/* /*
...@@ -774,24 +773,7 @@ int git_repository_head_detached(git_repository *repo) ...@@ -774,24 +773,7 @@ int git_repository_head_detached(git_repository *repo)
int git_repository_head(git_reference **head_out, git_repository *repo) int git_repository_head(git_reference **head_out, git_repository *repo)
{ {
git_reference *ref, *resolved_ref; return git_reference_lookup_resolved(head_out, repo, GIT_HEAD_FILE, -1);
int error;
*head_out = NULL;
error = git_reference_lookup(&ref, repo, GIT_HEAD_FILE);
if (error < 0)
return error;
error = git_reference_resolve(&resolved_ref, ref);
if (error < 0) {
git_reference_free(ref);
return error;
}
git_reference_free(ref);
*head_out = resolved_ref;
return 0;
} }
int git_repository_head_orphan(git_repository *repo) int git_repository_head_orphan(git_repository *repo)
......
...@@ -77,11 +77,10 @@ static int commit_time_cmp(void *a, void *b) ...@@ -77,11 +77,10 @@ static int commit_time_cmp(void *a, void *b)
static commit_list *commit_list_insert(commit_object *item, commit_list **list_p) static commit_list *commit_list_insert(commit_object *item, commit_list **list_p)
{ {
commit_list *new_list = git__malloc(sizeof(commit_list)); commit_list *new_list = git__malloc(sizeof(commit_list));
if (new_list == NULL) if (new_list != NULL) {
return NULL; new_list->item = item;
new_list->next = *list_p;
new_list->item = item; }
new_list->next = *list_p;
*list_p = new_list; *list_p = new_list;
return new_list; return new_list;
} }
...@@ -143,8 +142,7 @@ static int alloc_chunk(git_revwalk *walk) ...@@ -143,8 +142,7 @@ static int alloc_chunk(git_revwalk *walk)
void *chunk; void *chunk;
chunk = git__calloc(COMMITS_PER_CHUNK, CHUNK_STEP); chunk = git__calloc(COMMITS_PER_CHUNK, CHUNK_STEP);
if (chunk == NULL) GITERR_CHECK_ALLOC(chunk);
return GIT_ENOMEM;
walk->chunk_size = 0; walk->chunk_size = 0;
return git_vector_insert(&walk->memory_alloc, chunk); return git_vector_insert(&walk->memory_alloc, chunk);
...@@ -155,7 +153,8 @@ static commit_object *alloc_commit(git_revwalk *walk) ...@@ -155,7 +153,8 @@ static commit_object *alloc_commit(git_revwalk *walk)
unsigned char *chunk; unsigned char *chunk;
if (walk->chunk_size == COMMITS_PER_CHUNK) if (walk->chunk_size == COMMITS_PER_CHUNK)
alloc_chunk(walk); if (alloc_chunk(walk) < 0)
return NULL;
chunk = git_vector_get(&walk->memory_alloc, walk->memory_alloc.length - 1); chunk = git_vector_get(&walk->memory_alloc, walk->memory_alloc.length - 1);
chunk += (walk->chunk_size * CHUNK_STEP); chunk += (walk->chunk_size * CHUNK_STEP);
...@@ -186,7 +185,7 @@ static commit_object *commit_lookup(git_revwalk *walk, const git_oid *oid) ...@@ -186,7 +185,7 @@ static commit_object *commit_lookup(git_revwalk *walk, const git_oid *oid)
git_oid_cpy(&commit->oid, oid); git_oid_cpy(&commit->oid, oid);
if (git_hashtable_insert(walk->commits, &commit->oid, commit) < GIT_SUCCESS) { if (git_hashtable_insert(walk->commits, &commit->oid, commit) < 0) {
git__free(commit); git__free(commit);
return NULL; return NULL;
} }
...@@ -196,7 +195,7 @@ static commit_object *commit_lookup(git_revwalk *walk, const git_oid *oid) ...@@ -196,7 +195,7 @@ static commit_object *commit_lookup(git_revwalk *walk, const git_oid *oid)
static int commit_quick_parse(git_revwalk *walk, commit_object *commit, git_rawobj *raw) static int commit_quick_parse(git_revwalk *walk, commit_object *commit, git_rawobj *raw)
{ {
const int parent_len = strlen("parent ") + GIT_OID_HEXSZ + 1; const size_t parent_len = strlen("parent ") + GIT_OID_HEXSZ + 1;
unsigned char *buffer = raw->data; unsigned char *buffer = raw->data;
unsigned char *buffer_end = buffer + raw->len; unsigned char *buffer_end = buffer + raw->len;
...@@ -262,7 +261,7 @@ static int commit_parse(git_revwalk *walk, commit_object *commit) ...@@ -262,7 +261,7 @@ static int commit_parse(git_revwalk *walk, commit_object *commit)
return 0; return 0;
if ((error = git_odb_read(&obj, walk->odb, &commit->oid)) < 0) if ((error = git_odb_read(&obj, walk->odb, &commit->oid)) < 0)
return -1; return error;
if (obj->raw.type != GIT_OBJ_COMMIT) { if (obj->raw.type != GIT_OBJ_COMMIT) {
git_odb_object_free(obj); git_odb_object_free(obj);
...@@ -432,6 +431,8 @@ static void mark_uninteresting(commit_object *commit) ...@@ -432,6 +431,8 @@ static void mark_uninteresting(commit_object *commit)
static int process_commit(git_revwalk *walk, commit_object *commit, int hide) static int process_commit(git_revwalk *walk, commit_object *commit, int hide)
{ {
int error;
if (hide) if (hide)
mark_uninteresting(commit); mark_uninteresting(commit);
...@@ -440,8 +441,8 @@ static int process_commit(git_revwalk *walk, commit_object *commit, int hide) ...@@ -440,8 +441,8 @@ static int process_commit(git_revwalk *walk, commit_object *commit, int hide)
commit->seen = 1; commit->seen = 1;
if (commit_parse(walk, commit) < 0) if ((error = commit_parse(walk, commit)) < 0)
return -1; return error;
return walk->enqueue(walk, commit); return walk->enqueue(walk, commit);
} }
...@@ -449,13 +450,12 @@ static int process_commit(git_revwalk *walk, commit_object *commit, int hide) ...@@ -449,13 +450,12 @@ static int process_commit(git_revwalk *walk, commit_object *commit, int hide)
static int process_commit_parents(git_revwalk *walk, commit_object *commit) static int process_commit_parents(git_revwalk *walk, commit_object *commit)
{ {
unsigned short i; unsigned short i;
int error = 0;
for (i = 0; i < commit->out_degree; ++i) { for (i = 0; i < commit->out_degree && !error; ++i)
if (process_commit(walk, commit->parents[i], commit->uninteresting) < 0) error = process_commit(walk, commit->parents[i], commit->uninteresting);
return -1;
}
return 0; return error;
} }
static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting) static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting)
...@@ -464,7 +464,7 @@ static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting) ...@@ -464,7 +464,7 @@ static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting)
commit = commit_lookup(walk, oid); commit = commit_lookup(walk, oid);
if (commit == NULL) if (commit == NULL)
return -1; return -1; /* error already reported by failed lookup */
commit->uninteresting = uninteresting; commit->uninteresting = uninteresting;
if (walk->one == NULL && !uninteresting) { if (walk->one == NULL && !uninteresting) {
...@@ -492,21 +492,12 @@ int git_revwalk_hide(git_revwalk *walk, const git_oid *oid) ...@@ -492,21 +492,12 @@ int git_revwalk_hide(git_revwalk *walk, const git_oid *oid)
static int push_ref(git_revwalk *walk, const char *refname, int hide) static int push_ref(git_revwalk *walk, const char *refname, int hide)
{ {
git_reference *ref, *resolved; git_oid oid;
int error;
if (git_reference_lookup(&ref, walk->repo, refname) < 0)
return -1;
error = git_reference_resolve(&resolved, ref); if (git_reference_name_to_oid(&oid, walk->repo, refname) < 0)
git_reference_free(ref);
if (error < 0)
return -1; return -1;
error = push_commit(walk, git_reference_oid(resolved), hide); return push_commit(walk, &oid, hide);
git_reference_free(resolved);
return error;
} }
struct push_cb_data { struct push_cb_data {
...@@ -558,7 +549,8 @@ static int push_glob(git_revwalk *walk, const char *glob, int hide) ...@@ -558,7 +549,8 @@ static int push_glob(git_revwalk *walk, const char *glob, int hide)
data.glob = git_buf_cstr(&buf); data.glob = git_buf_cstr(&buf);
data.hide = hide; data.hide = hide;
if (git_reference_foreach(walk->repo, GIT_REF_LISTALL, push_glob_cb, &data) < 0) if (git_reference_foreach(
walk->repo, GIT_REF_LISTALL, push_glob_cb, &data) < 0)
goto on_error; goto on_error;
regfree(&preg); regfree(&preg);
...@@ -614,7 +606,7 @@ static int revwalk_enqueue_timesort(git_revwalk *walk, commit_object *commit) ...@@ -614,7 +606,7 @@ static int revwalk_enqueue_timesort(git_revwalk *walk, commit_object *commit)
static int revwalk_enqueue_unsorted(git_revwalk *walk, commit_object *commit) static int revwalk_enqueue_unsorted(git_revwalk *walk, commit_object *commit)
{ {
return commit_list_insert(commit, &walk->iterator_rand) ? GIT_SUCCESS : GIT_ENOMEM; return commit_list_insert(commit, &walk->iterator_rand) ? 0 : -1;
} }
static int revwalk_next_timesort(commit_object **object_out, git_revwalk *walk) static int revwalk_next_timesort(commit_object **object_out, git_revwalk *walk)
...@@ -624,7 +616,7 @@ static int revwalk_next_timesort(commit_object **object_out, git_revwalk *walk) ...@@ -624,7 +616,7 @@ static int revwalk_next_timesort(commit_object **object_out, git_revwalk *walk)
while ((next = git_pqueue_pop(&walk->iterator_time)) != NULL) { while ((next = git_pqueue_pop(&walk->iterator_time)) != NULL) {
if ((error = process_commit_parents(walk, next)) < 0) if ((error = process_commit_parents(walk, next)) < 0)
return -1; return error;
if (!next->uninteresting) { if (!next->uninteresting) {
*object_out = next; *object_out = next;
...@@ -642,7 +634,7 @@ static int revwalk_next_unsorted(commit_object **object_out, git_revwalk *walk) ...@@ -642,7 +634,7 @@ static int revwalk_next_unsorted(commit_object **object_out, git_revwalk *walk)
while ((next = commit_list_pop(&walk->iterator_rand)) != NULL) { while ((next = commit_list_pop(&walk->iterator_rand)) != NULL) {
if ((error = process_commit_parents(walk, next)) < 0) if ((error = process_commit_parents(walk, next)) < 0)
return -1; return error;
if (!next->uninteresting) { if (!next->uninteresting) {
*object_out = next; *object_out = next;
...@@ -724,19 +716,19 @@ static int prepare_walk(git_revwalk *walk) ...@@ -724,19 +716,19 @@ static int prepare_walk(git_revwalk *walk)
} }
if (error != GIT_EREVWALKOVER) if (error != GIT_EREVWALKOVER)
return -1; return error;
walk->get_next = &revwalk_next_toposort; walk->get_next = &revwalk_next_toposort;
} }
if (walk->sorting & GIT_SORT_REVERSE) { if (walk->sorting & GIT_SORT_REVERSE) {
while ((error = walk->get_next(&next, walk)) == GIT_SUCCESS) while ((error = walk->get_next(&next, walk)) == 0)
if (commit_list_insert(next, &walk->iterator_reverse) == NULL) if (commit_list_insert(next, &walk->iterator_reverse) == NULL)
return -1; return -1;
if (error != GIT_EREVWALKOVER) if (error != GIT_EREVWALKOVER)
return -1; return error;
walk->get_next = &revwalk_next_reverse; walk->get_next = &revwalk_next_reverse;
} }
...@@ -761,16 +753,13 @@ int git_revwalk_new(git_revwalk **revwalk_out, git_repository *repo) ...@@ -761,16 +753,13 @@ int git_revwalk_new(git_revwalk **revwalk_out, git_repository *repo)
walk->commits = git_hashtable_alloc(64, walk->commits = git_hashtable_alloc(64,
object_table_hash, object_table_hash,
(git_hash_keyeq_ptr)git_oid_cmp); (git_hash_keyeq_ptr)git_oid_cmp);
GITERR_CHECK_ALLOC(walk->commits);
if (walk->commits == NULL) { if (git_pqueue_init(&walk->iterator_time, 8, commit_time_cmp) < 0 ||
git__free(walk); git_vector_init(&walk->memory_alloc, 8, NULL) < 0 ||
git_vector_init(&walk->twos, 4, NULL) < 0 ||
alloc_chunk(walk) < 0)
return -1; return -1;
}
git_pqueue_init(&walk->iterator_time, 8, commit_time_cmp);
git_vector_init(&walk->memory_alloc, 8, NULL);
git_vector_init(&walk->twos, 4, NULL);
alloc_chunk(walk);
walk->get_next = &revwalk_next_unsorted; walk->get_next = &revwalk_next_unsorted;
walk->enqueue = &revwalk_enqueue_unsorted; walk->enqueue = &revwalk_enqueue_unsorted;
...@@ -849,7 +838,7 @@ int git_revwalk_next(git_oid *oid, git_revwalk *walk) ...@@ -849,7 +838,7 @@ int git_revwalk_next(git_oid *oid, git_revwalk *walk)
if (!walk->walking) { if (!walk->walking) {
if ((error = prepare_walk(walk)) < 0) if ((error = prepare_walk(walk)) < 0)
return -1; return error;
} }
error = walk->get_next(&next, walk); error = walk->get_next(&next, walk);
...@@ -859,11 +848,10 @@ int git_revwalk_next(git_oid *oid, git_revwalk *walk) ...@@ -859,11 +848,10 @@ int git_revwalk_next(git_oid *oid, git_revwalk *walk)
return GIT_EREVWALKOVER; return GIT_EREVWALKOVER;
} }
if (error < 0) if (!error)
return -1; git_oid_cpy(oid, &next->oid);
git_oid_cpy(oid, &next->oid); return error;
return 0;
} }
void git_revwalk_reset(git_revwalk *walk) void git_revwalk_reset(git_revwalk *walk)
......
...@@ -232,7 +232,7 @@ void git__blk_SHA1_Init(blk_SHA_CTX *ctx) ...@@ -232,7 +232,7 @@ void git__blk_SHA1_Init(blk_SHA_CTX *ctx)
ctx->H[4] = 0xc3d2e1f0; ctx->H[4] = 0xc3d2e1f0;
} }
void git__blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, unsigned long len) void git__blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, size_t len)
{ {
unsigned int lenW = ctx->size & 63; unsigned int lenW = ctx->size & 63;
...@@ -242,7 +242,7 @@ void git__blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, unsigned long len) ...@@ -242,7 +242,7 @@ void git__blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, unsigned long len)
if (lenW) { if (lenW) {
unsigned int left = 64 - lenW; unsigned int left = 64 - lenW;
if (len < left) if (len < left)
left = len; left = (unsigned int)len;
memcpy(lenW + (char *)ctx->W, data, left); memcpy(lenW + (char *)ctx->W, data, left);
lenW = (lenW + left) & 63; lenW = (lenW + left) & 63;
len -= left; len -= left;
......
...@@ -12,7 +12,7 @@ typedef struct { ...@@ -12,7 +12,7 @@ typedef struct {
} blk_SHA_CTX; } blk_SHA_CTX;
void git__blk_SHA1_Init(blk_SHA_CTX *ctx); void git__blk_SHA1_Init(blk_SHA_CTX *ctx);
void git__blk_SHA1_Update(blk_SHA_CTX *ctx, const void *dataIn, unsigned long len); void git__blk_SHA1_Update(blk_SHA_CTX *ctx, const void *dataIn, size_t len);
void git__blk_SHA1_Final(unsigned char hashout[20], blk_SHA_CTX *ctx); void git__blk_SHA1_Final(unsigned char hashout[20], blk_SHA_CTX *ctx);
#define SHA_CTX blk_SHA_CTX #define SHA_CTX blk_SHA_CTX
......
...@@ -47,7 +47,7 @@ static int signature_error(const char *msg) ...@@ -47,7 +47,7 @@ static int signature_error(const char *msg)
static int process_trimming(const char *input, char **storage, const char *input_end, int fail_when_empty) static int process_trimming(const char *input, char **storage, const char *input_end, int fail_when_empty)
{ {
const char *left, *right; const char *left, *right;
int trimmed_input_length; size_t trimmed_input_length;
assert(storage); assert(storage);
......
...@@ -67,7 +67,8 @@ int git_tag__parse_buffer(git_tag *tag, const char *buffer, size_t length) ...@@ -67,7 +67,8 @@ int git_tag__parse_buffer(git_tag *tag, const char *buffer, size_t length)
NULL, "commit\n", "tree\n", "blob\n", "tag\n" NULL, "commit\n", "tree\n", "blob\n", "tag\n"
}; };
unsigned int i, text_len; unsigned int i;
size_t text_len;
char *search; char *search;
int error; int error;
......
...@@ -46,7 +46,7 @@ static int gen_proto(git_buf *request, const char *cmd, const char *url) ...@@ -46,7 +46,7 @@ static int gen_proto(git_buf *request, const char *cmd, const char *url)
char *delim, *repo; char *delim, *repo;
char default_command[] = "git-upload-pack"; char default_command[] = "git-upload-pack";
char host[] = "host="; char host[] = "host=";
int len; size_t len;
delim = strchr(url, '/'); delim = strchr(url, '/');
if (delim == NULL) { if (delim == NULL) {
...@@ -66,7 +66,8 @@ static int gen_proto(git_buf *request, const char *cmd, const char *url) ...@@ -66,7 +66,8 @@ static int gen_proto(git_buf *request, const char *cmd, const char *url)
len = 4 + strlen(cmd) + 1 + strlen(repo) + 1 + strlen(host) + (delim - url) + 1; len = 4 + strlen(cmd) + 1 + strlen(repo) + 1 + strlen(host) + (delim - url) + 1;
git_buf_grow(request, len); git_buf_grow(request, len);
git_buf_printf(request, "%04x%s %s%c%s", len, cmd, repo, 0, host); git_buf_printf(request, "%04x%s %s%c%s",
(unsigned int)(len & 0x0FFFF), cmd, repo, 0, host);
git_buf_put(request, url, delim - url); git_buf_put(request, url, delim - url);
git_buf_putc(request, '\0'); git_buf_putc(request, '\0');
...@@ -119,7 +120,7 @@ static int do_connect(transport_git *t, const char *url) ...@@ -119,7 +120,7 @@ static int do_connect(transport_git *t, const char *url)
git__free(port); git__free(port);
if (error < GIT_SUCCESS && s > 0) if (error < GIT_SUCCESS && s > 0)
close(s); gitno_close(s);
if (!connected) { if (!connected) {
giterr_set(GITERR_NET, "Failed to connect to the host"); giterr_set(GITERR_NET, "Failed to connect to the host");
return -1; return -1;
......
...@@ -32,7 +32,7 @@ typedef struct { ...@@ -32,7 +32,7 @@ typedef struct {
git_protocol proto; git_protocol proto;
git_vector refs; git_vector refs;
git_vector common; git_vector common;
int socket; GIT_SOCKET socket;
git_buf buf; git_buf buf;
git_remote_head **heads; git_remote_head **heads;
int error; int error;
...@@ -96,7 +96,7 @@ static int do_connect(transport_http *t, const char *host, const char *port) ...@@ -96,7 +96,7 @@ static int do_connect(transport_http *t, const char *host, const char *port)
t->socket = s; t->socket = s;
t->parent.connected = 1; t->parent.connected = 1;
return GIT_SUCCESS; return 0;
} }
/* /*
......
...@@ -26,31 +26,22 @@ static int add_ref(transport_local *t, const char *name) ...@@ -26,31 +26,22 @@ static int add_ref(transport_local *t, const char *name)
{ {
const char peeled[] = "^{}"; const char peeled[] = "^{}";
git_remote_head *head; git_remote_head *head;
git_reference *ref = NULL, *resolved_ref = NULL;
git_object *obj = NULL, *target = NULL; git_object *obj = NULL, *target = NULL;
git_buf buf = GIT_BUF_INIT; git_buf buf = GIT_BUF_INIT;
if (git_reference_lookup(&ref, t->repo, name) < 0)
return -1;
if (git_reference_resolve(&resolved_ref, ref) < 0) {
git_reference_free(ref);
return -1;
}
head = git__malloc(sizeof(git_remote_head)); head = git__malloc(sizeof(git_remote_head));
GITERR_CHECK_ALLOC(head); GITERR_CHECK_ALLOC(head);
head->name = git__strdup(name); head->name = git__strdup(name);
GITERR_CHECK_ALLOC(head->name); GITERR_CHECK_ALLOC(head->name);
git_oid_cpy(&head->oid, git_reference_oid(resolved_ref)); if (git_reference_name_to_oid(&head->oid, t->repo, name) < 0 ||
git_vector_insert(&t->refs, head) < 0)
if (git_vector_insert(&t->refs, head) < 0) {
git__free(head->name);
git__free(head);
return -1; return -1;
}
git_reference_free(ref);
git_reference_free(resolved_ref);
/* If it's not a tag, we don't need to try to peel it */ /* If it's not a tag, we don't need to try to peel it */
if (git__prefixcmp(name, GIT_REFS_TAGS_DIR)) if (git__prefixcmp(name, GIT_REFS_TAGS_DIR))
...@@ -100,10 +91,8 @@ static int store_refs(transport_local *t) ...@@ -100,10 +91,8 @@ static int store_refs(transport_local *t)
assert(t); assert(t);
if (git_vector_init(&t->refs, ref_names.count, NULL) < 0) if (git_reference_listall(&ref_names, t->repo, GIT_REF_LISTALL) < 0 ||
return -1; git_vector_init(&t->refs, (unsigned int)ref_names.count, NULL) < 0)
if (git_reference_listall(&ref_names, t->repo, GIT_REF_LISTALL) < 0)
goto on_error; goto on_error;
/* Sort the references first */ /* Sort the references first */
......
...@@ -624,7 +624,7 @@ static int tree_frompath( ...@@ -624,7 +624,7 @@ static int tree_frompath(
git_tree **parent_out, git_tree **parent_out,
git_tree *root, git_tree *root,
git_buf *treeentry_path, git_buf *treeentry_path,
int offset) size_t offset)
{ {
char *slash_pos = NULL; char *slash_pos = NULL;
const git_tree_entry* entry; const git_tree_entry* entry;
......
...@@ -30,8 +30,10 @@ static int binsearch(void **dst, const void *x, size_t size, cmp_ptr_t cmp) ...@@ -30,8 +30,10 @@ static int binsearch(void **dst, const void *x, size_t size, cmp_ptr_t cmp)
int l, c, r; int l, c, r;
void *lx, *cx; void *lx, *cx;
assert(size > 0);
l = 0; l = 0;
r = size - 1; r = (int)size - 1;
c = r >> 1; c = r >> 1;
lx = dst[l]; lx = dst[l];
...@@ -84,7 +86,7 @@ static void bisort(void **dst, size_t start, size_t size, cmp_ptr_t cmp) ...@@ -84,7 +86,7 @@ static void bisort(void **dst, size_t start, size_t size, cmp_ptr_t cmp)
/* Else we need to find the right place, shift everything over, and squeeze in */ /* Else we need to find the right place, shift everything over, and squeeze in */
x = dst[i]; x = dst[i];
location = binsearch(dst, x, i, cmp); location = binsearch(dst, x, i, cmp);
for (j = i - 1; j >= location; j--) { for (j = (int)i - 1; j >= location; j--) {
dst[j + 1] = dst[j]; dst[j + 1] = dst[j];
} }
dst[location] = x; dst[location] = x;
...@@ -104,7 +106,7 @@ struct tsort_store { ...@@ -104,7 +106,7 @@ struct tsort_store {
void **storage; void **storage;
}; };
static void reverse_elements(void **dst, int start, int end) static void reverse_elements(void **dst, ssize_t start, ssize_t end)
{ {
while (start < end) { while (start < end) {
void *tmp = dst[start]; void *tmp = dst[start];
...@@ -116,7 +118,7 @@ static void reverse_elements(void **dst, int start, int end) ...@@ -116,7 +118,7 @@ static void reverse_elements(void **dst, int start, int end)
} }
} }
static int count_run(void **dst, ssize_t start, ssize_t size, struct tsort_store *store) static ssize_t count_run(void **dst, ssize_t start, ssize_t size, struct tsort_store *store)
{ {
ssize_t curr = start + 2; ssize_t curr = start + 2;
...@@ -148,7 +150,7 @@ static int count_run(void **dst, ssize_t start, ssize_t size, struct tsort_store ...@@ -148,7 +150,7 @@ static int count_run(void **dst, ssize_t start, ssize_t size, struct tsort_store
} }
} }
static int compute_minrun(size_t n) static size_t compute_minrun(size_t n)
{ {
int r = 0; int r = 0;
while (n >= 64) { while (n >= 64) {
...@@ -158,19 +160,19 @@ static int compute_minrun(size_t n) ...@@ -158,19 +160,19 @@ static int compute_minrun(size_t n)
return n + r; return n + r;
} }
static int check_invariant(struct tsort_run *stack, int stack_curr) static int check_invariant(struct tsort_run *stack, ssize_t stack_curr)
{ {
if (stack_curr < 2) if (stack_curr < 2)
return 1; return 1;
else if (stack_curr == 2) { else if (stack_curr == 2) {
const int A = stack[stack_curr - 2].length; const ssize_t A = stack[stack_curr - 2].length;
const int B = stack[stack_curr - 1].length; const ssize_t B = stack[stack_curr - 1].length;
return (A > B); return (A > B);
} else { } else {
const int A = stack[stack_curr - 3].length; const ssize_t A = stack[stack_curr - 3].length;
const int B = stack[stack_curr - 2].length; const ssize_t B = stack[stack_curr - 2].length;
const int C = stack[stack_curr - 1].length; const ssize_t C = stack[stack_curr - 1].length;
return !((A <= B + C) || (B <= C)); return !((A <= B + C) || (B <= C));
} }
} }
...@@ -195,7 +197,7 @@ static int resize(struct tsort_store *store, size_t new_size) ...@@ -195,7 +197,7 @@ static int resize(struct tsort_store *store, size_t new_size)
return 0; return 0;
} }
static void merge(void **dst, const struct tsort_run *stack, int stack_curr, struct tsort_store *store) static void merge(void **dst, const struct tsort_run *stack, ssize_t stack_curr, struct tsort_store *store)
{ {
const ssize_t A = stack[stack_curr - 2].length; const ssize_t A = stack[stack_curr - 2].length;
const ssize_t B = stack[stack_curr - 1].length; const ssize_t B = stack[stack_curr - 1].length;
...@@ -343,7 +345,7 @@ void git__tsort(void **dst, size_t size, cmp_ptr_t cmp) ...@@ -343,7 +345,7 @@ void git__tsort(void **dst, size_t size, cmp_ptr_t cmp)
} }
/* compute the minimum run length */ /* compute the minimum run length */
minrun = compute_minrun(size); minrun = (ssize_t)compute_minrun(size);
/* temporary storage for merges */ /* temporary storage for merges */
store->alloc = 0; store->alloc = 0;
......
...@@ -391,10 +391,11 @@ int git__bsearch( ...@@ -391,10 +391,11 @@ int git__bsearch(
int (*compare)(const void *, const void *), int (*compare)(const void *, const void *),
size_t *position) size_t *position)
{ {
int lim, cmp = -1; unsigned int lim;
int cmp = -1;
void **part, **base = array; void **part, **base = array;
for (lim = array_len; lim != 0; lim >>= 1) { for (lim = (unsigned int)array_len; lim != 0; lim >>= 1) {
part = base + (lim >> 1); part = base + (lim >> 1);
cmp = (*compare)(key, *part); cmp = (*compare)(key, *part);
if (cmp == 0) { if (cmp == 0) {
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "vector.h" #include "vector.h"
static const double resize_factor = 1.75; static const double resize_factor = 1.75;
static const size_t minimum_size = 8; static const unsigned int minimum_size = 8;
static int resize_vector(git_vector *v) static int resize_vector(git_vector *v)
{ {
......
...@@ -49,5 +49,7 @@ extern int p_open(const char *path, int flags); ...@@ -49,5 +49,7 @@ extern int p_open(const char *path, int flags);
extern int p_creat(const char *path, mode_t mode); extern int p_creat(const char *path, mode_t mode);
extern int p_getcwd(char *buffer_out, size_t size); extern int p_getcwd(char *buffer_out, size_t size);
extern int p_rename(const char *from, const char *to); extern int p_rename(const char *from, const char *to);
extern int p_recv(GIT_SOCKET socket, void *buffer, size_t length, int flags);
extern int p_send(GIT_SOCKET socket, const void *buffer, size_t length, int flags);
#endif #endif
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* This file is part of libgit2, distributed under the GNU GPL v2 with * This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file. * a Linking Exception. For full terms see the included COPYING file.
*/ */
#include "posix.h" #include "../posix.h"
#include "path.h" #include "path.h"
#include "utf-conv.h" #include "utf-conv.h"
#include <errno.h> #include <errno.h>
...@@ -179,11 +179,11 @@ int p_readlink(const char *link, char *target, size_t target_len) ...@@ -179,11 +179,11 @@ int p_readlink(const char *link, char *target, size_t target_len)
target_w = (wchar_t*)git__malloc(target_len * sizeof(wchar_t)); target_w = (wchar_t*)git__malloc(target_len * sizeof(wchar_t));
GITERR_CHECK_ALLOC(target_w); GITERR_CHECK_ALLOC(target_w);
dwRet = pGetFinalPath(hFile, target_w, target_len, 0x0); dwRet = pGetFinalPath(hFile, target_w, (DWORD)target_len, 0x0);
if (dwRet == 0 || if (dwRet == 0 ||
dwRet >= target_len || dwRet >= target_len ||
!WideCharToMultiByte(CP_UTF8, 0, target_w, -1, target, !WideCharToMultiByte(CP_UTF8, 0, target_w, -1, target,
target_len * sizeof(char), NULL, NULL)) (int)(target_len * sizeof(char)), NULL, NULL))
error = -1; error = -1;
git__free(target_w); git__free(target_w);
...@@ -241,13 +241,19 @@ int p_creat(const char *path, mode_t mode) ...@@ -241,13 +241,19 @@ int p_creat(const char *path, mode_t mode)
int p_getcwd(char *buffer_out, size_t size) int p_getcwd(char *buffer_out, size_t size)
{ {
wchar_t* buf = (wchar_t*)git__malloc(sizeof(wchar_t) * (int)size);
int ret; int ret;
wchar_t* buf;
if ((size_t)((int)size) != size)
return -1;
buf = (wchar_t*)git__malloc(sizeof(wchar_t) * (int)size);
GITERR_CHECK_ALLOC(buf);
_wgetcwd(buf, (int)size); _wgetcwd(buf, (int)size);
ret = WideCharToMultiByte( ret = WideCharToMultiByte(
CP_UTF8, 0, buf, -1, buffer_out, size, NULL, NULL); CP_UTF8, 0, buf, -1, buffer_out, (int)size, NULL, NULL);
git__free(buf); git__free(buf);
return !ret ? -1 : 0; return !ret ? -1 : 0;
...@@ -421,3 +427,19 @@ int p_rename(const char *from, const char *to) ...@@ -421,3 +427,19 @@ int p_rename(const char *from, const char *to)
return ret; return ret;
} }
int p_recv(GIT_SOCKET socket, void *buffer, size_t length, int flags)
{
if ((size_t)((int)length) != length)
return -1; /* giterr_set will be done by caller */
return recv(socket, buffer, (int)length, flags);
}
int p_send(GIT_SOCKET socket, const void *buffer, size_t length, int flags)
{
if ((size_t)((int)length) != length)
return -1; /* giterr_set will be done by caller */
return send(socket, buffer, (int)length, flags);
}
...@@ -31,27 +31,23 @@ void gitwin_set_utf8(void) ...@@ -31,27 +31,23 @@ void gitwin_set_utf8(void)
wchar_t* gitwin_to_utf16(const char* str) wchar_t* gitwin_to_utf16(const char* str)
{ {
wchar_t* ret; wchar_t* ret;
int cb; size_t cb;
if (!str) if (!str)
return NULL; return NULL;
cb = strlen(str) * sizeof(wchar_t); cb = strlen(str) * sizeof(wchar_t);
if (cb == 0) { if (cb == 0)
ret = (wchar_t*)git__malloc(sizeof(wchar_t)); return (wchar_t *)git__calloc(1, sizeof(wchar_t));
if (ret)
ret[0] = 0;
return ret;
}
/* Add space for null terminator */ /* Add space for null terminator */
cb += sizeof(wchar_t); cb += sizeof(wchar_t);
ret = (wchar_t*)git__malloc(cb); ret = (wchar_t *)git__malloc(cb);
if (!ret) if (!ret)
return NULL; return NULL;
if (MultiByteToWideChar(_active_codepage, 0, str, -1, ret, cb) == 0) { if (MultiByteToWideChar(_active_codepage, 0, str, -1, ret, (int)cb) == 0) {
giterr_set(GITERR_OS, "Could not convert string to UTF-16"); giterr_set(GITERR_OS, "Could not convert string to UTF-16");
git__free(ret); git__free(ret);
ret = NULL; ret = NULL;
...@@ -62,7 +58,7 @@ wchar_t* gitwin_to_utf16(const char* str) ...@@ -62,7 +58,7 @@ wchar_t* gitwin_to_utf16(const char* str)
int gitwin_append_utf16(wchar_t *buffer, const char *str, size_t len) int gitwin_append_utf16(wchar_t *buffer, const char *str, size_t len)
{ {
int result = MultiByteToWideChar(_active_codepage, 0, str, -1, buffer, len); int result = MultiByteToWideChar(_active_codepage, 0, str, -1, buffer, (int)len);
if (result == 0) if (result == 0)
giterr_set(GITERR_OS, "Could not convert string to UTF-16"); giterr_set(GITERR_OS, "Could not convert string to UTF-16");
return result; return result;
...@@ -71,19 +67,14 @@ int gitwin_append_utf16(wchar_t *buffer, const char *str, size_t len) ...@@ -71,19 +67,14 @@ int gitwin_append_utf16(wchar_t *buffer, const char *str, size_t len)
char* gitwin_from_utf16(const wchar_t* str) char* gitwin_from_utf16(const wchar_t* str)
{ {
char* ret; char* ret;
int cb; size_t cb;
if (!str) { if (!str)
return NULL; return NULL;
}
cb = wcslen(str) * sizeof(char); cb = wcslen(str) * sizeof(char);
if (cb == 0) { if (cb == 0)
ret = (char*)git__malloc(sizeof(char)); return (char *)git__calloc(1, sizeof(char));
if (ret)
ret[0] = 0;
return ret;
}
/* Add space for null terminator */ /* Add space for null terminator */
cb += sizeof(char); cb += sizeof(char);
...@@ -92,7 +83,7 @@ char* gitwin_from_utf16(const wchar_t* str) ...@@ -92,7 +83,7 @@ char* gitwin_from_utf16(const wchar_t* str)
if (!ret) if (!ret)
return NULL; return NULL;
if (WideCharToMultiByte(_active_codepage, 0, str, -1, ret, cb, NULL, NULL) == 0) { if (WideCharToMultiByte(_active_codepage, 0, str, -1, ret, (int)cb, NULL, NULL) == 0) {
giterr_set(GITERR_OS, "Could not convert string to UTF-8"); giterr_set(GITERR_OS, "Could not convert string to UTF-8");
git__free(ret); git__free(ret);
ret = NULL; ret = NULL;
......
...@@ -40,7 +40,7 @@ static long xdl_get_rec(xdfile_t *xdf, long ri, char const **rec) { ...@@ -40,7 +40,7 @@ static long xdl_get_rec(xdfile_t *xdf, long ri, char const **rec) {
static int xdl_emit_record(xdfile_t *xdf, long ri, char const *pre, xdemitcb_t *ecb) { static int xdl_emit_record(xdfile_t *xdf, long ri, char const *pre, xdemitcb_t *ecb) {
long size, psize = strlen(pre); long size, psize = (long)strlen(pre);
char const *rec; char const *rec;
size = xdl_get_rec(xdf, ri, &rec); size = xdl_get_rec(xdf, ri, &rec);
......
...@@ -149,9 +149,9 @@ static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1, ...@@ -149,9 +149,9 @@ static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
int size, int i, int style, int size, int i, int style,
xdmerge_t *m, char *dest, int marker_size) xdmerge_t *m, char *dest, int marker_size)
{ {
int marker1_size = (name1 ? strlen(name1) + 1 : 0); int marker1_size = (name1 ? (int)strlen(name1) + 1 : 0);
int marker2_size = (name2 ? strlen(name2) + 1 : 0); int marker2_size = (name2 ? (int)strlen(name2) + 1 : 0);
int marker3_size = (name3 ? strlen(name3) + 1 : 0); int marker3_size = (name3 ? (int)strlen(name3) + 1 : 0);
if (marker_size <= 0) if (marker_size <= 0)
marker_size = DEFAULT_CONFLICT_MARKER_SIZE; marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
......
...@@ -62,14 +62,14 @@ int xdl_emit_diffrec(char const *rec, long size, char const *pre, long psize, ...@@ -62,14 +62,14 @@ int xdl_emit_diffrec(char const *rec, long size, char const *pre, long psize,
void *xdl_mmfile_first(mmfile_t *mmf, long *size) void *xdl_mmfile_first(mmfile_t *mmf, long *size)
{ {
*size = mmf->size; *size = (long)mmf->size;
return mmf->ptr; return mmf->ptr;
} }
long xdl_mmfile_size(mmfile_t *mmf) long xdl_mmfile_size(mmfile_t *mmf)
{ {
return mmf->size; return (long)mmf->size;
} }
...@@ -321,7 +321,7 @@ int xdl_num_out(char *out, long val) { ...@@ -321,7 +321,7 @@ int xdl_num_out(char *out, long val) {
*str++ = '0'; *str++ = '0';
*str = '\0'; *str = '\0';
return str - out; return (int)(str - out);
} }
......
...@@ -34,7 +34,7 @@ GIT_INLINE(void) attr_check_expected( ...@@ -34,7 +34,7 @@ GIT_INLINE(void) attr_check_expected(
break; break;
case EXPECT_STRING: case EXPECT_STRING:
cl_assert_strequal(expected_str, value); cl_assert_equal_s(expected_str, value);
break; break;
} }
} }
......
...@@ -13,19 +13,19 @@ void test_attr_file__simple_read(void) ...@@ -13,19 +13,19 @@ void test_attr_file__simple_read(void)
cl_git_pass(git_attr_file__new(&file)); cl_git_pass(git_attr_file__new(&file));
cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr0"), file)); cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr0"), file));
cl_assert_strequal(cl_fixture("attr/attr0"), file->path); cl_assert_equal_s(cl_fixture("attr/attr0"), file->path);
cl_assert(file->rules.length == 1); cl_assert(file->rules.length == 1);
rule = get_rule(0); rule = get_rule(0);
cl_assert(rule != NULL); cl_assert(rule != NULL);
cl_assert_strequal("*", rule->match.pattern); cl_assert_equal_s("*", rule->match.pattern);
cl_assert(rule->match.length == 1); cl_assert(rule->match.length == 1);
cl_assert((rule->match.flags & GIT_ATTR_FNMATCH_HASWILD) != 0); cl_assert((rule->match.flags & GIT_ATTR_FNMATCH_HASWILD) != 0);
cl_assert(rule->assigns.length == 1); cl_assert(rule->assigns.length == 1);
assign = get_assign(rule, 0); assign = get_assign(rule, 0);
cl_assert(assign != NULL); cl_assert(assign != NULL);
cl_assert_strequal("binary", assign->name); cl_assert_equal_s("binary", assign->name);
cl_assert(GIT_ATTR_TRUE(assign->value)); cl_assert(GIT_ATTR_TRUE(assign->value));
cl_assert(!assign->is_allocated); cl_assert(!assign->is_allocated);
...@@ -40,7 +40,7 @@ void test_attr_file__match_variants(void) ...@@ -40,7 +40,7 @@ void test_attr_file__match_variants(void)
cl_git_pass(git_attr_file__new(&file)); cl_git_pass(git_attr_file__new(&file));
cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr1"), file)); cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr1"), file));
cl_assert_strequal(cl_fixture("attr/attr1"), file->path); cl_assert_equal_s(cl_fixture("attr/attr1"), file->path);
cl_assert(file->rules.length == 10); cl_assert(file->rules.length == 10);
/* let's do a thorough check of this rule, then just verify /* let's do a thorough check of this rule, then just verify
...@@ -48,53 +48,53 @@ void test_attr_file__match_variants(void) ...@@ -48,53 +48,53 @@ void test_attr_file__match_variants(void)
*/ */
rule = get_rule(0); rule = get_rule(0);
cl_assert(rule); cl_assert(rule);
cl_assert_strequal("pat0", rule->match.pattern); cl_assert_equal_s("pat0", rule->match.pattern);
cl_assert(rule->match.length == strlen("pat0")); cl_assert(rule->match.length == strlen("pat0"));
cl_assert(rule->match.flags == 0); cl_assert(rule->match.flags == 0);
cl_assert(rule->assigns.length == 1); cl_assert(rule->assigns.length == 1);
assign = get_assign(rule,0); assign = get_assign(rule,0);
cl_assert_strequal("attr0", assign->name); cl_assert_equal_s("attr0", assign->name);
cl_assert(assign->name_hash == git_attr_file__name_hash(assign->name)); cl_assert(assign->name_hash == git_attr_file__name_hash(assign->name));
cl_assert(GIT_ATTR_TRUE(assign->value)); cl_assert(GIT_ATTR_TRUE(assign->value));
cl_assert(!assign->is_allocated); cl_assert(!assign->is_allocated);
rule = get_rule(1); rule = get_rule(1);
cl_assert_strequal("pat1", rule->match.pattern); cl_assert_equal_s("pat1", rule->match.pattern);
cl_assert(rule->match.length == strlen("pat1")); cl_assert(rule->match.length == strlen("pat1"));
cl_assert(rule->match.flags == GIT_ATTR_FNMATCH_NEGATIVE); cl_assert(rule->match.flags == GIT_ATTR_FNMATCH_NEGATIVE);
rule = get_rule(2); rule = get_rule(2);
cl_assert_strequal("pat2", rule->match.pattern); cl_assert_equal_s("pat2", rule->match.pattern);
cl_assert(rule->match.length == strlen("pat2")); cl_assert(rule->match.length == strlen("pat2"));
cl_assert(rule->match.flags == GIT_ATTR_FNMATCH_DIRECTORY); cl_assert(rule->match.flags == GIT_ATTR_FNMATCH_DIRECTORY);
rule = get_rule(3); rule = get_rule(3);
cl_assert_strequal("pat3dir/pat3file", rule->match.pattern); cl_assert_equal_s("pat3dir/pat3file", rule->match.pattern);
cl_assert(rule->match.flags == GIT_ATTR_FNMATCH_FULLPATH); cl_assert(rule->match.flags == GIT_ATTR_FNMATCH_FULLPATH);
rule = get_rule(4); rule = get_rule(4);
cl_assert_strequal("pat4.*", rule->match.pattern); cl_assert_equal_s("pat4.*", rule->match.pattern);
cl_assert((rule->match.flags & GIT_ATTR_FNMATCH_HASWILD) != 0); cl_assert((rule->match.flags & GIT_ATTR_FNMATCH_HASWILD) != 0);
rule = get_rule(5); rule = get_rule(5);
cl_assert_strequal("*.pat5", rule->match.pattern); cl_assert_equal_s("*.pat5", rule->match.pattern);
cl_assert((rule->match.flags & GIT_ATTR_FNMATCH_HASWILD) != 0); cl_assert((rule->match.flags & GIT_ATTR_FNMATCH_HASWILD) != 0);
rule = get_rule(7); rule = get_rule(7);
cl_assert_strequal("pat7[a-e]??[xyz]", rule->match.pattern); cl_assert_equal_s("pat7[a-e]??[xyz]", rule->match.pattern);
cl_assert(rule->assigns.length == 1); cl_assert(rule->assigns.length == 1);
cl_assert((rule->match.flags & GIT_ATTR_FNMATCH_HASWILD) != 0); cl_assert((rule->match.flags & GIT_ATTR_FNMATCH_HASWILD) != 0);
assign = get_assign(rule,0); assign = get_assign(rule,0);
cl_assert_strequal("attr7", assign->name); cl_assert_equal_s("attr7", assign->name);
cl_assert(GIT_ATTR_TRUE(assign->value)); cl_assert(GIT_ATTR_TRUE(assign->value));
rule = get_rule(8); rule = get_rule(8);
cl_assert_strequal("pat8 with spaces", rule->match.pattern); cl_assert_equal_s("pat8 with spaces", rule->match.pattern);
cl_assert(rule->match.length == strlen("pat8 with spaces")); cl_assert(rule->match.length == strlen("pat8 with spaces"));
cl_assert(rule->match.flags == 0); cl_assert(rule->match.flags == 0);
rule = get_rule(9); rule = get_rule(9);
cl_assert_strequal("pat9", rule->match.pattern); cl_assert_equal_s("pat9", rule->match.pattern);
git_attr_file__free(file); git_attr_file__free(file);
} }
...@@ -111,9 +111,9 @@ static void check_one_assign( ...@@ -111,9 +111,9 @@ static void check_one_assign(
git_attr_rule *rule = get_rule(rule_idx); git_attr_rule *rule = get_rule(rule_idx);
git_attr_assignment *assign = get_assign(rule, assign_idx); git_attr_assignment *assign = get_assign(rule, assign_idx);
cl_assert_strequal(pattern, rule->match.pattern); cl_assert_equal_s(pattern, rule->match.pattern);
cl_assert(rule->assigns.length == 1); cl_assert(rule->assigns.length == 1);
cl_assert_strequal(name, assign->name); cl_assert_equal_s(name, assign->name);
cl_assert(assign->name_hash == git_attr_file__name_hash(assign->name)); cl_assert(assign->name_hash == git_attr_file__name_hash(assign->name));
attr_check_expected(expected, expected_str, assign->value); attr_check_expected(expected, expected_str, assign->value);
...@@ -127,7 +127,7 @@ void test_attr_file__assign_variants(void) ...@@ -127,7 +127,7 @@ void test_attr_file__assign_variants(void)
cl_git_pass(git_attr_file__new(&file)); cl_git_pass(git_attr_file__new(&file));
cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr2"), file)); cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr2"), file));
cl_assert_strequal(cl_fixture("attr/attr2"), file->path); cl_assert_equal_s(cl_fixture("attr/attr2"), file->path);
cl_assert(file->rules.length == 11); cl_assert(file->rules.length == 11);
check_one_assign(file, 0, 0, "pat0", "simple", EXPECT_TRUE, NULL); check_one_assign(file, 0, 0, "pat0", "simple", EXPECT_TRUE, NULL);
...@@ -140,45 +140,45 @@ void test_attr_file__assign_variants(void) ...@@ -140,45 +140,45 @@ void test_attr_file__assign_variants(void)
check_one_assign(file, 7, 0, "pat6", "negempty", EXPECT_FALSE, NULL); check_one_assign(file, 7, 0, "pat6", "negempty", EXPECT_FALSE, NULL);
rule = get_rule(8); rule = get_rule(8);
cl_assert_strequal("pat7", rule->match.pattern); cl_assert_equal_s("pat7", rule->match.pattern);
cl_assert(rule->assigns.length == 5); cl_assert(rule->assigns.length == 5);
/* assignments will be sorted by hash value, so we have to do /* assignments will be sorted by hash value, so we have to do
* lookups by search instead of by position * lookups by search instead of by position
*/ */
assign = git_attr_rule__lookup_assignment(rule, "multiple"); assign = git_attr_rule__lookup_assignment(rule, "multiple");
cl_assert(assign); cl_assert(assign);
cl_assert_strequal("multiple", assign->name); cl_assert_equal_s("multiple", assign->name);
cl_assert(GIT_ATTR_TRUE(assign->value)); cl_assert(GIT_ATTR_TRUE(assign->value));
assign = git_attr_rule__lookup_assignment(rule, "single"); assign = git_attr_rule__lookup_assignment(rule, "single");
cl_assert(assign); cl_assert(assign);
cl_assert_strequal("single", assign->name); cl_assert_equal_s("single", assign->name);
cl_assert(GIT_ATTR_FALSE(assign->value)); cl_assert(GIT_ATTR_FALSE(assign->value));
assign = git_attr_rule__lookup_assignment(rule, "values"); assign = git_attr_rule__lookup_assignment(rule, "values");
cl_assert(assign); cl_assert(assign);
cl_assert_strequal("values", assign->name); cl_assert_equal_s("values", assign->name);
cl_assert_strequal("1", assign->value); cl_assert_equal_s("1", assign->value);
assign = git_attr_rule__lookup_assignment(rule, "also"); assign = git_attr_rule__lookup_assignment(rule, "also");
cl_assert(assign); cl_assert(assign);
cl_assert_strequal("also", assign->name); cl_assert_equal_s("also", assign->name);
cl_assert_strequal("a-really-long-value/*", assign->value); cl_assert_equal_s("a-really-long-value/*", assign->value);
assign = git_attr_rule__lookup_assignment(rule, "happy"); assign = git_attr_rule__lookup_assignment(rule, "happy");
cl_assert(assign); cl_assert(assign);
cl_assert_strequal("happy", assign->name); cl_assert_equal_s("happy", assign->name);
cl_assert_strequal("yes!", assign->value); cl_assert_equal_s("yes!", assign->value);
assign = git_attr_rule__lookup_assignment(rule, "other"); assign = git_attr_rule__lookup_assignment(rule, "other");
cl_assert(!assign); cl_assert(!assign);
rule = get_rule(9); rule = get_rule(9);
cl_assert_strequal("pat8", rule->match.pattern); cl_assert_equal_s("pat8", rule->match.pattern);
cl_assert(rule->assigns.length == 2); cl_assert(rule->assigns.length == 2);
assign = git_attr_rule__lookup_assignment(rule, "again"); assign = git_attr_rule__lookup_assignment(rule, "again");
cl_assert(assign); cl_assert(assign);
cl_assert_strequal("again", assign->name); cl_assert_equal_s("again", assign->name);
cl_assert(GIT_ATTR_TRUE(assign->value)); cl_assert(GIT_ATTR_TRUE(assign->value));
assign = git_attr_rule__lookup_assignment(rule, "another"); assign = git_attr_rule__lookup_assignment(rule, "another");
cl_assert(assign); cl_assert(assign);
cl_assert_strequal("another", assign->name); cl_assert_equal_s("another", assign->name);
cl_assert_strequal("12321", assign->value); cl_assert_equal_s("12321", assign->value);
check_one_assign(file, 10, 0, "pat9", "at-eof", EXPECT_FALSE, NULL); check_one_assign(file, 10, 0, "pat9", "at-eof", EXPECT_FALSE, NULL);
...@@ -193,37 +193,37 @@ void test_attr_file__check_attr_examples(void) ...@@ -193,37 +193,37 @@ void test_attr_file__check_attr_examples(void)
cl_git_pass(git_attr_file__new(&file)); cl_git_pass(git_attr_file__new(&file));
cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr3"), file)); cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr3"), file));
cl_assert_strequal(cl_fixture("attr/attr3"), file->path); cl_assert_equal_s(cl_fixture("attr/attr3"), file->path);
cl_assert(file->rules.length == 3); cl_assert(file->rules.length == 3);
rule = get_rule(0); rule = get_rule(0);
cl_assert_strequal("*.java", rule->match.pattern); cl_assert_equal_s("*.java", rule->match.pattern);
cl_assert(rule->assigns.length == 3); cl_assert(rule->assigns.length == 3);
assign = git_attr_rule__lookup_assignment(rule, "diff"); assign = git_attr_rule__lookup_assignment(rule, "diff");
cl_assert_strequal("diff", assign->name); cl_assert_equal_s("diff", assign->name);
cl_assert_strequal("java", assign->value); cl_assert_equal_s("java", assign->value);
assign = git_attr_rule__lookup_assignment(rule, "crlf"); assign = git_attr_rule__lookup_assignment(rule, "crlf");
cl_assert_strequal("crlf", assign->name); cl_assert_equal_s("crlf", assign->name);
cl_assert(GIT_ATTR_FALSE(assign->value)); cl_assert(GIT_ATTR_FALSE(assign->value));
assign = git_attr_rule__lookup_assignment(rule, "myAttr"); assign = git_attr_rule__lookup_assignment(rule, "myAttr");
cl_assert_strequal("myAttr", assign->name); cl_assert_equal_s("myAttr", assign->name);
cl_assert(GIT_ATTR_TRUE(assign->value)); cl_assert(GIT_ATTR_TRUE(assign->value));
assign = git_attr_rule__lookup_assignment(rule, "missing"); assign = git_attr_rule__lookup_assignment(rule, "missing");
cl_assert(assign == NULL); cl_assert(assign == NULL);
rule = get_rule(1); rule = get_rule(1);
cl_assert_strequal("NoMyAttr.java", rule->match.pattern); cl_assert_equal_s("NoMyAttr.java", rule->match.pattern);
cl_assert(rule->assigns.length == 1); cl_assert(rule->assigns.length == 1);
assign = get_assign(rule, 0); assign = get_assign(rule, 0);
cl_assert_strequal("myAttr", assign->name); cl_assert_equal_s("myAttr", assign->name);
cl_assert(assign->value == NULL); cl_assert(assign->value == NULL);
rule = get_rule(2); rule = get_rule(2);
cl_assert_strequal("README", rule->match.pattern); cl_assert_equal_s("README", rule->match.pattern);
cl_assert(rule->assigns.length == 1); cl_assert(rule->assigns.length == 1);
assign = get_assign(rule, 0); assign = get_assign(rule, 0);
cl_assert_strequal("caveat", assign->name); cl_assert_equal_s("caveat", assign->name);
cl_assert_strequal("unspecified", assign->value); cl_assert_equal_s("unspecified", assign->value);
git_attr_file__free(file); git_attr_file__free(file);
} }
...@@ -11,12 +11,12 @@ void test_attr_lookup__simple(void) ...@@ -11,12 +11,12 @@ void test_attr_lookup__simple(void)
cl_git_pass(git_attr_file__new(&file)); cl_git_pass(git_attr_file__new(&file));
cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr0"), file)); cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr0"), file));
cl_assert_strequal(cl_fixture("attr/attr0"), file->path); cl_assert_equal_s(cl_fixture("attr/attr0"), file->path);
cl_assert(file->rules.length == 1); cl_assert(file->rules.length == 1);
cl_git_pass(git_attr_path__init(&path, "test", NULL)); cl_git_pass(git_attr_path__init(&path, "test", NULL));
cl_assert_strequal("test", path.path); cl_assert_equal_s("test", path.path);
cl_assert_strequal("test", path.basename); cl_assert_equal_s("test", path.basename);
cl_assert(!path.is_dir); cl_assert(!path.is_dir);
cl_git_pass(git_attr_file__lookup_one(file,&path,"binary",&value)); cl_git_pass(git_attr_file__lookup_one(file,&path,"binary",&value));
...@@ -129,11 +129,11 @@ void test_attr_lookup__match_variants(void) ...@@ -129,11 +129,11 @@ void test_attr_lookup__match_variants(void)
cl_git_pass(git_attr_file__new(&file)); cl_git_pass(git_attr_file__new(&file));
cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr1"), file)); cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr1"), file));
cl_assert_strequal(cl_fixture("attr/attr1"), file->path); cl_assert_equal_s(cl_fixture("attr/attr1"), file->path);
cl_assert(file->rules.length == 10); cl_assert(file->rules.length == 10);
cl_git_pass(git_attr_path__init(&path, "/testing/for/pat0", NULL)); cl_git_pass(git_attr_path__init(&path, "/testing/for/pat0", NULL));
cl_assert_strequal("pat0", path.basename); cl_assert_equal_s("pat0", path.basename);
run_test_cases(file, cases, 0); run_test_cases(file, cases, 0);
run_test_cases(file, dir_cases, 1); run_test_cases(file, dir_cases, 1);
......
...@@ -101,7 +101,7 @@ void test_attr_repo__get_many(void) ...@@ -101,7 +101,7 @@ void test_attr_repo__get_many(void)
cl_assert(GIT_ATTR_TRUE(values[0])); cl_assert(GIT_ATTR_TRUE(values[0]));
cl_assert(GIT_ATTR_TRUE(values[1])); cl_assert(GIT_ATTR_TRUE(values[1]));
cl_assert(GIT_ATTR_UNSPECIFIED(values[2])); cl_assert(GIT_ATTR_UNSPECIFIED(values[2]));
cl_assert_strequal("yes", values[3]); cl_assert_equal_s("yes", values[3]);
} }
static int count_attrs( static int count_attrs(
...@@ -150,7 +150,7 @@ void test_attr_repo__manpage_example(void) ...@@ -150,7 +150,7 @@ void test_attr_repo__manpage_example(void)
cl_assert(GIT_ATTR_FALSE(value)); cl_assert(GIT_ATTR_FALSE(value));
cl_git_pass(git_attr_get(g_repo, "sub/abc", "merge", &value)); cl_git_pass(git_attr_get(g_repo, "sub/abc", "merge", &value));
cl_assert_strequal("filfre", value); cl_assert_equal_s("filfre", value);
cl_git_pass(git_attr_get(g_repo, "sub/abc", "frotz", &value)); cl_git_pass(git_attr_get(g_repo, "sub/abc", "frotz", &value));
cl_assert(GIT_ATTR_UNSPECIFIED(value)); cl_assert(GIT_ATTR_UNSPECIFIED(value));
...@@ -177,13 +177,13 @@ void test_attr_repo__macros(void) ...@@ -177,13 +177,13 @@ void test_attr_repo__macros(void)
cl_assert(GIT_ATTR_TRUE(values[1])); cl_assert(GIT_ATTR_TRUE(values[1]));
cl_assert(GIT_ATTR_FALSE(values[2])); cl_assert(GIT_ATTR_FALSE(values[2]));
cl_assert(GIT_ATTR_UNSPECIFIED(values[3])); cl_assert(GIT_ATTR_UNSPECIFIED(values[3]));
cl_assert_strequal("77", values[4]); cl_assert_equal_s("77", values[4]);
cl_git_pass(git_attr_get_many(g_repo, "macro_test", 3, names3, values)); cl_git_pass(git_attr_get_many(g_repo, "macro_test", 3, names3, values));
cl_assert(GIT_ATTR_TRUE(values[0])); cl_assert(GIT_ATTR_TRUE(values[0]));
cl_assert(GIT_ATTR_FALSE(values[1])); cl_assert(GIT_ATTR_FALSE(values[1]));
cl_assert_strequal("answer", values[2]); cl_assert_equal_s("answer", values[2]);
} }
void test_attr_repo__bad_macros(void) void test_attr_repo__bad_macros(void)
...@@ -222,7 +222,7 @@ void test_attr_repo__bad_macros(void) ...@@ -222,7 +222,7 @@ void test_attr_repo__bad_macros(void)
* -firstmacro secondmacro="hahaha" thirdmacro * -firstmacro secondmacro="hahaha" thirdmacro
*/ */
cl_assert(GIT_ATTR_FALSE(values[3])); cl_assert(GIT_ATTR_FALSE(values[3]));
cl_assert_strequal("hahaha", values[4]); cl_assert_equal_s("hahaha", values[4]);
cl_assert(GIT_ATTR_TRUE(values[5])); cl_assert(GIT_ATTR_TRUE(values[5]));
} }
...@@ -25,26 +25,6 @@ ...@@ -25,26 +25,6 @@
*/ */
#define cl_git_fail(expr) cl_must_fail(expr) #define cl_git_fail(expr) cl_must_fail(expr)
/**
* Wrapper for string comparison that knows about nulls.
*/
#define cl_assert_strequal(a,b) \
cl_assert_strequal_internal(a,b,__FILE__,__LINE__,"string mismatch: " #a " != " #b)
GIT_INLINE(void) cl_assert_strequal_internal(
const char *a, const char *b, const char *file, int line, const char *err)
{
int match = (a == NULL || b == NULL) ? (a == b) : (strcmp(a, b) == 0);
if (!match) {
char buf[4096];
snprintf(buf, 4096, "'%s' != '%s'", a, b);
clar__assert(0, file, line, err, buf, 1);
}
}
#define cl_assert_intequal(a,b) \
do { if ((a) != (b)) { char buf[128]; snprintf(buf,128,"%d != %d",(a),(b)); clar__assert(0,__FILE__,__LINE__,#a " != " #b,buf,1); } } while (0)
/* /*
* Some utility macros for building long strings * Some utility macros for building long strings
*/ */
......
...@@ -42,12 +42,14 @@ void test_core_errors__new_school(void) ...@@ -42,12 +42,14 @@ void test_core_errors__new_school(void)
cl_assert(str_in_error != NULL); cl_assert(str_in_error != NULL);
git_error_clear(); git_error_clear();
cl_assert(git_error_last() == NULL);
{ do {
struct stat st; struct stat st;
memset(&st, 0, sizeof(st));
assert(p_lstat("this_file_does_not_exist", &st) < 0); assert(p_lstat("this_file_does_not_exist", &st) < 0);
GIT_UNUSED(st); GIT_UNUSED(st);
} } while (false);
giterr_set(GITERR_OS, "stat failed"); /* internal fn */ giterr_set(GITERR_OS, "stat failed"); /* internal fn */
cl_assert(git_error_last() != NULL); cl_assert(git_error_last() != NULL);
......
...@@ -8,11 +8,11 @@ check_dirname(const char *A, const char *B) ...@@ -8,11 +8,11 @@ check_dirname(const char *A, const char *B)
char *dir2; char *dir2;
cl_assert(git_path_dirname_r(&dir, A) >= 0); cl_assert(git_path_dirname_r(&dir, A) >= 0);
cl_assert_strequal(B, dir.ptr); cl_assert_equal_s(B, dir.ptr);
git_buf_free(&dir); git_buf_free(&dir);
cl_assert((dir2 = git_path_dirname(A)) != NULL); cl_assert((dir2 = git_path_dirname(A)) != NULL);
cl_assert_strequal(B, dir2); cl_assert_equal_s(B, dir2);
git__free(dir2); git__free(dir2);
} }
...@@ -23,11 +23,11 @@ check_basename(const char *A, const char *B) ...@@ -23,11 +23,11 @@ check_basename(const char *A, const char *B)
char *base2; char *base2;
cl_assert(git_path_basename_r(&base, A) >= 0); cl_assert(git_path_basename_r(&base, A) >= 0);
cl_assert_strequal(B, base.ptr); cl_assert_equal_s(B, base.ptr);
git_buf_free(&base); git_buf_free(&base);
cl_assert((base2 = git_path_basename(A)) != NULL); cl_assert((base2 = git_path_basename(A)) != NULL);
cl_assert_strequal(B, base2); cl_assert_equal_s(B, base2);
git__free(base2); git__free(base2);
} }
...@@ -37,7 +37,7 @@ check_topdir(const char *A, const char *B) ...@@ -37,7 +37,7 @@ check_topdir(const char *A, const char *B)
const char *dir; const char *dir;
cl_assert((dir = git_path_topdir(A)) != NULL); cl_assert((dir = git_path_topdir(A)) != NULL);
cl_assert_strequal(B, dir); cl_assert_equal_s(B, dir);
} }
static void static void
...@@ -46,7 +46,7 @@ check_joinpath(const char *path_a, const char *path_b, const char *expected_path ...@@ -46,7 +46,7 @@ check_joinpath(const char *path_a, const char *path_b, const char *expected_path
git_buf joined_path = GIT_BUF_INIT; git_buf joined_path = GIT_BUF_INIT;
cl_git_pass(git_buf_joinpath(&joined_path, path_a, path_b)); cl_git_pass(git_buf_joinpath(&joined_path, path_a, path_b));
cl_assert_strequal(expected_path, joined_path.ptr); cl_assert_equal_s(expected_path, joined_path.ptr);
git_buf_free(&joined_path); git_buf_free(&joined_path);
} }
...@@ -63,7 +63,7 @@ check_joinpath_n( ...@@ -63,7 +63,7 @@ check_joinpath_n(
cl_git_pass(git_buf_join_n(&joined_path, '/', 4, cl_git_pass(git_buf_join_n(&joined_path, '/', 4,
path_a, path_b, path_c, path_d)); path_a, path_b, path_c, path_d));
cl_assert_strequal(expected_path, joined_path.ptr); cl_assert_equal_s(expected_path, joined_path.ptr);
git_buf_free(&joined_path); git_buf_free(&joined_path);
} }
...@@ -189,7 +189,7 @@ check_path_to_dir( ...@@ -189,7 +189,7 @@ check_path_to_dir(
git_buf_sets(&tgt, path); git_buf_sets(&tgt, path);
cl_git_pass(git_path_to_dir(&tgt)); cl_git_pass(git_path_to_dir(&tgt));
cl_assert_strequal(expected, tgt.ptr); cl_assert_equal_s(expected, tgt.ptr);
git_buf_free(&tgt); git_buf_free(&tgt);
} }
...@@ -197,16 +197,18 @@ check_path_to_dir( ...@@ -197,16 +197,18 @@ check_path_to_dir(
static void static void
check_string_to_dir( check_string_to_dir(
const char* path, const char* path,
int maxlen, size_t maxlen,
const char* expected) const char* expected)
{ {
int len = strlen(path); size_t len = strlen(path);
char *buf = git__malloc(len + 2); char *buf = git__malloc(len + 2);
cl_assert(buf);
strncpy(buf, path, len + 2); strncpy(buf, path, len + 2);
git_path_string_to_dir(buf, maxlen); git_path_string_to_dir(buf, maxlen);
cl_assert_strequal(expected, buf); cl_assert_equal_s(expected, buf);
git__free(buf); git__free(buf);
} }
...@@ -247,28 +249,28 @@ void test_core_path__08_self_join(void) ...@@ -247,28 +249,28 @@ void test_core_path__08_self_join(void)
asize = path.asize; asize = path.asize;
cl_git_pass(git_buf_sets(&path, "/foo")); cl_git_pass(git_buf_sets(&path, "/foo"));
cl_assert_strequal(path.ptr, "/foo"); cl_assert_equal_s(path.ptr, "/foo");
cl_assert(asize < path.asize); cl_assert(asize < path.asize);
asize = path.asize; asize = path.asize;
cl_git_pass(git_buf_joinpath(&path, path.ptr, "this is a new string")); cl_git_pass(git_buf_joinpath(&path, path.ptr, "this is a new string"));
cl_assert_strequal(path.ptr, "/foo/this is a new string"); cl_assert_equal_s(path.ptr, "/foo/this is a new string");
cl_assert(asize < path.asize); cl_assert(asize < path.asize);
asize = path.asize; asize = path.asize;
cl_git_pass(git_buf_joinpath(&path, path.ptr, "/grow the buffer, grow the buffer, grow the buffer")); cl_git_pass(git_buf_joinpath(&path, path.ptr, "/grow the buffer, grow the buffer, grow the buffer"));
cl_assert_strequal(path.ptr, "/foo/this is a new string/grow the buffer, grow the buffer, grow the buffer"); cl_assert_equal_s(path.ptr, "/foo/this is a new string/grow the buffer, grow the buffer, grow the buffer");
cl_assert(asize < path.asize); cl_assert(asize < path.asize);
git_buf_free(&path); git_buf_free(&path);
cl_git_pass(git_buf_sets(&path, "/foo/bar")); cl_git_pass(git_buf_sets(&path, "/foo/bar"));
cl_git_pass(git_buf_joinpath(&path, path.ptr + 4, "baz")); cl_git_pass(git_buf_joinpath(&path, path.ptr + 4, "baz"));
cl_assert_strequal(path.ptr, "/bar/baz"); cl_assert_equal_s(path.ptr, "/bar/baz");
asize = path.asize; asize = path.asize;
cl_git_pass(git_buf_joinpath(&path, path.ptr + 4, "somethinglongenoughtorealloc")); cl_git_pass(git_buf_joinpath(&path, path.ptr + 4, "somethinglongenoughtorealloc"));
cl_assert_strequal(path.ptr, "/baz/somethinglongenoughtorealloc"); cl_assert_equal_s(path.ptr, "/baz/somethinglongenoughtorealloc");
cl_assert(asize < path.asize); cl_assert(asize < path.asize);
git_buf_free(&path); git_buf_free(&path);
...@@ -279,7 +281,7 @@ static void check_percent_decoding(const char *expected_result, const char *inpu ...@@ -279,7 +281,7 @@ static void check_percent_decoding(const char *expected_result, const char *inpu
git_buf buf = GIT_BUF_INIT; git_buf buf = GIT_BUF_INIT;
cl_git_pass(git__percent_decode(&buf, input)); cl_git_pass(git__percent_decode(&buf, input));
cl_assert_strequal(expected_result, git_buf_cstr(&buf)); cl_assert_equal_s(expected_result, git_buf_cstr(&buf));
git_buf_free(&buf); git_buf_free(&buf);
} }
...@@ -306,7 +308,7 @@ static void check_fromurl(const char *expected_result, const char *input, int sh ...@@ -306,7 +308,7 @@ static void check_fromurl(const char *expected_result, const char *input, int sh
if (!should_fail) { if (!should_fail) {
cl_git_pass(git_path_fromurl(&buf, input)); cl_git_pass(git_path_fromurl(&buf, input));
cl_assert_strequal(expected_result, git_buf_cstr(&buf)); cl_assert_equal_s(expected_result, git_buf_cstr(&buf));
} else } else
cl_git_fail(git_path_fromurl(&buf, input)); cl_git_fail(git_path_fromurl(&buf, input));
...@@ -346,7 +348,7 @@ static int check_one_walkup_step(void *ref, git_buf *path) ...@@ -346,7 +348,7 @@ static int check_one_walkup_step(void *ref, git_buf *path)
{ {
check_walkup_info *info = (check_walkup_info *)ref; check_walkup_info *info = (check_walkup_info *)ref;
cl_assert(info->expect[info->expect_idx] != NULL); cl_assert(info->expect[info->expect_idx] != NULL);
cl_assert_strequal(info->expect[info->expect_idx], path->ptr); cl_assert_equal_s(info->expect[info->expect_idx], path->ptr);
info->expect_idx++; info->expect_idx++;
return 0; return 0;
} }
...@@ -380,7 +382,7 @@ void test_core_path__11_walkup(void) ...@@ -380,7 +382,7 @@ void test_core_path__11_walkup(void)
git_path_walk_up(&p, root[j], check_one_walkup_step, &info) git_path_walk_up(&p, root[j], check_one_walkup_step, &info)
); );
cl_assert_strequal(p.ptr, expect[i]); cl_assert_equal_s(p.ptr, expect[i]);
/* skip to next run of expectations */ /* skip to next run of expectations */
while (expect[i] != NULL) i++; while (expect[i] != NULL) i++;
......
...@@ -5,7 +5,7 @@ git_tree *resolve_commit_oid_to_tree( ...@@ -5,7 +5,7 @@ git_tree *resolve_commit_oid_to_tree(
git_repository *repo, git_repository *repo,
const char *partial_oid) const char *partial_oid)
{ {
size_t len = strlen(partial_oid); unsigned int len = (unsigned int)strlen(partial_oid);
git_oid oid; git_oid oid;
git_object *obj = NULL; git_object *obj = NULL;
git_tree *tree = NULL; git_tree *tree = NULL;
......
...@@ -37,7 +37,7 @@ static void tree_iterator_test( ...@@ -37,7 +37,7 @@ static void tree_iterator_test(
while (entry != NULL) { while (entry != NULL) {
if (expected_values != NULL) if (expected_values != NULL)
cl_assert_strequal(expected_values[count], entry->path); cl_assert_equal_s(expected_values[count], entry->path);
count++; count++;
...@@ -192,7 +192,7 @@ static void index_iterator_test( ...@@ -192,7 +192,7 @@ static void index_iterator_test(
while (entry != NULL) { while (entry != NULL) {
if (expected_names != NULL) if (expected_names != NULL)
cl_assert_strequal(expected_names[count], entry->path); cl_assert_equal_s(expected_names[count], entry->path);
if (expected_oids != NULL) { if (expected_oids != NULL) {
git_oid oid; git_oid oid;
...@@ -330,7 +330,7 @@ static void workdir_iterator_test( ...@@ -330,7 +330,7 @@ static void workdir_iterator_test(
} }
if (expected_names != NULL) if (expected_names != NULL)
cl_assert_strequal(expected_names[count_all], entry->path); cl_assert_equal_s(expected_names[count_all], entry->path);
if (an_ignored_name && strcmp(an_ignored_name,entry->path)==0) if (an_ignored_name && strcmp(an_ignored_name,entry->path)==0)
cl_assert(ignored); cl_assert(ignored);
......
...@@ -149,15 +149,15 @@ void test_diff_tree__options(void) ...@@ -149,15 +149,15 @@ void test_diff_tree__options(void)
diff, &actual, diff_file_fn, diff_hunk_fn, diff_line_fn)); diff, &actual, diff_file_fn, diff_hunk_fn, diff_line_fn));
expected = &test_expects[i]; expected = &test_expects[i];
cl_assert_intequal(actual.files, expected->files); cl_assert_equal_i(actual.files, expected->files);
cl_assert_intequal(actual.file_adds, expected->file_adds); cl_assert_equal_i(actual.file_adds, expected->file_adds);
cl_assert_intequal(actual.file_dels, expected->file_dels); cl_assert_equal_i(actual.file_dels, expected->file_dels);
cl_assert_intequal(actual.file_mods, expected->file_mods); cl_assert_equal_i(actual.file_mods, expected->file_mods);
cl_assert_intequal(actual.hunks, expected->hunks); cl_assert_equal_i(actual.hunks, expected->hunks);
cl_assert_intequal(actual.lines, expected->lines); cl_assert_equal_i(actual.lines, expected->lines);
cl_assert_intequal(actual.line_ctxt, expected->line_ctxt); cl_assert_equal_i(actual.line_ctxt, expected->line_ctxt);
cl_assert_intequal(actual.line_adds, expected->line_adds); cl_assert_equal_i(actual.line_adds, expected->line_adds);
cl_assert_intequal(actual.line_dels, expected->line_dels); cl_assert_equal_i(actual.line_dels, expected->line_dels);
git_diff_list_free(diff); git_diff_list_free(diff);
diff = NULL; diff = NULL;
......
...@@ -37,19 +37,19 @@ void test_diff_workdir__to_index(void) ...@@ -37,19 +37,19 @@ void test_diff_workdir__to_index(void)
* - git diff * - git diff
* - mv .git .gitted * - mv .git .gitted
*/ */
cl_assert_intequal(12, exp.files); cl_assert_equal_i(12, exp.files);
cl_assert_intequal(0, exp.file_adds); cl_assert_equal_i(0, exp.file_adds);
cl_assert_intequal(4, exp.file_dels); cl_assert_equal_i(4, exp.file_dels);
cl_assert_intequal(4, exp.file_mods); cl_assert_equal_i(4, exp.file_mods);
cl_assert_intequal(1, exp.file_ignored); cl_assert_equal_i(1, exp.file_ignored);
cl_assert_intequal(3, exp.file_untracked); cl_assert_equal_i(3, exp.file_untracked);
cl_assert_intequal(8, exp.hunks); cl_assert_equal_i(8, exp.hunks);
cl_assert_intequal(14, exp.lines); cl_assert_equal_i(14, exp.lines);
cl_assert_intequal(5, exp.line_ctxt); cl_assert_equal_i(5, exp.line_ctxt);
cl_assert_intequal(4, exp.line_adds); cl_assert_equal_i(4, exp.line_adds);
cl_assert_intequal(5, exp.line_dels); cl_assert_equal_i(5, exp.line_dels);
git_diff_list_free(diff); git_diff_list_free(diff);
} }
......
#include "clar_libgit2.h"
#include "refs.h"
static git_repository *g_repo;
void test_refs_lookup__initialize(void)
{
g_repo = cl_git_sandbox_init("testrepo.git");
}
void test_refs_lookup__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_refs_lookup__with_resolve(void)
{
git_reference *a, *b, *temp;
cl_git_pass(git_reference_lookup(&temp, g_repo, "HEAD"));
cl_git_pass(git_reference_resolve(&a, temp));
git_reference_free(temp);
cl_git_pass(git_reference_lookup_resolved(&b, g_repo, "HEAD", 5));
cl_assert(git_reference_cmp(a, b) == 0);
git_reference_free(b);
cl_git_pass(git_reference_lookup_resolved(&b, g_repo, "head-tracker", 5));
cl_assert(git_reference_cmp(a, b) == 0);
git_reference_free(b);
git_reference_free(a);
}
void test_refs_lookup__oid(void)
{
git_oid tag, expected;
cl_git_pass(git_reference_name_to_oid(&tag, g_repo, "refs/tags/point_to_blob"));
cl_git_pass(git_oid_fromstr(&expected, "1385f264afb75a56a5bec74243be9b367ba4ca08"));
cl_assert(git_oid_cmp(&tag, &expected) == 0);
}
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "fileops.h" #include "fileops.h"
#include <ctype.h>
void test_repo_open__cleanup(void) void test_repo_open__cleanup(void)
{ {
......
struct status_entry_counts { struct status_entry_counts {
int wrong_status_flags_count; size_t wrong_status_flags_count;
int wrong_sorted_path; size_t wrong_sorted_path;
int entry_count; size_t entry_count;
const unsigned int* expected_statuses; const unsigned int* expected_statuses;
const char** expected_paths; const char** expected_paths;
int expected_entry_count; size_t expected_entry_count;
}; };
/* entries for a plain copy of tests/resources/status */ /* entries for a plain copy of tests/resources/status */
......
...@@ -112,7 +112,7 @@ BEGIN_TEST(table2, "make sure the table resizes automatically") ...@@ -112,7 +112,7 @@ BEGIN_TEST(table2, "make sure the table resizes automatically")
const int objects_n = 64; const int objects_n = 64;
int i; int i;
unsigned int old_size; size_t old_size;
table_item *objects; table_item *objects;
git_hashtable *table = NULL; git_hashtable *table = NULL;
......
...@@ -87,7 +87,7 @@ void locate_loose_object(const char *repository_folder, git_object *object, char ...@@ -87,7 +87,7 @@ void locate_loose_object(const char *repository_folder, git_object *object, char
static const char *objects_folder = "objects/"; static const char *objects_folder = "objects/";
char *ptr, *full_path, *top_folder; char *ptr, *full_path, *top_folder;
int path_length, objects_length; size_t path_length, objects_length;
assert(repository_folder && object); assert(repository_folder && object);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment