summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blob.c26
-rw-r--r--src/blob.h6
-rw-r--r--src/bswap.h12
-rw-r--r--src/buffer.c6
-rw-r--r--src/buffer.h6
-rw-r--r--src/cache.c24
-rw-r--r--src/cache.h6
-rw-r--r--src/cc-compat.h23
-rw-r--r--src/commit.c24
-rw-r--r--src/commit.h6
-rw-r--r--src/common.h12
-rw-r--r--src/config.c29
-rw-r--r--src/config.h6
-rw-r--r--src/config_file.c53
-rw-r--r--src/delta-apply.c20
-rw-r--r--src/delta-apply.h6
-rw-r--r--src/dir.h20
-rw-r--r--src/errors.c26
-rw-r--r--src/fetch.c24
-rw-r--r--src/fetch.h6
-rw-r--r--src/filebuf.c41
-rw-r--r--src/filebuf.h6
-rw-r--r--src/fileops.c18
-rw-r--r--src/fileops.h15
-rw-r--r--src/hash.c24
-rw-r--r--src/hash.h5
-rw-r--r--src/hashtable.c24
-rw-r--r--src/hashtable.h6
-rw-r--r--src/index.c34
-rw-r--r--src/index.h6
-rw-r--r--src/indexer.c29
-rw-r--r--src/map.h28
-rw-r--r--src/mwindow.c34
-rw-r--r--src/mwindow.h24
-rw-r--r--src/netops.c24
-rw-r--r--src/netops.h5
-rw-r--r--src/object.c38
-rw-r--r--src/odb.c28
-rw-r--r--src/odb.h12
-rw-r--r--src/odb_loose.c68
-rw-r--r--src/odb_pack.c154
-rw-r--r--src/oid.c30
-rw-r--r--src/pack.c68
-rw-r--r--src/pack.h26
-rw-r--r--src/path.c136
-rw-r--r--src/path.h5
-rw-r--r--src/pkt.c32
-rw-r--r--src/pkt.h24
-rw-r--r--src/posix.c6
-rw-r--r--src/posix.h5
-rw-r--r--src/ppc/sha1.c10
-rw-r--r--src/ppc/sha1.h5
-rw-r--r--src/pqueue.c144
-rw-r--r--src/pqueue.h30
-rw-r--r--src/reflog.c26
-rw-r--r--src/reflog.h6
-rw-r--r--src/refs.c42
-rw-r--r--src/refs.h6
-rw-r--r--src/refspec.c26
-rw-r--r--src/refspec.h6
-rw-r--r--src/remote.c29
-rw-r--r--src/remote.h6
-rw-r--r--src/repository.c54
-rw-r--r--src/repository.h6
-rw-r--r--src/revwalk.c24
-rw-r--r--src/sha1.c33
-rw-r--r--src/sha1.h7
-rw-r--r--src/sha1_lookup.c93
-rw-r--r--src/sha1_lookup.h14
-rw-r--r--src/signature.c24
-rw-r--r--src/signature.h6
-rw-r--r--src/status.c758
-rw-r--r--src/tag.c32
-rw-r--r--src/tag.h6
-rw-r--r--src/thread-utils.c22
-rw-r--r--src/thread-utils.h12
-rw-r--r--src/transport.c6
-rw-r--r--src/transport.h8
-rw-r--r--src/transport_git.c30
-rw-r--r--src/transport_local.c6
-rw-r--r--src/tree.c177
-rw-r--r--src/tree.h6
-rw-r--r--src/tsort.c10
-rw-r--r--src/unix/map.c6
-rw-r--r--src/unix/posix.h6
-rw-r--r--src/util.c56
-rw-r--r--src/util.h10
-rw-r--r--src/vector.c24
-rw-r--r--src/vector.h6
-rw-r--r--src/win32/dir.c6
-rw-r--r--src/win32/fnmatch.c327
-rw-r--r--src/win32/fnmatch.h45
-rw-r--r--src/win32/map.c10
-rw-r--r--src/win32/mingw-compat.h8
-rw-r--r--src/win32/msvc-compat.h26
-rw-r--r--src/win32/posix.c33
-rw-r--r--src/win32/posix.h6
-rw-r--r--src/win32/pthread.c72
-rw-r--r--src/win32/pthread.h30
99 files changed, 1750 insertions, 1887 deletions
diff --git a/src/blob.c b/src/blob.c
index b8282e505..42564ab50 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "git2/common.h"
@@ -36,7 +18,7 @@ const void *git_blob_rawcontent(git_blob *blob)
return blob->odb_object->raw.data;
}
-int git_blob_rawsize(git_blob *blob)
+size_t git_blob_rawsize(git_blob *blob)
{
assert(blob);
return blob->odb_object->raw.len;
diff --git a/src/blob.h b/src/blob.h
index 4300d7e54..0cc9900c9 100644
--- a/src/blob.h
+++ b/src/blob.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_blob_h__
#define INCLUDE_blob_h__
diff --git a/src/bswap.h b/src/bswap.h
index b9211c3c8..0914906ff 100644
--- a/src/bswap.h
+++ b/src/bswap.h
@@ -1,8 +1,8 @@
/*
- * Let's make sure we always have a sane definition for ntohl()/htonl().
- * Some libraries define those as a function call, just to perform byte
- * shifting, bringing significant overhead to what should be a simple
- * operation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "common.h"
@@ -14,8 +14,8 @@
GIT_INLINE(uint32_t) default_swab32(uint32_t val)
{
return (((val & 0xff000000) >> 24) |
- ((val & 0x00ff0000) >> 8) |
- ((val & 0x0000ff00) << 8) |
+ ((val & 0x00ff0000) >> 8) |
+ ((val & 0x0000ff00) << 8) |
((val & 0x000000ff) << 24));
}
diff --git a/src/buffer.c b/src/buffer.c
index 6af4c9195..b1be29241 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#include "buffer.h"
#include "posix.h"
#include <stdarg.h>
diff --git a/src/buffer.h b/src/buffer.h
index 1209340a1..14233b82b 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_buffer_h__
#define INCLUDE_buffer_h__
diff --git a/src/cache.c b/src/cache.c
index fca7e1236..79f3eaea2 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "common.h"
diff --git a/src/cache.h b/src/cache.h
index 4794dea3a..8c885d9a5 100644
--- a/src/cache.h
+++ b/src/cache.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_cache_h__
#define INCLUDE_cache_h__
diff --git a/src/cc-compat.h b/src/cc-compat.h
index cf6cccf12..cce4ca9b1 100644
--- a/src/cc-compat.h
+++ b/src/cc-compat.h
@@ -1,5 +1,8 @@
/*
- * cc-compat.h - C compiler compat macros for internal use
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_compat_h__
#define INCLUDE_compat_h__
@@ -9,18 +12,18 @@
*/
#ifndef GIT_FLEX_ARRAY
# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
-# define GIT_FLEX_ARRAY /* empty */
+# define GIT_FLEX_ARRAY /* empty */
# elif defined(__GNUC__)
-# if (__GNUC__ >= 3)
-# define GIT_FLEX_ARRAY /* empty */
-# else
-# define GIT_FLEX_ARRAY 0 /* older GNU extension */
-# endif
+# if (__GNUC__ >= 3)
+# define GIT_FLEX_ARRAY /* empty */
+# else
+# define GIT_FLEX_ARRAY 0 /* older GNU extension */
+# endif
# endif
/* Default to safer but a bit wasteful traditional style */
# ifndef GIT_FLEX_ARRAY
-# define GIT_FLEX_ARRAY 1
+# define GIT_FLEX_ARRAY 1
# endif
#endif
@@ -34,9 +37,9 @@
# define GIT_UNUSED(x)
#else
# ifdef __GNUC__
-# define GIT_UNUSED(x) x __attribute__ ((__unused__))
+# define GIT_UNUSED(x) x __attribute__ ((__unused__))
# else
-# define GIT_UNUSED(x) x
+# define GIT_UNUSED(x) x
# endif
#endif
diff --git a/src/commit.c b/src/commit.c
index d9cc11078..0ee3854c4 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "git2/common.h"
diff --git a/src/commit.h b/src/commit.h
index 6d1caeeeb..bfc4bba19 100644
--- a/src/commit.h
+++ b/src/commit.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_commit_h__
#define INCLUDE_commit_h__
diff --git a/src/common.h b/src/common.h
index 5986a6568..f4ea1ebf7 100644
--- a/src/common.h
+++ b/src/common.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_common_h__
#define INCLUDE_common_h__
@@ -26,18 +32,20 @@
# include "win32/msvc-compat.h"
# include "win32/mingw-compat.h"
# ifdef GIT_THREADS
-# include "win32/pthread.h"
+# include "win32/pthread.h"
#endif
# define snprintf _snprintf
+#ifndef _SSIZE_T_DEFINED
typedef SSIZE_T ssize_t;
+#endif
#else
# include <unistd.h>
# ifdef GIT_THREADS
-# include <pthread.h>
+# include <pthread.h>
# endif
#endif
diff --git a/src/config.c b/src/config.c
index 771250731..f233e76fd 100644
--- a/src/config.c
+++ b/src/config.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "common.h"
@@ -43,6 +25,9 @@ void git_config_free(git_config *cfg)
git_config_file *file;
file_internal *internal;
+ if (cfg == NULL)
+ return;
+
for(i = 0; i < cfg->files.length; ++i){
internal = git_vector_get(&cfg->files, i);
file = internal->file;
@@ -169,7 +154,7 @@ int git_config_foreach(git_config *cfg, int (*fn)(const char *, const char *, vo
int git_config_delete(git_config *cfg, const char *name)
{
- return git_config_set_string(cfg, name, NULL);
+ return git_config_set_string(cfg, name, NULL);
}
/**************
diff --git a/src/config.h b/src/config.h
index e2f301bf1..7749a9c1a 100644
--- a/src/config.h
+++ b/src/config.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_config_h__
#define INCLUDE_config_h__
diff --git a/src/config_file.c b/src/config_file.c
index fc41590f6..f76efed97 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "common.h"
@@ -135,7 +117,7 @@ static int cvar_match_section(const char *local, const char *input)
{
char *first_dot;
char *local_sp = strchr(local, ' ');
- int comparison_len;
+ size_t comparison_len;
/*
* If the local section name doesn't contain a space, then we can
@@ -198,7 +180,8 @@ static int cvar_normalize_name(cvar_t *var, char **output)
{
char *section_sp = strchr(var->section, ' ');
char *quote, *name;
- int len, ret;
+ size_t len;
+ int ret;
/*
* The final string is going to be at most one char longer than
@@ -245,7 +228,7 @@ static int cvar_normalize_name(cvar_t *var, char **output)
static char *interiorize_section(const char *orig)
{
char *dot, *last_dot, *section, *ret;
- int len;
+ size_t len;
dot = strchr(orig, '.');
last_dot = strrchr(orig, '.');
@@ -530,7 +513,7 @@ static char *cfg_readline(diskfile_backend *cfg)
{
char *line = NULL;
char *line_src, *line_end;
- int line_len;
+ size_t line_len;
line_src = cfg->reader.read_ptr;
@@ -538,9 +521,9 @@ static char *cfg_readline(diskfile_backend *cfg)
while (isspace(*line_src))
++line_src;
- line_end = strchr(line_src, '\n');
+ line_end = strchr(line_src, '\n');
- /* no newline at EOF */
+ /* no newline at EOF */
if (line_end == NULL)
line_end = strchr(line_src, 0);
@@ -552,10 +535,8 @@ static char *cfg_readline(diskfile_backend *cfg)
memcpy(line, line_src, line_len);
- line[line_len] = '\0';
-
- while (--line_len >= 0 && isspace(line[line_len]))
- line[line_len] = '\0';
+ do line[line_len] = '\0';
+ while (line_len-- > 0 && isspace(line[line_len]));
if (*line_end == '\n')
line_end++;
@@ -600,7 +581,8 @@ GIT_INLINE(int) config_keychar(int c)
static int parse_section_header_ext(const char *line, const char *base_name, char **section_name)
{
- int buf_len, total_len, pos, rpos;
+ size_t buf_len, total_len;
+ int pos, rpos;
int c, ret;
char *subsection, *first_quote, *last_quote;
int error = GIT_SUCCESS;
@@ -764,7 +746,7 @@ static int skip_bom(diskfile_backend *cfg)
if (memcmp(cfg->reader.read_ptr, utf8_bom, sizeof(utf8_bom)) == 0)
cfg->reader.read_ptr += sizeof(utf8_bom);
- /* TODO: the reference implementation does pretty stupid
+ /* TODO: the reference implementation does pretty stupid
shit with the BoM
*/
@@ -1035,7 +1017,7 @@ static int config_write(diskfile_backend *cfg, cvar_t *var)
/* And then the write out rest of the file */
error = git_filebuf_write(&file, post_start,
- cfg->reader.buffer.len - (post_start - data_start));
+ cfg->reader.buffer.len - (post_start - data_start));
if (error < GIT_SUCCESS) {
git__rethrow(error, "Failed to write the rest of the file");
@@ -1100,7 +1082,8 @@ static int is_multiline_var(const char *str)
static int parse_multiline_variable(diskfile_backend *cfg, const char *first, char **out)
{
char *line = NULL, *end;
- int error = GIT_SUCCESS, len, ret;
+ int error = GIT_SUCCESS, ret;
+ size_t len;
char *buf;
/* Check that the next line exists */
diff --git a/src/delta-apply.c b/src/delta-apply.c
index a6b711436..e1fb15b9b 100644
--- a/src/delta-apply.c
+++ b/src/delta-apply.c
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#include "common.h"
#include "git2/odb.h"
#include "delta-apply.h"
@@ -5,7 +11,7 @@
/*
* This file was heavily cribbed from BinaryDelta.java in JGit, which
* itself was heavily cribbed from <code>patch-delta.c</code> in the
- * GIT project. The original delta patching code was written by
+ * GIT project. The original delta patching code was written by
* Nicolas Pitre <nico@cam.org>.
*/
@@ -64,15 +70,15 @@ int git__delta_apply(
*/
size_t off = 0, len = 0;
- if (cmd & 0x01) off = *delta++;
- if (cmd & 0x02) off |= *delta++ << 8;
+ if (cmd & 0x01) off = *delta++;
+ if (cmd & 0x02) off |= *delta++ << 8;
if (cmd & 0x04) off |= *delta++ << 16;
if (cmd & 0x08) off |= *delta++ << 24;
- if (cmd & 0x10) len = *delta++;
- if (cmd & 0x20) len |= *delta++ << 8;
+ if (cmd & 0x10) len = *delta++;
+ if (cmd & 0x20) len |= *delta++ << 8;
if (cmd & 0x40) len |= *delta++ << 16;
- if (!len) len = 0x10000;
+ if (!len) len = 0x10000;
if (base_len < off + len || res_sz < len)
goto fail;
@@ -87,7 +93,7 @@ int git__delta_apply(
if (delta_end - delta < cmd || res_sz < cmd)
goto fail;
memcpy(res_dp, delta, cmd);
- delta += cmd;
+ delta += cmd;
res_dp += cmd;
res_sz -= cmd;
diff --git a/src/delta-apply.h b/src/delta-apply.h
index 36c5cc60d..42ded3e0b 100644
--- a/src/delta-apply.h
+++ b/src/delta-apply.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_delta_apply_h__
#define INCLUDE_delta_apply_h__
diff --git a/src/dir.h b/src/dir.h
index c01c3fae7..ed517da33 100644
--- a/src/dir.h
+++ b/src/dir.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_dir_h__
#define INCLUDE_dir_h__
@@ -10,7 +16,7 @@
#ifdef GIT_WIN32
struct git__dirent {
- int d_ino;
+ int d_ino;
char d_name[261];
};
@@ -28,12 +34,12 @@ extern void git__rewinddir(git__DIR *);
extern int git__closedir(git__DIR *);
# ifndef GIT__WIN32_NO_WRAP_DIR
-# define dirent git__dirent
-# define DIR git__DIR
-# define opendir git__opendir
-# define readdir git__readdir
-# define rewinddir git__rewinddir
-# define closedir git__closedir
+# define dirent git__dirent
+# define DIR git__DIR
+# define opendir git__opendir
+# define readdir git__readdir
+# define rewinddir git__rewinddir
+# define closedir git__closedir
# endif
#endif
diff --git a/src/errors.c b/src/errors.c
index 5031245de..60d774636 100644
--- a/src/errors.c
+++ b/src/errors.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "common.h"
#include "git2/thread-utils.h" /* for GIT_TLS */
@@ -89,7 +71,7 @@ void git___rethrow(const char *msg, ...)
va_end(va);
old_error = strdup(g_last_error);
- snprintf(g_last_error, sizeof(g_last_error), "%s \n - %s", new_error, old_error);
+ snprintf(g_last_error, sizeof(g_last_error), "%s \n - %s", new_error, old_error);
free(old_error);
}
diff --git a/src/fetch.c b/src/fetch.c
index 74c93da8d..1bb896870 100644
--- a/src/fetch.c
+++ b/src/fetch.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "git2/remote.h"
diff --git a/src/fetch.h b/src/fetch.h
index ad4451ffe..6ca21d5b4 100644
--- a/src/fetch.h
+++ b/src/fetch.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_fetch_h__
#define INCLUDE_fetch_h__
diff --git a/src/filebuf.c b/src/filebuf.c
index 6d398a7db..bc1a8dceb 100644
--- a/src/filebuf.c
+++ b/src/filebuf.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include <stdarg.h>
@@ -116,24 +98,25 @@ static int write_deflate(git_filebuf *file, void *source, size_t len)
z_stream *zs = &file->zs;
if (len > 0 || file->flush_mode == Z_FINISH) {
- zs->next_in = (void *)source;
- zs->avail_in = len;
+ zs->next_in = source;
+ zs->avail_in = (uInt)len;
do {
- int have;
+ size_t have;
zs->next_out = file->z_buf;
- zs->avail_out = file->buf_size;
+ zs->avail_out = (uInt)file->buf_size;
- result = deflate(zs, file->flush_mode);
- assert(result != Z_STREAM_ERROR);
+ result = deflate(zs, file->flush_mode);
+ if (result == Z_STREAM_ERROR)
+ return git__throw(GIT_ERROR, "Failed to deflate input");
- have = file->buf_size - zs->avail_out;
+ have = file->buf_size - (size_t)zs->avail_out;
if (p_write(file->fd, file->z_buf, have) < GIT_SUCCESS)
return git__throw(GIT_EOSERR, "Failed to write to file");
- } while (zs->avail_out == 0);
+ } while (zs->avail_out == 0);
assert(zs->avail_in == 0);
diff --git a/src/filebuf.h b/src/filebuf.h
index 9154cabcd..d20881e9f 100644
--- a/src/filebuf.h
+++ b/src/filebuf.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_filebuf_h__
#define INCLUDE_filebuf_h__
diff --git a/src/fileops.c b/src/fileops.c
index d7413a138..bfd63f584 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#include "common.h"
#include "fileops.h"
#include <ctype.h>
@@ -188,7 +194,7 @@ int git_futils_readbuffer_updated(git_fbuffer *obj, const char *path, time_t *mt
*updated = 1;
obj->data = buff;
- obj->len = len;
+ obj->len = len;
return GIT_SUCCESS;
}
@@ -287,7 +293,7 @@ int git_futils_mkdir_r(const char *path, int mode)
{
int error, root_path_offset;
char *pp, *sp;
- char *path_copy = git__strdup(path);
+ char *path_copy = git__strdup(path);
if (path_copy == NULL)
return GIT_ENOMEM;
@@ -299,7 +305,7 @@ int git_futils_mkdir_r(const char *path, int mode)
if (root_path_offset > 0)
pp += root_path_offset; /* On Windows, will skip the drive name (eg. C: or D:) */
- while (error == GIT_SUCCESS && (sp = strchr(pp, '/')) != NULL) {
+ while (error == GIT_SUCCESS && (sp = strchr(pp, '/')) != NULL) {
if (sp != pp && git_futils_isdir(path_copy) < GIT_SUCCESS) {
*sp = 0;
error = p_mkdir(path_copy, mode);
@@ -353,7 +359,7 @@ int git_futils_rmdir_r(const char *path, int force)
{
char p[GIT_PATH_MAX];
strncpy(p, path, GIT_PATH_MAX);
- return _rmdir_recurs_foreach(&force, p);
+ return _rmdir_recurs_foreach(&force, p);
}
int git_futils_cmp_path(const char *name1, int len1, int isdir1,
@@ -367,10 +373,10 @@ int git_futils_cmp_path(const char *name1, int len1, int isdir1,
return cmp;
if (len1 < len2)
return ((!isdir1 && !isdir2) ? -1 :
- (isdir1 ? '/' - name2[len1] : name2[len1] - '/'));
+ (isdir1 ? '/' - name2[len1] : name2[len1] - '/'));
if (len1 > len2)
return ((!isdir1 && !isdir2) ? 1 :
- (isdir2 ? name1[len2] - '/' : '/' - name1[len2]));
+ (isdir2 ? name1[len2] - '/' : '/' - name1[len2]));
return 0;
}
diff --git a/src/fileops.h b/src/fileops.h
index 84c35e41b..5b69199d2 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -1,7 +1,8 @@
/*
- * fileops.h - OS agnostic disk io operations
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * This header describes the strictly internal part of the api
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_fileops_h__
#define INCLUDE_fileops_h__
@@ -19,9 +20,9 @@
*/
#define GIT_FBUFFER_INIT {NULL, 0}
-typedef struct { /* file io buffer */
- void *data; /* data bytes */
- size_t len; /* data length */
+typedef struct { /* file io buffer */
+ void *data; /* data bytes */
+ size_t len; /* data length */
} git_fbuffer;
extern int git_futils_readbuffer(git_fbuffer *obj, const char *path);
@@ -138,8 +139,8 @@ extern void git_futils_mmap_free(git_map *map);
* @param pathbuf buffer the function reads the initial directory
* path from, and updates with each successive entry's name.
* @param pathmax maximum allocation of pathbuf.
- * @param fn function to invoke with each entry. The first arg is
- * the input state and the second arg is pathbuf. The function
+ * @param fn function to invoke with each entry. The first arg is
+ * the input state and the second arg is pathbuf. The function
* may modify the pathbuf, but only by appending new text.
* @param state to pass to fn as the first arg.
*/
diff --git a/src/hash.c b/src/hash.c
index b8b311bcb..ff85ca957 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "common.h"
diff --git a/src/hash.h b/src/hash.h
index 2b769a4c9..fe1ba5d46 100644
--- a/src/hash.h
+++ b/src/hash.h
@@ -1,5 +1,8 @@
/*
- * hash.h
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_hash_h__
#define INCLUDE_hash_h__
diff --git a/src/hashtable.c b/src/hashtable.c
index 86e5a113a..1382eabaa 100644
--- a/src/hashtable.c
+++ b/src/hashtable.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "common.h"
diff --git a/src/hashtable.h b/src/hashtable.h
index be21be2b1..f0ca3ebd2 100644
--- a/src/hashtable.h
+++ b/src/hashtable.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_hashtable_h__
#define INCLUDE_hashtable_h__
diff --git a/src/index.c b/src/index.c
index f20c2a7ab..e6a181979 100644
--- a/src/index.c
+++ b/src/index.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include <stddef.h>
@@ -706,7 +688,7 @@ static int read_unmerged(git_index *index, const char *buffer, size_t size)
long tmp;
if (git__strtol32(&tmp, buffer, &endptr, 8) < GIT_SUCCESS ||
- !endptr || endptr == buffer || *endptr || tmp > UINT_MAX)
+ !endptr || endptr == buffer || *endptr || (unsigned)tmp > UINT_MAX)
return GIT_ERROR;
lost->mode[i] = tmp;
@@ -981,11 +963,11 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry)
ondisk->mtime.seconds = htonl((uint32_t)entry->mtime.seconds);
ondisk->ctime.nanoseconds = htonl(entry->ctime.nanoseconds);
ondisk->mtime.nanoseconds = htonl(entry->mtime.nanoseconds);
- ondisk->dev = htonl(entry->dev);
- ondisk->ino = htonl(entry->ino);
+ ondisk->dev = htonl(entry->dev);
+ ondisk->ino = htonl(entry->ino);
ondisk->mode = htonl(entry->mode);
- ondisk->uid = htonl(entry->uid);
- ondisk->gid = htonl(entry->gid);
+ ondisk->uid = htonl(entry->uid);
+ ondisk->gid = htonl(entry->gid);
ondisk->file_size = htonl((uint32_t)entry->file_size);
git_oid_cpy(&ondisk->oid, &entry->oid);
diff --git a/src/index.h b/src/index.h
index f2402fd71..76633a96a 100644
--- a/src/index.h
+++ b/src/index.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_index_h__
#define INCLUDE_index_h__
diff --git a/src/indexer.c b/src/indexer.c
index 3934250e2..07803355e 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "git2/indexer.h"
@@ -99,7 +81,7 @@ static int cache_cmp(const void *a, const void *b)
int git_indexer_new(git_indexer **out, const char *packname)
{
git_indexer *idx;
- unsigned int namelen;
+ size_t namelen;
int ret, error;
assert(out && packname);
@@ -186,7 +168,8 @@ static void index_path(char *path, git_indexer *idx)
int git_indexer_write(git_indexer *idx)
{
git_mwindow *w = NULL;
- int error, namelen;
+ int error;
+ size_t namelen;
unsigned int i, long_offsets = 0, left;
struct git_pack_idx_header hdr;
char filename[GIT_PATH_MAX];
diff --git a/src/map.h b/src/map.h
index 1dfbeeb4b..6969de5b3 100644
--- a/src/map.h
+++ b/src/map.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_map_h__
#define INCLUDE_map_h__
@@ -5,23 +11,23 @@
/* p_mmap() prot values */
-#define GIT_PROT_NONE 0x0
-#define GIT_PROT_READ 0x1
+#define GIT_PROT_NONE 0x0
+#define GIT_PROT_READ 0x1
#define GIT_PROT_WRITE 0x2
-#define GIT_PROT_EXEC 0x4
+#define GIT_PROT_EXEC 0x4
/* git__mmmap() flags values */
-#define GIT_MAP_FILE 0
-#define GIT_MAP_SHARED 1
+#define GIT_MAP_FILE 0
+#define GIT_MAP_SHARED 1
#define GIT_MAP_PRIVATE 2
-#define GIT_MAP_TYPE 0xf
-#define GIT_MAP_FIXED 0x10
+#define GIT_MAP_TYPE 0xf
+#define GIT_MAP_FIXED 0x10
-typedef struct { /* memory mapped buffer */
- void *data; /* data bytes */
- size_t len; /* data length */
+typedef struct { /* memory mapped buffer */
+ void *data; /* data bytes */
+ size_t len; /* data length */
#ifdef GIT_WIN32
- HANDLE fmh; /* file mapping handle */
+ HANDLE fmh; /* file mapping handle */
#endif
} git_map;
diff --git a/src/mwindow.c b/src/mwindow.c
index cf2427349..c126fa2bd 100644
--- a/src/mwindow.c
+++ b/src/mwindow.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "common.h"
@@ -31,11 +13,11 @@
#define DEFAULT_WINDOW_SIZE \
(sizeof(void*) >= 8 \
- ? 1 * 1024 * 1024 * 1024 \
+ ? 1 * 1024 * 1024 * 1024 \
: 32 * 1024 * 1024)
#define DEFAULT_MAPPED_LIMIT \
- ((1024L * 1024L) * (sizeof(void*) >= 8 ? 8192 : 256))
+ ((1024 * 1024) * (sizeof(void*) >= 8 ? 8192ULL : 256UL))
/*
* We need this because each process is only allowed a specific amount
@@ -183,7 +165,7 @@ static git_mwindow *new_window(git_mwindow_file *mwf, git_file fd, git_off_t siz
ctl.mapped += (size_t)len;
while(ctl.mapped_limit < ctl.mapped &&
- git_mwindow_close_lru(mwf) == GIT_SUCCESS) {}
+ git_mwindow_close_lru(mwf) == GIT_SUCCESS) {}
/* FIXME: Shouldn't we error out if there's an error in closing lru? */
@@ -211,7 +193,7 @@ cleanup:
* enough space. Don't forget to add it to your list
*/
unsigned char *git_mwindow_open(git_mwindow_file *mwf, git_mwindow **cursor,
- git_off_t offset, int extra, unsigned int *left)
+ git_off_t offset, int extra, unsigned int *left)
{
git_mwindow *w = *cursor;
@@ -259,7 +241,7 @@ int git_mwindow_file_register(git_mwindow_file *mwf)
int error;
if (ctl.windowfiles.length == 0 &&
- (error = git_vector_init(&ctl.windowfiles, 8, NULL)) < GIT_SUCCESS)
+ (error = git_vector_init(&ctl.windowfiles, 8, NULL)) < GIT_SUCCESS)
return error;
return git_vector_insert(&ctl.windowfiles, mwf);
diff --git a/src/mwindow.h b/src/mwindow.h
index 1d4a58453..ec75f901f 100644
--- a/src/mwindow.h
+++ b/src/mwindow.h
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_mwindow__
diff --git a/src/netops.c b/src/netops.c
index b5251925e..a237fae73 100644
--- a/src/netops.c
+++ b/src/netops.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef _WIN32
diff --git a/src/netops.h b/src/netops.h
index c259ed2d6..1aa7aebac 100644
--- a/src/netops.h
+++ b/src/netops.h
@@ -1,5 +1,8 @@
/*
- * netops.h - convencience functions for networking
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_netops_h__
#define INCLUDE_netops_h__
diff --git a/src/object.c b/src/object.c
index 8b07197f1..edc2d80fa 100644
--- a/src/object.c
+++ b/src/object.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include <stdarg.h>
@@ -37,8 +19,8 @@
static const int OBJECT_BASE_SIZE = 4096;
static struct {
- const char *str; /* type name string */
- int loose; /* valid loose object type flag */
+ const char *str; /* type name string */
+ int loose; /* valid loose object type flag */
size_t size; /* size in bytes of the object structure */
} git_objects_table[] = {
/* 0 = GIT_OBJ__EXT1 */
@@ -110,7 +92,7 @@ int git_object_lookup_prefix(git_object **object_out, git_repository *repo, cons
if (len > GIT_OID_HEXSZ)
len = GIT_OID_HEXSZ;
- if (len == GIT_OID_HEXSZ) {
+ if (len == GIT_OID_HEXSZ) {
/* We want to match the full id : we can first look up in the cache,
* since there is no need to check for non ambiguousity
*/
@@ -144,10 +126,10 @@ int git_object_lookup_prefix(git_object **object_out, git_repository *repo, cons
/* If len < GIT_OID_HEXSZ (a strict short oid was given), we have
* 2 options :
* - We always search in the cache first. If we find that short oid is
- * ambiguous, we can stop. But in all the other cases, we must then
- * explore all the backends (to find an object if there was match,
- * or to check that oid is not ambiguous if we have found 1 match in
- * the cache)
+ * ambiguous, we can stop. But in all the other cases, we must then
+ * explore all the backends (to find an object if there was match,
+ * or to check that oid is not ambiguous if we have found 1 match in
+ * the cache)
* - We never explore the cache, go right to exploring the backends
* We chose the latter : we explore directly the backends.
*/
diff --git a/src/odb.c b/src/odb.c
index ec81cdacb..02809beec 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "common.h"
@@ -75,9 +57,9 @@ int git_odb__hash_obj(git_oid *id, git_rawobj *obj)
return git__rethrow(hdrlen, "Failed to hash object");
vec[0].data = header;
- vec[0].len = hdrlen;
+ vec[0].len = hdrlen;
vec[1].data = obj->data;
- vec[1].len = obj->len;
+ vec[1].len = obj->len;
git_hash_vec(id, vec, 2);
diff --git a/src/odb.h b/src/odb.h
index 1d4f07dcc..4e850916b 100644
--- a/src/odb.h
+++ b/src/odb.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_odb_h__
#define INCLUDE_odb_h__
@@ -10,9 +16,9 @@
/* DO NOT EXPORT */
typedef struct {
- void *data; /**< Raw, decompressed object data. */
- size_t len; /**< Total number of bytes in data. */
- git_otype type; /**< Type of this object. */
+ void *data; /**< Raw, decompressed object data. */
+ size_t len; /**< Total number of bytes in data. */
+ git_otype type; /**< Type of this object. */
} git_rawobj;
/* EXPORT */
diff --git a/src/odb_loose.c b/src/odb_loose.c
index f78750899..3ca46d1b5 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "common.h"
@@ -36,9 +18,9 @@
#include "git2/odb_backend.h"
#include "git2/types.h"
-typedef struct { /* object header data */
- git_otype type; /* object type */
- size_t size; /* object size */
+typedef struct { /* object header data */
+ git_otype type; /* object type */
+ size_t size; /* object size */
} obj_hdr;
typedef struct {
@@ -142,7 +124,7 @@ static size_t get_object_header(obj_hdr *hdr, unsigned char *data)
if (used == 0)
return 0;
hdr->type = git_object_string2type(typename);
- used++; /* consume the space */
+ used++; /* consume the space */
/*
* length follows immediately in decimal (without
@@ -182,20 +164,20 @@ static size_t get_object_header(obj_hdr *hdr, unsigned char *data)
static void init_stream(z_stream *s, void *out, size_t len)
{
memset(s, 0, sizeof(*s));
- s->next_out = out;
- s->avail_out = len;
+ s->next_out = out;
+ s->avail_out = (uInt)len;
}
static void set_stream_input(z_stream *s, void *in, size_t len)
{
- s->next_in = in;
- s->avail_in = len;
+ s->next_in = in;
+ s->avail_in = (uInt)len;
}
static void set_stream_output(z_stream *s, void *out, size_t len)
{
- s->next_out = out;
- s->avail_out = len;
+ s->next_out = out;
+ s->avail_out = (uInt)len;
}
@@ -242,11 +224,11 @@ static int inflate_buffer(void *in, size_t inlen, void *out, size_t outlen)
memset(&zs, 0x0, sizeof(zs));
- zs.next_out = out;
- zs.avail_out = outlen;
+ zs.next_out = out;
+ zs.avail_out = (uInt)outlen;
- zs.next_in = in;
- zs.avail_in = inlen;
+ zs.next_in = in;
+ zs.avail_in = (uInt)inlen;
if (inflateInit(&zs) < Z_OK)
return git__throw(GIT_ERROR, "Failed to inflate buffer");
@@ -332,7 +314,7 @@ static int inflate_packlike_loose_disk_obj(git_rawobj *out, git_fbuffer *obj)
if (!buf)
return GIT_ENOMEM;
- in = ((unsigned char *)obj->data) + used;
+ in = ((unsigned char *)obj->data) + used;
len = obj->len - used;
if (inflate_buffer(in, len, buf, hdr.size)) {
free(buf);
@@ -341,7 +323,7 @@ static int inflate_packlike_loose_disk_obj(git_rawobj *out, git_fbuffer *obj)
buf[hdr.size] = '\0';
out->data = buf;
- out->len = hdr.size;
+ out->len = hdr.size;
out->type = hdr.type;
return GIT_SUCCESS;
@@ -382,7 +364,7 @@ static int inflate_disk_obj(git_rawobj *out, git_fbuffer *obj)
buf[hdr.size] = '\0';
out->data = buf;
- out->len = hdr.size;
+ out->len = hdr.size;
out->type = hdr.type;
return GIT_SUCCESS;
@@ -410,7 +392,7 @@ static int read_loose(git_rawobj *out, const char *loc)
assert(out && loc);
out->data = NULL;
- out->len = 0;
+ out->len = 0;
out->type = GIT_OBJ_BAD;
if (git_futils_readbuffer(&obj, loc) < 0)
@@ -461,7 +443,7 @@ static int read_header_loose(git_rawobj *out, const char *loc)
goto cleanup;
}
- out->len = header_obj.size;
+ out->len = header_obj.size;
out->type = header_obj.type;
cleanup:
@@ -712,8 +694,8 @@ static int format_object_header(char *hdr, size_t n, size_t obj_len, git_otype o
const char *type_str = git_object_type2string(obj_type);
int len = snprintf(hdr, n, "%s %"PRIuZ, type_str, obj_len);
- assert(len > 0); /* otherwise snprintf() is broken */
- assert(((size_t) len) < n); /* otherwise the caller is broken! */
+ assert(len > 0); /* otherwise snprintf() is broken */
+ assert(((size_t) len) < n); /* otherwise the caller is broken! */
if (len < 0 || ((size_t) len) >= n)
return git__throw(GIT_ERROR, "Failed to format object header. Length is out of bounds");
@@ -726,7 +708,7 @@ static int loose_backend__stream(git_odb_stream **stream_out, git_odb_backend *_
loose_writestream *stream;
char hdr[64], tmp_path[GIT_PATH_MAX];
- int hdrlen;
+ int hdrlen;
int error;
assert(_backend);
diff --git a/src/odb_pack.c b/src/odb_pack.c
index b3db27280..4607fb74a 100644
--- a/src/odb_pack.c
+++ b/src/odb_pack.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "common.h"
@@ -48,9 +30,9 @@ struct pack_backend {
/**
* The wonderful tale of a Packed Object lookup query
* ===================================================
- * A riveting and epic story of epicness and ASCII
- * art, presented by yours truly,
- * Sir Vicent of Marti
+ * A riveting and epic story of epicness and ASCII
+ * art, presented by yours truly,
+ * Sir Vicent of Marti
*
*
* Chapter 1: Once upon a time...
@@ -61,32 +43,32 @@ struct pack_backend {
* | Creates the pack backend structure, initializes the
* | callback pointers to our default read() and exist() methods,
* | and tries to preload all the known packfiles in the ODB.
- * |
+ * |
* |-# packfile_load_all
- * | Tries to find the `pack` folder, if it exists. ODBs without
- * | a pack folder are ignored altogether. If there's a `pack` folder
- * | we run a `dirent` callback through every file in the pack folder
- * | to find our packfiles. The packfiles are then sorted according
- * | to a sorting callback.
- * |
- * |-# packfile_load__cb
- * | | This callback is called from `dirent` with every single file
- * | | inside the pack folder. We find the packs by actually locating
- * | | their index (ends in ".idx"). From that index, we verify that
- * | | the corresponding packfile exists and is valid, and if so, we
- * | | add it to the pack list.
- * | |
- * | |-# packfile_check
- * | Make sure that there's a packfile to back this index, and store
- * | some very basic information regarding the packfile itself,
- * | such as the full path, the size, and the modification time.
- * | We don't actually open the packfile to check for internal consistency.
- * |
- * |-# packfile_sort__cb
- * Sort all the preloaded packs according to some specific criteria:
- * we prioritize the "newer" packs because it's more likely they
- * contain the objects we are looking for, and we prioritize local
- * packs over remote ones.
+ * | Tries to find the `pack` folder, if it exists. ODBs without
+ * | a pack folder are ignored altogether. If there's a `pack` folder
+ * | we run a `dirent` callback through every file in the pack folder
+ * | to find our packfiles. The packfiles are then sorted according
+ * | to a sorting callback.
+ * |
+ * |-# packfile_load__cb
+ * | | This callback is called from `dirent` with every single file
+ * | | inside the pack folder. We find the packs by actually locating
+ * | | their index (ends in ".idx"). From that index, we verify that
+ * | | the corresponding packfile exists and is valid, and if so, we
+ * | | add it to the pack list.
+ * | |
+ * | |-# packfile_check
+ * | Make sure that there's a packfile to back this index, and store
+ * | some very basic information regarding the packfile itself,
+ * | such as the full path, the size, and the modification time.
+ * | We don't actually open the packfile to check for internal consistency.
+ * |
+ * |-# packfile_sort__cb
+ * Sort all the preloaded packs according to some specific criteria:
+ * we prioritize the "newer" packs because it's more likely they
+ * contain the objects we are looking for, and we prioritize local
+ * packs over remote ones.
*
*
*
@@ -94,41 +76,41 @@ struct pack_backend {
* A standard packed `exist` query for an OID
* --------------------------------------------------
*
- * # pack_backend__exists
- * | Check if the given SHA1 oid exists in any of the packs
- * | that have been loaded for our ODB.
- * |
- * |-# pack_entry_find
- * | Iterate through all the packs that have been preloaded
- * | (starting by the pack where the latest object was found)
- * | to try to find the OID in one of them.
- * |
- * |-# pack_entry_find1
- * | Check the index of an individual pack to see if the SHA1
- * | OID can be found. If we can find the offset to that SHA1
- * | inside of the index, that means the object is contained
- * | inside of the packfile and we can stop searching.
- * | Before returning, we verify that the packfile behing the
- * | index we are searching still exists on disk.
- * |
- * |-# pack_entry_find_offset
- * | | Mmap the actual index file to disk if it hasn't been opened
- * | | yet, and run a binary search through it to find the OID.
- * | | See <http://book.git-scm.com/7_the_packfile.html> for specifics
- * | | on the Packfile Index format and how do we find entries in it.
- * | |
- * | |-# pack_index_open
- * | | Guess the name of the index based on the full path to the
- * | | packfile, open it and verify its contents. Only if the index
- * | | has not been opened already.
- * | |
- * | |-# pack_index_check
- * | Mmap the index file and do a quick run through the header
- * | to guess the index version (right now we support v1 and v2),
- * | and to verify that the size of the index makes sense.
- * |
- * |-# packfile_open
- * See `packfile_open` in Chapter 3
+ * # pack_backend__exists
+ * | Check if the given SHA1 oid exists in any of the packs
+ * | that have been loaded for our ODB.
+ * |
+ * |-# pack_entry_find
+ * | Iterate through all the packs that have been preloaded
+ * | (starting by the pack where the latest object was found)
+ * | to try to find the OID in one of them.
+ * |
+ * |-# pack_entry_find1
+ * | Check the index of an individual pack to see if the SHA1
+ * | OID can be found. If we can find the offset to that SHA1
+ * | inside of the index, that means the object is contained
+ * | inside of the packfile and we can stop searching.
+ * | Before returning, we verify that the packfile behing the
+ * | index we are searching still exists on disk.
+ * |
+ * |-# pack_entry_find_offset
+ * | | Mmap the actual index file to disk if it hasn't been opened
+ * | | yet, and run a binary search through it to find the OID.
+ * | | See <http://book.git-scm.com/7_the_packfile.html> for specifics
+ * | | on the Packfile Index format and how do we find entries in it.
+ * | |
+ * | |-# pack_index_open
+ * | | Guess the name of the index based on the full path to the
+ * | | packfile, open it and verify its contents. Only if the index
+ * | | has not been opened already.
+ * | |
+ * | |-# pack_index_check
+ * | Mmap the index file and do a quick run through the header
+ * | to guess the index version (right now we support v1 and v2),
+ * | and to verify that the size of the index makes sense.
+ * |
+ * |-# packfile_open
+ * See `packfile_open` in Chapter 3
*
*
*
@@ -188,7 +170,7 @@ GIT_INLINE(int) pack_window_contains(git_mwindow *win, off_t offset)
/* We must promise at least 20 bytes (one hash) after the
* offset is available from this window, otherwise the offset
* is not actually in this window and a different window (which
- * has that one hash excess) must be used. This is to support
+ * has that one hash excess) must be used. This is to support
* the object header and delta base parsing routines below.
*/
return git_mwindow_contains(win, offset + 20);
@@ -202,7 +184,7 @@ static int packfile_sort__cb(const void *a_, const void *b_)
/*
* Local packs tend to contain objects specific to our
- * variant of the project than remote ones. In addition,
+ * variant of the project than remote ones. In addition,
* remote ones could be on a network mounted filesystem.
* Favor local ones for these reasons.
*/
diff --git a/src/oid.c b/src/oid.c
index f12ba30b9..e2d16d537 100644
--- a/src/oid.c
+++ b/src/oid.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "common.h"
@@ -33,7 +15,7 @@ static signed char from_hex[] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 00 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 10 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 20 */
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /* 30 */
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /* 30 */
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 40 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 50 */
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 60 */
@@ -61,7 +43,7 @@ int git_oid_fromstrn(git_oid *out, const char *str, size_t length)
for (p = 0; p < length; p += 2) {
int v = (from_hex[(unsigned char)str[p + 0]] << 4)
- | from_hex[(unsigned char)str[p + 1]];
+ | from_hex[(unsigned char)str[p + 1]];
if (v < 0)
return git__throw(GIT_ENOTOID, "Failed to generate sha1. Given string is not a valid sha1 hash");
@@ -122,7 +104,7 @@ char *git_oid_to_string(char *out, size_t n, const git_oid *oid)
if (!out || n == 0 || !oid)
return "";
- n--; /* allow room for terminating NUL */
+ n--; /* allow room for terminating NUL */
if (n > 0) {
git_oid_fmt(str, oid);
diff --git a/src/pack.c b/src/pack.c
index d882516be..8de2d7814 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "mwindow.h"
@@ -70,7 +52,7 @@ static void pack_index_free(struct git_pack_file *p)
}
}
-static int pack_index_check(const char *path, struct git_pack_file *p)
+static int pack_index_check(const char *path, struct git_pack_file *p)
{
struct git_pack_idx_header *hdr;
uint32_t version, nr, i, *index;
@@ -126,7 +108,7 @@ static int pack_index_check(const char *path, struct git_pack_file *p)
index = idx_map;
if (version > 1)
- index += 2; /* skip index header */
+ index += 2; /* skip index header */
for (i = 0; i < 256; i++) {
uint32_t n = ntohl(index[i]);
@@ -140,10 +122,10 @@ static int pack_index_check(const char *path, struct git_pack_file *p)
if (version == 1) {
/*
* Total size:
- * - 256 index entries 4 bytes each
- * - 24-byte entries * nr (20-byte sha1 + 4-byte offset)
- * - 20-byte SHA1 of the packfile
- * - 20-byte SHA1 file checksum
+ * - 256 index entries 4 bytes each
+ * - 24-byte entries * nr (20-byte sha1 + 4-byte offset)
+ * - 20-byte SHA1 of the packfile
+ * - 20-byte SHA1 file checksum
*/
if (idx_size != 4*256 + nr * 24 + 20 + 20) {
git_futils_mmap_free(&p->index_map);
@@ -152,13 +134,13 @@ static int pack_index_check(const char *path, struct git_pack_file *p)
} else if (version == 2) {
/*
* Minimum size:
- * - 8 bytes of header
- * - 256 index entries 4 bytes each
- * - 20-byte sha1 entry * nr
- * - 4-byte crc entry * nr
- * - 4-byte offset entry * nr
- * - 20-byte SHA1 of the packfile
- * - 20-byte SHA1 file checksum
+ * - 8 bytes of header
+ * - 256 index entries 4 bytes each
+ * - 20-byte sha1 entry * nr
+ * - 4-byte crc entry * nr
+ * - 4-byte offset entry * nr
+ * - 20-byte SHA1 of the packfile
+ * - 20-byte SHA1 file checksum
* And after the 4-byte offset table might be a
* variable sized table containing 8-byte entries
* for offsets larger than 2^31.
@@ -263,8 +245,8 @@ int git_packfile_unpack_header(
unsigned long used;
/* pack_window_open() assures us we have [base, base + 20) available
- * as a range that we can look at at. (Its actually the hash
- * size that is assured.) With our object header encoding
+ * as a range that we can look at at. (Its actually the hash
+ * size that is assured.) With our object header encoding
* the maximum deflated object size is 2^137, which is just
* insane, so we know won't exceed what we have been given.
*/
@@ -404,7 +386,7 @@ int packfile_unpack_compressed(
memset(&stream, 0, sizeof(stream));
stream.next_out = buffer;
- stream.avail_out = size + 1;
+ stream.avail_out = (uInt)size + 1;
st = inflateInit(&stream);
if (st != Z_OK) {
@@ -453,8 +435,8 @@ off_t get_delta_base(
/* pack_window_open() assured us we have [base_info, base_info + 20)
* as a range that we can look at without walking off the
- * end of the mapped window. Its actually the hash size
- * that is assured. An OFS_DELTA longer than the hash size
+ * end of the mapped window. Its actually the hash size
+ * that is assured. An OFS_DELTA longer than the hash size
* is stupid, as then a REF_DELTA would be smaller to store.
*/
if (type == GIT_OBJ_OFS_DELTA) {
@@ -464,13 +446,13 @@ off_t get_delta_base(
while (c & 128) {
base_offset += 1;
if (!base_offset || MSB(base_offset, 7))
- return 0; /* overflow */
+ return 0; /* overflow */
c = base_info[used++];
base_offset = (base_offset << 7) + (c & 127);
}
base_offset = delta_obj_offset - base_offset;
if (base_offset <= 0 || base_offset >= delta_obj_offset)
- return 0; /* out of bound */
+ return 0; /* out of bound */
*curpos += used;
} else if (type == GIT_OBJ_REF_DELTA) {
/* If we have the cooperative cache, search in it first */
@@ -668,7 +650,7 @@ static off_t nth_packed_object_offset(const struct git_pack_file *p, uint32_t n)
return off;
index += p->num_objects * 4 + (off & 0x7fffffff) * 8;
return (((uint64_t)ntohl(*((uint32_t *)(index + 0)))) << 32) |
- ntohl(*((uint32_t *)(index + 4)));
+ ntohl(*((uint32_t *)(index + 4)));
}
}
@@ -721,7 +703,7 @@ static int pack_entry_find_offset(
#endif
/* Use git.git lookup code */
- pos = sha1_entry_pos(index, stride, 0, lo, hi, p->num_objects, short_oid->id);
+ pos = sha1_entry_pos(index, stride, 0, lo, hi, p->num_objects, short_oid->id);
if (pos >= 0) {
/* An object matching exactly the oid was found */
diff --git a/src/pack.h b/src/pack.h
index 164086fdf..0fddd9dc8 100644
--- a/src/pack.h
+++ b/src/pack.h
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_pack_h__
@@ -56,7 +38,7 @@ struct git_pack_header {
* Very old git binaries will also compare the first 4 bytes to the
* next 4 bytes in the index and abort with a "non-monotonic index"
* error if the second 4 byte word is smaller than the first 4
- * byte word. This would be true in the proposed future index
+ * byte word. This would be true in the proposed future index
* format as idx_signature would be greater than idx_version.
*/
diff --git a/src/path.c b/src/path.c
index 1f7a16679..2c6b76dd0 100644
--- a/src/path.c
+++ b/src/path.c
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#include "common.h"
#include "path.h"
#include "posix.h"
@@ -17,8 +23,8 @@ int git_path_basename_r(char *buffer, size_t bufflen, const char *path)
/* Empty or NULL string gets treated as "." */
if (path == NULL || *path == '\0') {
- startp = ".";
- len = 1;
+ startp = ".";
+ len = 1;
goto Exit;
}
@@ -30,7 +36,7 @@ int git_path_basename_r(char *buffer, size_t bufflen, const char *path)
/* All slashes becomes "/" */
if (endp == path && *endp == '/') {
startp = "/";
- len = 1;
+ len = 1;
goto Exit;
}
@@ -47,7 +53,7 @@ Exit:
return result;
}
if (len > (int)bufflen-1) {
- len = (int)bufflen-1;
+ len = (int)bufflen-1;
result = GIT_ENOMEM;
}
@@ -64,93 +70,103 @@ Exit:
*/
int git_path_dirname_r(char *buffer, size_t bufflen, const char *path)
{
- const char *endp;
- int result, len;
-
- /* Empty or NULL string gets treated as "." */
- if (path == NULL || *path == '\0') {
- path = ".";
- len = 1;
- goto Exit;
- }
-
- /* Strip trailing slashes */
- endp = path + strlen(path) - 1;
- while (endp > path && *endp == '/')
- endp--;
-
- /* Find the start of the dir */
- while (endp > path && *endp != '/')
- endp--;
-
- /* Either the dir is "/" or there are no slashes */
- if (endp == path) {
- path = (*endp == '/') ? "/" : ".";
- len = 1;
- goto Exit;
- }
-
- do {
- endp--;
- } while (endp > path && *endp == '/');
-
- len = endp - path +1;
+ const char *endp;
+ int result, len;
+
+ /* Empty or NULL string gets treated as "." */
+ if (path == NULL || *path == '\0') {
+ path = ".";
+ len = 1;
+ goto Exit;
+ }
+
+ /* Strip trailing slashes */
+ endp = path + strlen(path) - 1;
+ while (endp > path && *endp == '/')
+ endp--;
+
+ /* Find the start of the dir */
+ while (endp > path && *endp != '/')
+ endp--;
+
+ /* Either the dir is "/" or there are no slashes */
+ if (endp == path) {
+ path = (*endp == '/') ? "/" : ".";
+ len = 1;
+ goto Exit;
+ }
+
+ do {
+ endp--;
+ } while (endp > path && *endp == '/');
+
+ len = endp - path +1;
+
+#ifdef GIT_WIN32
+ /* Mimic unix behavior where '/.git' returns '/': 'C:/.git' will return
+ 'C:/' here */
+
+ if (len == 2 && isalpha(path[0]) && path[1] == ':') {
+ len = 3;
+ goto Exit;
+ }
+#endif
Exit:
- result = len;
- if (len+1 > GIT_PATH_MAX) {
- return GIT_ENOMEM;
- }
- if (buffer == NULL)
- return result;
-
- if (len > (int)bufflen-1) {
- len = (int)bufflen-1;
- result = GIT_ENOMEM;
- }
-
- if (len >= 0) {
- memmove(buffer, path, len);
- buffer[len] = 0;
- }
- return result;
+ result = len;
+ if (len+1 > GIT_PATH_MAX) {
+ return GIT_ENOMEM;
+ }
+ if (buffer == NULL)
+ return result;
+
+ if (len > (int)bufflen-1) {
+ len = (int)bufflen-1;
+ result = GIT_ENOMEM;
+ }
+
+ if (len >= 0) {
+ memmove(buffer, path, len);
+ buffer[len] = 0;
+ }
+ return result;
}
char *git_path_dirname(const char *path)
{
- char *dname = NULL;
- int len;
+ char *dname = NULL;
+ int len;
len = (path ? strlen(path) : 0) + 2;
dname = (char *)git__malloc(len);
if (dname == NULL)
return NULL;
- if (git_path_dirname_r(dname, len, path) < GIT_SUCCESS) {
+ if (git_path_dirname_r(dname, len, path) < GIT_SUCCESS) {
free(dname);
return NULL;
}
- return dname;
+ return dname;
}
char *git_path_basename(const char *path)
{
- char *bname = NULL;
- int len;
+ char *bname = NULL;
+ int len;
len = (path ? strlen(path) : 0) + 2;
bname = (char *)git__malloc(len);
if (bname == NULL)
return NULL;
- if (git_path_basename_r(bname, len, path) < GIT_SUCCESS) {
+ if (git_path_basename_r(bname, len, path) < GIT_SUCCESS) {
free(bname);
return NULL;
}
- return bname;
+ return bname;
}
diff --git a/src/path.h b/src/path.h
index 36e22a768..51bedeed7 100644
--- a/src/path.h
+++ b/src/path.h
@@ -1,5 +1,8 @@
/*
- * posix.h - Path management methods
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_path_h__
#define INCLUDE_path_h__
diff --git a/src/pkt.c b/src/pkt.c
index 4eac0411f..e0beb72e0 100644
--- a/src/pkt.c
+++ b/src/pkt.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "common.h"
@@ -181,11 +163,11 @@ static ssize_t parse_len(const char *line)
/*
* As per the documentation, the syntax is:
*
- * pkt-line = data-pkt / flush-pkt
- * data-pkt = pkt-len pkt-payload
- * pkt-len = 4*(HEXDIG)
+ * pkt-line = data-pkt / flush-pkt
+ * data-pkt = pkt-len pkt-payload
+ * pkt-len = 4*(HEXDIG)
* pkt-payload = (pkt-len -4)*(OCTET)
- * flush-pkt = "0000"
+ * flush-pkt = "0000"
*
* Which means that the first four bytes are the length of the line,
* in ASCII hexadecimal (including itself)
diff --git a/src/pkt.h b/src/pkt.h
index 1c6a20659..5a94024de 100644
--- a/src/pkt.h
+++ b/src/pkt.h
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_pkt_h__
diff --git a/src/posix.c b/src/posix.c
index 4bb8c3246..61c79b071 100644
--- a/src/posix.c
+++ b/src/posix.c
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#include "common.h"
#include "posix.h"
#include "path.h"
diff --git a/src/posix.h b/src/posix.h
index f1424f8d3..7c1ac66c5 100644
--- a/src/posix.h
+++ b/src/posix.h
@@ -1,5 +1,8 @@
/*
- * posix.h - OS agnostic POSIX calls
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_posix_h__
#define INCLUDE_posix_h__
diff --git a/src/ppc/sha1.c b/src/ppc/sha1.c
index ec6a1926d..a34bf2557 100644
--- a/src/ppc/sha1.c
+++ b/src/ppc/sha1.c
@@ -1,17 +1,15 @@
/*
- * SHA-1 implementation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * Copyright (C) 2005 Paul Mackerras <paulus@samba.org>
- *
- * This version assumes we are running on a big-endian machine.
- * It calls an external sha1_core() to process blocks of 64 bytes.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include <stdio.h>
#include <string.h>
#include "sha1.h"
extern void ppc_sha1_core(uint32_t *hash, const unsigned char *p,
- unsigned int nblocks);
+ unsigned int nblocks);
int ppc_SHA1_Init(ppc_SHA_CTX *c)
{
diff --git a/src/ppc/sha1.h b/src/ppc/sha1.h
index 70957110c..7448381ab 100644
--- a/src/ppc/sha1.h
+++ b/src/ppc/sha1.h
@@ -1,7 +1,8 @@
/*
- * SHA-1 implementation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * Copyright (C) 2005 Paul Mackerras <paulus@samba.org>
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include <stdint.h>
diff --git a/src/pqueue.c b/src/pqueue.c
index 9883a35d8..b5ddab835 100644
--- a/src/pqueue.c
+++ b/src/pqueue.c
@@ -1,52 +1,36 @@
/*
- * BORING COPYRIGHT NOTICE:
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * This file is a heavily modified version of the priority queue found
- * in the Apache project and the libpqueue library.
- *
- * https://github.com/vy/libpqueue
- *
- * These are the original authors:
- *
- * Copyright 2010 Volkan Yazıcı <volkan.yazici@gmail.com>
- * Copyright 2006-2010 The Apache Software Foundation
- *
- * This file is licensed under the Apache 2.0 license, which
- * supposedly makes it compatible with the GPLv2 that libgit2 uses.
- *
- * Check the Apache license at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * So much licensing trouble for a binary heap. Oh well.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "common.h"
#include "pqueue.h"
-#define left(i) ((i) << 1)
-#define right(i) (((i) << 1) + 1)
+#define left(i) ((i) << 1)
+#define right(i) (((i) << 1) + 1)
#define parent(i) ((i) >> 1)
int git_pqueue_init(git_pqueue *q, size_t n, git_pqueue_cmp cmppri)
{
assert(q);
- /* Need to allocate n+1 elements since element 0 isn't used. */
- if ((q->d = malloc((n + 1) * sizeof(void *))) == NULL)
+ /* Need to allocate n+1 elements since element 0 isn't used. */
+ if ((q->d = malloc((n + 1) * sizeof(void *))) == NULL)
return GIT_ENOMEM;
- q->size = 1;
- q->avail = q->step = (n + 1); /* see comment above about n+1 */
- q->cmppri = cmppri;
+ q->size = 1;
+ q->avail = q->step = (n + 1); /* see comment above about n+1 */
+ q->cmppri = cmppri;
- return GIT_SUCCESS;
+ return GIT_SUCCESS;
}
void git_pqueue_free(git_pqueue *q)
{
- free(q->d);
+ free(q->d);
q->d = NULL;
}
@@ -57,101 +41,101 @@ void git_pqueue_clear(git_pqueue *q)
size_t git_pqueue_size(git_pqueue *q)
{
- /* queue element 0 exists but doesn't count since it isn't used. */
- return (q->size - 1);
+ /* queue element 0 exists but doesn't count since it isn't used. */
+ return (q->size - 1);
}
static void bubble_up(git_pqueue *q, size_t i)
{
- size_t parent_node;
- void *moving_node = q->d[i];
+ size_t parent_node;
+ void *moving_node = q->d[i];
- for (parent_node = parent(i);
- ((i > 1) && q->cmppri(q->d[parent_node], moving_node));
- i = parent_node, parent_node = parent(i)) {
- q->d[i] = q->d[parent_node];
- }
+ for (parent_node = parent(i);
+ ((i > 1) && q->cmppri(q->d[parent_node], moving_node));
+ i = parent_node, parent_node = parent(i)) {
+ q->d[i] = q->d[parent_node];
+ }
- q->d[i] = moving_node;
+ q->d[i] = moving_node;
}
static size_t maxchild(git_pqueue *q, size_t i)
{
- size_t child_node = left(i);
+ size_t child_node = left(i);
- if (child_node >= q->size)
- return 0;
+ if (child_node >= q->size)
+ return 0;
- if ((child_node + 1) < q->size &&
- q->cmppri(q->d[child_node], q->d[child_node + 1]))
- child_node++; /* use right child instead of left */
+ if ((child_node + 1) < q->size &&
+ q->cmppri(q->d[child_node], q->d[child_node + 1]))
+ child_node++; /* use right child instead of left */
- return child_node;
+ return child_node;
}
static void percolate_down(git_pqueue *q, size_t i)
{
- size_t child_node;
- void *moving_node = q->d[i];
+ size_t child_node;
+ void *moving_node = q->d[i];
- while ((child_node = maxchild(q, i)) != 0 &&
- q->cmppri(moving_node, q->d[child_node])) {
- q->d[i] = q->d[child_node];
- i = child_node;
- }
+ while ((child_node = maxchild(q, i)) != 0 &&
+ q->cmppri(moving_node, q->d[child_node])) {
+ q->d[i] = q->d[child_node];
+ i = child_node;
+ }
- q->d[i] = moving_node;
+ q->d[i] = moving_node;
}
int git_pqueue_insert(git_pqueue *q, void *d)
{
- void *tmp;
- size_t i;
- size_t newsize;
+ void *tmp;
+ size_t i;
+ size_t newsize;
- if (!q) return 1;
+ if (!q) return 1;
- /* allocate more memory if necessary */
- if (q->size >= q->avail) {
- newsize = q->size + q->step;
- if ((tmp = realloc(q->d, sizeof(void *) * newsize)) == NULL)
- return GIT_ENOMEM;
+ /* allocate more memory if necessary */
+ if (q->size >= q->avail) {
+ newsize = q->size + q->step;
+ if ((tmp = realloc(q->d, sizeof(void *) * newsize)) == NULL)
+ return GIT_ENOMEM;
- q->d = tmp;
- q->avail = newsize;
- }
+ q->d = tmp;
+ q->avail = newsize;
+ }
- /* insert item */
- i = q->size++;
- q->d[i] = d;
- bubble_up(q, i);
+ /* insert item */
+ i = q->size++;
+ q->d[i] = d;
+ bubble_up(q, i);
- return GIT_SUCCESS;
+ return GIT_SUCCESS;
}
void *git_pqueue_pop(git_pqueue *q)
{
- void *head;
+ void *head;
- if (!q || q->size == 1)
- return NULL;
+ if (!q || q->size == 1)
+ return NULL;
- head = q->d[1];
- q->d[1] = q->d[--q->size];
- percolate_down(q, 1);
+ head = q->d[1];
+ q->d[1] = q->d[--q->size];
+ percolate_down(q, 1);
- return head;
+ return head;
}
void *git_pqueue_peek(git_pqueue *q)
{
- if (!q || q->size == 1)
- return NULL;
- return q->d[1];
+ if (!q || q->size == 1)
+ return NULL;
+ return q->d[1];
}
diff --git a/src/pqueue.h b/src/pqueue.h
index ef8362c33..6826055e5 100644
--- a/src/pqueue.h
+++ b/src/pqueue.h
@@ -1,24 +1,8 @@
/*
- * BORING COPYRIGHT NOTICE:
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * This file is a heavily modified version of the priority queue found
- * in the Apache project and the libpqueue library.
- *
- * https://github.com/vy/libpqueue
- *
- * These are the original authors:
- *
- * Copyright 2010 Volkan Yazıcı <volkan.yazici@gmail.com>
- * Copyright 2006-2010 The Apache Software Foundation
- *
- * This file is licensed under the Apache 2.0 license, which
- * supposedly makes it compatible with the GPLv2 that libgit2 uses.
- *
- * Check the Apache license at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * So much licensing trouble for a binary heap. Oh well.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_pqueue_h__
@@ -29,9 +13,9 @@ typedef int (*git_pqueue_cmp)(void *a, void *b);
/** the priority queue handle */
typedef struct {
- size_t size, avail, step;
- git_pqueue_cmp cmppri;
- void **d;
+ size_t size, avail, step;
+ git_pqueue_cmp cmppri;
+ void **d;
} git_pqueue;
@@ -39,7 +23,7 @@ typedef struct {
* initialize the queue
*
* @param n the initial estimate of the number of queue items for which memory
- * should be preallocated
+ * should be preallocated
* @param cmppri the callback function to compare two nodes of the queue
*
* @Return the handle or NULL for insufficent memory
diff --git a/src/reflog.c b/src/reflog.c
index d28e5cba1..594963c03 100644
--- a/src/reflog.c
+++ b/src/reflog.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "reflog.h"
@@ -223,7 +205,7 @@ int git_reflog_read(git_reflog **reflog, git_reference *ref)
}
int git_reflog_write(git_reference *ref, const git_oid *oid_old,
- const git_signature *committer, const char *msg)
+ const git_signature *committer, const char *msg)
{
int error;
char old[GIT_OID_HEXSZ+1];
diff --git a/src/reflog.h b/src/reflog.h
index b6daf2a76..093874e51 100644
--- a/src/reflog.h
+++ b/src/reflog.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_reflog_h__
#define INCLUDE_reflog_h__
diff --git a/src/refs.c b/src/refs.c
index 04347d221..bc8827b46 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "refs.h"
@@ -512,7 +494,7 @@ static int packed_load(git_repository *repo)
}
error = reference_read(&packfile, &ref_cache->packfile_time,
- repo->path_repository, GIT_PACKEDREFS_FILE, &updated);
+ repo->path_repository, GIT_PACKEDREFS_FILE, &updated);
/*
* If we couldn't find the file, we need to clear the table and
@@ -845,7 +827,7 @@ static int packed_write(git_repository *repo)
const void *GIT_UNUSED(_unused);
GIT_HASHTABLE_FOREACH(repo->references.packfile, _unused, reference,
- git_vector_insert(&packing_list, reference); /* cannot fail: vector already has the right size */
+ git_vector_insert(&packing_list, reference); /* cannot fail: vector already has the right size */
);
}
@@ -923,7 +905,7 @@ static int _reference_available_cb(const char *ref, void *data)
const char *lead = reflen < newlen ? new : ref;
if (!strncmp(new, ref, cmplen) &&
- lead[cmplen] == '/')
+ lead[cmplen] == '/')
return GIT_EEXISTS;
}
@@ -1072,7 +1054,7 @@ int git_reference_create_symbolic(git_reference **ref_out, git_repository *repo,
* need a new reference because we can't make a symbolic ref out
* of an oid one.
* If if didn't exist, then we need to create a new one anyway.
- */
+ */
if (ref && ref->type & GIT_REF_SYMBOLIC){
updated = 1;
} else {
@@ -1131,7 +1113,7 @@ int git_reference_create_oid(git_reference **ref_out, git_repository *repo, cons
* need a new reference because we can't make a symbolic ref out
* of an oid one.
* If if didn't exist, then we need to create a new one anyway.
- */
+ */
if (ref && ref-> type & GIT_REF_OID){
updated = 1;
} else {
@@ -1362,10 +1344,10 @@ int git_reference_rename(git_reference *ref, const char *new_name, int force)
* writes reflogs by default in any repo with a working directory:
*
* "We only enable reflogs in repositories that have a working directory
- * associated with them, as shared/bare repositories do not have
- * an easy means to prune away old log entries, or may fail logging
- * entirely if the user's gecos information is not valid during a push.
- * This heuristic was suggested on the mailing list by Junio."
+ * associated with them, as shared/bare repositories do not have
+ * an easy means to prune away old log entries, or may fail logging
+ * entirely if the user's gecos information is not valid during a push.
+ * This heuristic was suggested on the mailing list by Junio."
*
* Shawn O. Pearce - 0bee59186976b1d9e6b2dd77332480c9480131d5
*
diff --git a/src/refs.h b/src/refs.h
index dfac455e0..979af2ee2 100644
--- a/src/refs.h
+++ b/src/refs.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_refs_h__
#define INCLUDE_refs_h__
diff --git a/src/refspec.c b/src/refspec.c
index 8500e07ea..9de273071 100644
--- a/src/refspec.c
+++ b/src/refspec.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "git2/errors.h"
@@ -73,7 +55,7 @@ int git_refspec_src_match(const git_refspec *refspec, const char *refname)
return git__fnmatch(refspec->src, refname, 0);
}
-int git_refspec_transform(char *out, size_t outlen, const git_refspec *spec, const char *name)
+int git_refspec_transform(char *out, size_t outlen, const git_refspec *spec, const char *name)
{
size_t baselen, namelen;
diff --git a/src/refspec.h b/src/refspec.h
index 230135a4a..58f3fe472 100644
--- a/src/refspec.h
+++ b/src/refspec.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_refspec_h__
#define INCLUDE_refspec_h__
diff --git a/src/remote.c b/src/remote.c
index 0cd1d9994..f581b973f 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "git2/remote.h"
@@ -128,7 +110,7 @@ int git_remote_get(git_remote **out, git_config *cfg, const char *name)
error = git_config_get_string(cfg, buf, &val);
if (error < GIT_SUCCESS) {
- error = git__rethrow(error, "Remote's url doesn't exist");
+ error = git__rethrow(error, "Remote's url doesn't exist");
goto cleanup;
}
@@ -262,6 +244,9 @@ int git_remote_update_tips(struct git_remote *remote)
void git_remote_free(git_remote *remote)
{
+ if (remote == NULL)
+ return;
+
free(remote->fetch.src);
free(remote->fetch.dst);
free(remote->push.src);
diff --git a/src/remote.h b/src/remote.h
index 21313acd4..66b9dd8f8 100644
--- a/src/remote.h
+++ b/src/remote.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_remote_h__
#define INCLUDE_remote_h__
diff --git a/src/repository.c b/src/repository.c
index 7d243398b..bb7ef396d 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include <stdarg.h>
@@ -288,7 +270,6 @@ cleanup:
int git_repository_config(
git_config **out,
git_repository *repo,
- const char *user_config_path,
const char *system_config_path)
{
char config_path[GIT_PATH_MAX];
@@ -305,10 +286,9 @@ int git_repository_config(
if (error < GIT_SUCCESS)
goto cleanup;
- if (user_config_path != NULL) {
- error = git_config_add_file_ondisk(*out, user_config_path, 2);
- if (error < GIT_SUCCESS)
- goto cleanup;
+ error = git_config_find_global(config_path);
+ if (error == GIT_SUCCESS) {
+ error = git_config_add_file_ondisk(*out, config_path, 2);
}
if (system_config_path != NULL) {
@@ -729,19 +709,31 @@ int git_repository_head_detached(git_repository *repo)
return 1;
}
-int git_repository_head_orphan(git_repository *repo)
+int git_repository_head(git_reference **head_out, git_repository *repo)
{
git_reference *ref;
int error;
+ *head_out = NULL;
+
error = git_reference_lookup(&ref, repo, GIT_HEAD_FILE);
if (error < GIT_SUCCESS)
- return error;
-
- if (git_reference_type(ref) == GIT_REF_OID)
- return 0;
+ return git__rethrow(GIT_ENOTAREPO, "Failed to locate the HEAD");
error = git_reference_resolve(&ref, ref);
+ if (error < GIT_SUCCESS)
+ return git__rethrow(error, "Failed to resolve the HEAD");
+
+ *head_out = ref;
+ return GIT_SUCCESS;
+}
+
+int git_repository_head_orphan(git_repository *repo)
+{
+ git_reference *ref;
+ int error;
+
+ error = git_repository_head(&ref, repo);
return error == GIT_ENOTFOUND ? 1 : error;
}
diff --git a/src/repository.h b/src/repository.h
index 2e0b9e352..99217e5a4 100644
--- a/src/repository.h
+++ b/src/repository.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_repository_h__
#define INCLUDE_repository_h__
diff --git a/src/revwalk.c b/src/revwalk.c
index 667291899..72eb69aba 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "common.h"
diff --git a/src/sha1.c b/src/sha1.c
index 0bccb4953..4043fb168 100644
--- a/src/sha1.c
+++ b/src/sha1.c
@@ -1,9 +1,8 @@
/*
- * SHA1 routine optimized to do word accesses rather than byte accesses,
- * and to avoid unnecessary copies into the context array.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * This was initially based on the Mozilla SHA1 implementation, although
- * none of the original Mozilla code remains.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "common.h"
@@ -53,11 +52,11 @@
*/
#if defined(__i386__) || defined(__x86_64__)
- #define setW(x, val) (*(volatile unsigned int *)&W(x) = (val))
+ #define setW(x, val) (*(volatile unsigned int *)&W(x) = (val))
#elif defined(__GNUC__) && defined(__arm__)
- #define setW(x, val) do { W(x) = (val); __asm__("":::"memory"); } while (0)
+ #define setW(x, val) do { W(x) = (val); __asm__("":::"memory"); } while (0)
#else
- #define setW(x, val) (W(x) = (val))
+ #define setW(x, val) (W(x) = (val))
#endif
/*
@@ -68,10 +67,10 @@
*/
#if defined(__i386__) || defined(__x86_64__) || \
- defined(_M_IX86) || defined(_M_X64) || \
- defined(__ppc__) || defined(__ppc64__) || \
- defined(__powerpc__) || defined(__powerpc64__) || \
- defined(__s390__) || defined(__s390x__)
+ defined(_M_IX86) || defined(_M_X64) || \
+ defined(__ppc__) || defined(__ppc64__) || \
+ defined(__powerpc__) || defined(__powerpc64__) || \
+ defined(__s390__) || defined(__s390x__)
#define get_be32(p) ntohl(*(const unsigned int *)(p))
#define put_be32(p, v) do { *(unsigned int *)(p) = htonl(v); } while (0)
@@ -81,14 +80,14 @@
#define get_be32(p) ( \
(*((const unsigned char *)(p) + 0) << 24) | \
(*((const unsigned char *)(p) + 1) << 16) | \
- (*((const unsigned char *)(p) + 2) << 8) | \
- (*((const unsigned char *)(p) + 3) << 0) )
+ (*((const unsigned char *)(p) + 2) << 8) | \
+ (*((const unsigned char *)(p) + 3) << 0) )
#define put_be32(p, v) do { \
unsigned int __v = (v); \
*((unsigned char *)(p) + 0) = __v >> 24; \
*((unsigned char *)(p) + 1) = __v >> 16; \
- *((unsigned char *)(p) + 2) = __v >> 8; \
- *((unsigned char *)(p) + 3) = __v >> 0; } while (0)
+ *((unsigned char *)(p) + 2) = __v >> 8; \
+ *((unsigned char *)(p) + 3) = __v >> 0; } while (0)
#endif
@@ -107,11 +106,11 @@
E += TEMP + SHA_ROL(A,5) + (fn) + (constant); \
B = SHA_ROR(B, 2); } while (0)
-#define T_0_15(t, A, B, C, D, E) SHA_ROUND(t, SHA_SRC, (((C^D)&B)^D) , 0x5a827999, A, B, C, D, E )
+#define T_0_15(t, A, B, C, D, E) SHA_ROUND(t, SHA_SRC, (((C^D)&B)^D) , 0x5a827999, A, B, C, D, E )
#define T_16_19(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, (((C^D)&B)^D) , 0x5a827999, A, B, C, D, E )
#define T_20_39(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, (B^C^D) , 0x6ed9eba1, A, B, C, D, E )
#define T_40_59(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, ((B&C)+(D&(B^C))) , 0x8f1bbcdc, A, B, C, D, E )
-#define T_60_79(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, (B^C^D) , 0xca62c1d6, A, B, C, D, E )
+#define T_60_79(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, (B^C^D) , 0xca62c1d6, A, B, C, D, E )
static void blk_SHA1_Block(blk_SHA_CTX *ctx, const unsigned int *data)
{
diff --git a/src/sha1.h b/src/sha1.h
index 558d6aece..f1e905e76 100644
--- a/src/sha1.h
+++ b/src/sha1.h
@@ -1,9 +1,8 @@
/*
- * SHA1 routine optimized to do word accesses rather than byte accesses,
- * and to avoid unnecessary copies into the context array.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * This was initially based on the Mozilla SHA1 implementation, although
- * none of the original Mozilla code remains.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
typedef struct {
diff --git a/src/sha1_lookup.c b/src/sha1_lookup.c
index 6ac00c5aa..3051568a3 100644
--- a/src/sha1_lookup.c
+++ b/src/sha1_lookup.c
@@ -1,27 +1,8 @@
/*
- * This file is basically taken from git code.
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include <stdio.h>
@@ -33,69 +14,69 @@
* Conventional binary search loop looks like this:
*
* unsigned lo, hi;
- * do {
- * unsigned mi = (lo + hi) / 2;
- * int cmp = "entry pointed at by mi" minus "target";
- * if (!cmp)
- * return (mi is the wanted one)
- * if (cmp > 0)
- * hi = mi; "mi is larger than target"
- * else
- * lo = mi+1; "mi is smaller than target"
- * } while (lo < hi);
+ * do {
+ * unsigned mi = (lo + hi) / 2;
+ * int cmp = "entry pointed at by mi" minus "target";
+ * if (!cmp)
+ * return (mi is the wanted one)
+ * if (cmp > 0)
+ * hi = mi; "mi is larger than target"
+ * else
+ * lo = mi+1; "mi is smaller than target"
+ * } while (lo < hi);
*
* The invariants are:
*
* - When entering the loop, lo points at a slot that is never
- * above the target (it could be at the target), hi points at a
- * slot that is guaranteed to be above the target (it can never
- * be at the target).
+ * above the target (it could be at the target), hi points at a
+ * slot that is guaranteed to be above the target (it can never
+ * be at the target).
*
* - We find a point 'mi' between lo and hi (mi could be the same
- * as lo, but never can be as same as hi), and check if it hits
- * the target. There are three cases:
+ * as lo, but never can be as same as hi), and check if it hits
+ * the target. There are three cases:
*
- * - if it is a hit, we are happy.
+ * - if it is a hit, we are happy.
*
- * - if it is strictly higher than the target, we set it to hi,
- * and repeat the search.
+ * - if it is strictly higher than the target, we set it to hi,
+ * and repeat the search.
*
- * - if it is strictly lower than the target, we update lo to
- * one slot after it, because we allow lo to be at the target.
+ * - if it is strictly lower than the target, we update lo to
+ * one slot after it, because we allow lo to be at the target.
*
- * If the loop exits, there is no matching entry.
+ * If the loop exits, there is no matching entry.
*
* When choosing 'mi', we do not have to take the "middle" but
* anywhere in between lo and hi, as long as lo <= mi < hi is
- * satisfied. When we somehow know that the distance between the
+ * satisfied. When we somehow know that the distance between the
* target and lo is much shorter than the target and hi, we could
* pick mi that is much closer to lo than the midway.
*
* Now, we can take advantage of the fact that SHA-1 is a good hash
* function, and as long as there are enough entries in the table, we
- * can expect uniform distribution. An entry that begins with for
+ * can expect uniform distribution. An entry that begins with for
* example "deadbeef..." is much likely to appear much later than in
- * the midway of the table. It can reasonably be expected to be near
+ * the midway of the table. It can reasonably be expected to be near
* 87% (222/256) from the top of the table.
*
- * However, we do not want to pick "mi" too precisely. If the entry at
+ * However, we do not want to pick "mi" too precisely. If the entry at
* the 87% in the above example turns out to be higher than the target
* we are looking for, we would end up narrowing the search space down
* only by 13%, instead of 50% we would get if we did a simple binary
- * search. So we would want to hedge our bets by being less aggressive.
+ * search. So we would want to hedge our bets by being less aggressive.
*
* The table at "table" holds at least "nr" entries of "elem_size"
- * bytes each. Each entry has the SHA-1 key at "key_offset". The
- * table is sorted by the SHA-1 key of the entries. The caller wants
+ * bytes each. Each entry has the SHA-1 key at "key_offset". The
+ * table is sorted by the SHA-1 key of the entries. The caller wants
* to find the entry with "key", and knows that the entry at "lo" is
* not higher than the entry it is looking for, and that the entry at
* "hi" is higher than the entry it is looking for.
*/
int sha1_entry_pos(const void *table,
- size_t elem_size,
- size_t key_offset,
- unsigned lo, unsigned hi, unsigned nr,
- const unsigned char *key)
+ size_t elem_size,
+ size_t key_offset,
+ unsigned lo, unsigned hi, unsigned nr,
+ const unsigned char *key)
{
const unsigned char *base = (const unsigned char*)table;
const unsigned char *hi_key, *lo_key;
@@ -157,7 +138,7 @@ int sha1_entry_pos(const void *table,
* end up narrowing the search space by a smaller
* amount (i.e. the distance between 'mi' and 'hi')
* than what we would have (i.e. about half of 'lo'
- * and 'hi'). Hedge our bets to pick 'mi' less
+ * and 'hi'). Hedge our bets to pick 'mi' less
* aggressively, i.e. make 'mi' a bit closer to the
* middle than we would otherwise pick.
*/
@@ -173,7 +154,7 @@ int sha1_entry_pos(const void *table,
#ifdef INDEX_DEBUG_LOOKUP
printf("lo %u hi %u rg %u mi %u ", lo, hi, range, mi);
printf("ofs %u lov %x, hiv %x, kyv %x\n",
- ofs_0, lov, hiv, kyv);
+ ofs_0, lov, hiv, kyv);
#endif
if (!(lo <= mi && mi < hi)) {
diff --git a/src/sha1_lookup.h b/src/sha1_lookup.h
index 5caa2f5ed..52282e672 100644
--- a/src/sha1_lookup.h
+++ b/src/sha1_lookup.h
@@ -1,12 +1,18 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_sha1_lookup_h__
#define INCLUDE_sha1_lookup_h__
#include <stdlib.h>
int sha1_entry_pos(const void *table,
- size_t elem_size,
- size_t key_offset,
- unsigned lo, unsigned hi, unsigned nr,
- const unsigned char *key);
+ size_t elem_size,
+ size_t key_offset,
+ unsigned lo, unsigned hi, unsigned nr,
+ const unsigned char *key);
#endif
diff --git a/src/signature.c b/src/signature.c
index 1890581fa..7cc3733bc 100644
--- a/src/signature.c
+++ b/src/signature.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "common.h"
diff --git a/src/signature.h b/src/signature.h
index 2fe6cd7c9..a66060661 100644
--- a/src/signature.h
+++ b/src/signature.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_signature_h__
#define INCLUDE_signature_h__
diff --git a/src/status.c b/src/status.c
index d9613c129..66fe8cbd6 100644
--- a/src/status.c
+++ b/src/status.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "common.h"
@@ -30,10 +12,9 @@
#include "vector.h"
#include "tree.h"
#include "git2/status.h"
+#include "repository.h"
struct status_entry {
- char path[GIT_PATH_MAX];
-
git_index_time mtime;
git_oid head_oid;
@@ -41,321 +22,646 @@ struct status_entry {
git_oid wt_oid;
unsigned int status_flags:6;
+
+ char path[GIT_FLEX_ARRAY]; /* more */
};
-static int status_cmp(const void *a, const void *b)
+static struct status_entry *status_entry_new(git_vector *entries, const char *path)
{
- const struct status_entry *entry_a = (const struct status_entry *)(a);
- const struct status_entry *entry_b = (const struct status_entry *)(b);
+ struct status_entry *e = git__malloc(sizeof(*e) + strlen(path) + 1);
+ if (e == NULL)
+ return NULL;
- return strcmp(entry_a->path, entry_b->path);
+ memset(e, 0x0, sizeof(*e));
+
+ if (entries != NULL)
+ git_vector_insert(entries, e);
+
+ strcpy(e->path, path);
+
+ return e;
}
-static int status_srch(const void *key, const void *array_member)
+GIT_INLINE(void) status_entry_update_from_tree_entry(struct status_entry *e, const git_tree_entry *tree_entry)
{
- const char *path = (const char *)key;
- const struct status_entry *entry = (const struct status_entry *)(array_member);
+ assert(e && tree_entry);
- return strcmp(path, entry->path);
+ git_oid_cpy(&e->head_oid, &tree_entry->oid);
}
-static int find_status_entry(git_vector *entries, const char *path)
+GIT_INLINE(void) status_entry_update_from_index_entry(struct status_entry *e, const git_index_entry *index_entry)
{
- return git_vector_bsearch2(entries, status_srch, path);
+ assert(e && index_entry);
+
+ git_oid_cpy(&e->index_oid, &index_entry->oid);
+ e->mtime = index_entry->mtime;
}
-static struct status_entry *new_status_entry(git_vector *entries, const char *path)
+static void status_entry_update_from_index(struct status_entry *e, git_index *index)
{
- struct status_entry *e = git__malloc(sizeof(struct status_entry));
- memset(e, 0x0, sizeof(struct status_entry));
- if (entries != NULL)
- git_vector_insert(entries, e);
- strcpy(e->path, path);
- return e;
+ int idx;
+ git_index_entry *index_entry;
+
+ assert(e && index);
+
+ idx = git_index_find(index, e->path);
+ if (idx < 0)
+ return;
+
+ index_entry = git_index_get(index, idx);
+
+ status_entry_update_from_index_entry(e, index_entry);
}
-static void recurse_tree_entries(git_tree *tree, git_vector *entries, char *path)
+static int status_entry_update_from_workdir(struct status_entry *e, char* full_path)
{
- int i, cnt, idx;
- struct status_entry *e;
- char file_path[GIT_PATH_MAX];
- git_tree *subtree;
+ struct stat filest;
- cnt = git_tree_entrycount(tree);
- for (i = 0; i < cnt; ++i) {
- const git_tree_entry *tree_entry = git_tree_entry_byindex(tree, i);
+ if (p_stat(full_path, &filest) < GIT_SUCCESS)
+ return git__throw(GIT_EOSERR, "Failed to determine status of file '%s'. Can't read file", full_path);
- git_path_join(file_path, path, tree_entry->filename);
+ if (e->mtime.seconds == (git_time_t)filest.st_mtime)
+ git_oid_cpy(&e->wt_oid, &e->index_oid);
+ else
+ git_odb_hashfile(&e->wt_oid, full_path, GIT_OBJ_BLOB);
- if (git_tree_lookup(&subtree, tree->object.repo, &tree_entry->oid) == GIT_SUCCESS) {
- recurse_tree_entries(subtree, entries, file_path);
- git_tree_close(subtree);
- continue;
- }
+ return GIT_SUCCESS;
+}
- if ((idx = find_status_entry(entries, file_path)) != GIT_ENOTFOUND)
- e = (struct status_entry *)git_vector_get(entries, idx);
- else
- e = new_status_entry(entries, file_path);
+static int status_entry_update_flags(struct status_entry *e)
+{
+ git_oid zero;
+ int head_zero, index_zero, wt_zero;
- git_oid_cpy(&e->head_oid, &tree_entry->oid);
- }
+ memset(&zero, 0x0, sizeof(git_oid));
+
+ head_zero = git_oid_cmp(&zero, &e->head_oid);
+ index_zero = git_oid_cmp(&zero, &e->index_oid);
+ wt_zero = git_oid_cmp(&zero, &e->wt_oid);
+
+ if (head_zero == 0 && index_zero == 0 && wt_zero == 0)
+ return GIT_ENOTFOUND;
+
+ if (head_zero == 0 && index_zero != 0)
+ e->status_flags |= GIT_STATUS_INDEX_NEW;
+ else if (index_zero == 0 && head_zero != 0)
+ e->status_flags |= GIT_STATUS_INDEX_DELETED;
+ else if (git_oid_cmp(&e->head_oid, &e->index_oid) != 0)
+ e->status_flags |= GIT_STATUS_INDEX_MODIFIED;
+
+ if (index_zero == 0 && wt_zero != 0)
+ e->status_flags |= GIT_STATUS_WT_NEW;
+ else if (wt_zero == 0 && index_zero != 0)
+ e->status_flags |= GIT_STATUS_WT_DELETED;
+ else if (git_oid_cmp(&e->index_oid, &e->wt_oid) != 0)
+ e->status_flags |= GIT_STATUS_WT_MODIFIED;
+
+ return GIT_SUCCESS;
}
-static void recurse_tree_entry(git_tree *tree, struct status_entry *e, const char *path)
+struct status_st {
+ git_vector *vector;
+ git_index *index;
+ git_tree *tree;
+
+ int workdir_path_len;
+ char* head_tree_relative_path;
+ int head_tree_relative_path_len;
+ unsigned int tree_position;
+ unsigned int index_position;
+ int is_dir:1;
+};
+
+static int retrieve_head_tree(git_tree **tree_out, git_repository *repo)
{
- char *dir_sep;
- char buffer[GIT_PATH_MAX];
- const git_tree_entry *tree_entry;
- git_tree *subtree;
+ git_reference *resolved_head_ref;
+ git_commit *head_commit = NULL;
+ git_tree *tree;
+ int error = GIT_SUCCESS;
- strcpy(buffer, path);
+ *tree_out = NULL;
- dir_sep = strchr(buffer, '/');
- if (dir_sep) {
- *dir_sep = '\0';
+ error = git_repository_head(&resolved_head_ref, repo);
+ if (error != GIT_SUCCESS && error != GIT_ENOTFOUND)
+ return git__rethrow(error, "HEAD can't be resolved");
- tree_entry = git_tree_entry_byname(tree, buffer);
- if (tree_entry != NULL) {
- if (git_tree_lookup(&subtree, tree->object.repo, &tree_entry->oid) == GIT_SUCCESS) {
- recurse_tree_entry(subtree, e, dir_sep+1);
- git_tree_close(subtree);
- return;
- }
- }
+ /*
+ * We assume that a situation where HEAD exists but can not be resolved is valid.
+ * A new repository fits this description for instance.
+ */
+
+ if (error == GIT_ENOTFOUND)
+ return GIT_SUCCESS;
+
+ if ((error = git_commit_lookup(&head_commit, repo, git_reference_oid(resolved_head_ref))) < GIT_SUCCESS)
+ return git__rethrow(error, "The tip of HEAD can't be retrieved");
+
+ if ((error = git_commit_tree(&tree, head_commit)) < GIT_SUCCESS) {
+ error = git__rethrow(error, "The tree of HEAD can't be retrieved");
+ goto exit;
}
- tree_entry = git_tree_entry_byname(tree, path);
- if (tree_entry != NULL) {
- git_oid_cpy(&e->head_oid, &tree_entry->oid);
+ *tree_out = tree;
+
+exit:
+ git_commit_close(head_commit);
+ return error;
+}
+
+#define GIT_STATUS_PATH_NULL -2
+#define GIT_STATUS_PATH_IGNORE -1
+#define GIT_STATUS_PATH_FILE 0
+#define GIT_STATUS_PATH_FOLDER 1
+
+static int dirent_cb(void *state, char *full_path);
+static int alphasorted_futils_direach(
+ char *path, size_t path_sz,
+ int (*fn)(void *, char *), void *arg);
+
+static int process_folder(struct status_st *st, const git_tree_entry *tree_entry, char *full_path, int path_type)
+{
+ git_object *subtree = NULL;
+ git_tree *pushed_tree = NULL;
+ int error, pushed_tree_position = 0;
+ git_otype tree_entry_type;
+
+ tree_entry_type = git_tree_entry_type(tree_entry);
+
+ switch (tree_entry_type) {
+ case GIT_OBJ_TREE:
+ error = git_tree_entry_2object(&subtree, ((git_object *)(st->tree))->repo, tree_entry);
+ pushed_tree = st->tree;
+ pushed_tree_position = st->tree_position;
+ st->tree = (git_tree *)subtree;
+ st->tree_position = 0;
+ st->head_tree_relative_path_len += 1 + tree_entry->filename_len; /* path + '/' + name */
+ break;
+
+ case GIT_OBJ_BLOB:
+ /* No op */
+ break;
+
+ default:
+ error = git__throw(GIT_EINVALIDTYPE, "Unexpected tree entry type"); /* TODO: How should we deal with submodules? */
}
+
+ if (full_path != NULL && path_type == GIT_STATUS_PATH_FOLDER)
+ error = alphasorted_futils_direach(full_path, GIT_PATH_MAX, dirent_cb, st);
+ else {
+ error = dirent_cb(st, NULL);
+ }
+
+ if (tree_entry_type == GIT_OBJ_TREE) {
+ git_object_close(subtree);
+ st->head_tree_relative_path_len -= 1 + tree_entry->filename_len;
+ st->tree = pushed_tree;
+ st->tree_position = pushed_tree_position;
+ st->tree_position++;
+ }
+
+ return error;
}
-struct status_st {
- union {
- git_vector *vector;
- struct status_entry *e;
- } entry;
+static int store_if_changed(struct status_st *st, struct status_entry *e)
+{
+ int error;
+ if ((error = status_entry_update_flags(e)) < GIT_SUCCESS)
+ return git__throw(error, "Failed to process the file '%s'. It doesn't exist in the workdir, in the HEAD nor in the index", e->path);
- int workdir_path_len;
-};
+ if (e->status_flags == GIT_STATUS_CURRENT) {
+ free(e);
+ return GIT_SUCCESS;
+ }
+
+ return git_vector_insert(st->vector, e);
+}
-static int dirent_cb(void *state, char *full_path)
+static int determine_status(struct status_st *st,
+ int in_head, int in_index, int in_workdir,
+ const git_tree_entry *tree_entry,
+ const git_index_entry *index_entry,
+ char *full_path,
+ const char *status_path,
+ int path_type)
{
- int idx;
struct status_entry *e;
- struct status_st *st = (struct status_st *)state;
- char *file_path = full_path + st->workdir_path_len;
- struct stat filest;
- git_oid oid;
+ int error = GIT_SUCCESS;
+ git_otype tree_entry_type = GIT_OBJ_BAD;
- if ((git_futils_isdir(full_path) == GIT_SUCCESS) && (!strcmp(".git", file_path)))
- return 0;
+ if (tree_entry != NULL)
+ tree_entry_type = git_tree_entry_type(tree_entry);
- if (git_futils_isdir(full_path) == GIT_SUCCESS)
- return git_futils_direach(full_path, GIT_PATH_MAX, dirent_cb, state);
+ /* If we're dealing with a directory in the workdir, let's recursively tackle it first */
+ if (path_type == GIT_STATUS_PATH_FOLDER)
+ return process_folder(st, tree_entry, full_path, path_type);
- if ((idx = find_status_entry(st->entry.vector, file_path)) != GIT_ENOTFOUND) {
- e = (struct status_entry *)git_vector_get(st->entry.vector, idx);
+ /* Are we dealing with a file somewhere? */
+ if (in_workdir || in_index || (in_head && tree_entry_type == GIT_OBJ_BLOB)) {
+ e = status_entry_new(NULL, status_path);
- if (p_stat(full_path, &filest) < 0)
- return git__throw(GIT_EOSERR, "Failed to read file %s", full_path);
+ if (in_head && tree_entry_type == GIT_OBJ_BLOB) {
+ status_entry_update_from_tree_entry(e, tree_entry);
+ st->tree_position++;
+ }
- if (e->mtime.seconds == (git_time_t)filest.st_mtime) {
- git_oid_cpy(&e->wt_oid, &e->index_oid);
- return 0;
+ if (in_index) {
+ status_entry_update_from_index_entry(e, index_entry);
+ st->index_position++;
}
- } else {
- e = new_status_entry(st->entry.vector, file_path);
+
+ if (in_workdir)
+ if ((error = status_entry_update_from_workdir(e, full_path)) < GIT_SUCCESS)
+ return error; /* The callee has already set the error message */
+
+ return store_if_changed(st, e);
}
- git_odb_hashfile(&oid, full_path, GIT_OBJ_BLOB);
- git_oid_cpy(&e->wt_oid, &oid);
+ /* Last option, we're dealing with a leftover folder tree entry */
+ assert(in_head && !in_index && !in_workdir && (tree_entry_type == GIT_OBJ_TREE));
+ return process_folder(st, tree_entry, full_path, path_type);
+}
+
+static int path_type_from(char *full_path, int is_dir)
+{
+ if (full_path == NULL)
+ return GIT_STATUS_PATH_NULL;
+
+ if (!is_dir)
+ return GIT_STATUS_PATH_FILE;
+
+ if (!git__suffixcmp(full_path, "/" DOT_GIT))
+ return GIT_STATUS_PATH_IGNORE;
- return 0;
+ return GIT_STATUS_PATH_FOLDER;
}
-static int single_dirent_cb(void *state, char *full_path)
+static const char *status_path(const char *first, const char *second, const char *third)
{
- struct status_st *st = (struct status_st *)state;
- struct status_entry *e = st->entry.e;
+ /* At least one of them can not be NULL */
+ assert(first != NULL || second != NULL || third != NULL);
- char *file_path = full_path + st->workdir_path_len;
- struct stat filest;
- git_oid oid;
+ /* TODO: Fixme. Ensure that when non null, they're all equal */
+ if (first != NULL)
+ return first;
+
+ if (second != NULL)
+ return second;
+
+ return third;
+}
- if ((git_futils_isdir(full_path) == GIT_SUCCESS) && (!strcmp(".git", file_path)))
+static int compare(const char *left, const char *right)
+{
+ if (left == NULL && right == NULL)
return 0;
- if (git_futils_isdir(full_path) == GIT_SUCCESS)
- return git_futils_direach(full_path, GIT_PATH_MAX, single_dirent_cb, state);
+ if (left == NULL)
+ return 1;
- if (!strcmp(file_path, e->path)) {
- if (p_stat(full_path, &filest) < 0)
- return git__throw(GIT_EOSERR, "Failed to read file %s", full_path);
+ if (right == NULL)
+ return -1;
- if (e->mtime.seconds == (git_time_t)filest.st_mtime) {
- git_oid_cpy(&e->wt_oid, &e->index_oid);
- return 1;
- }
+ return strcmp(left, right);
+}
- git_odb_hashfile(&oid, full_path, GIT_OBJ_BLOB);
- git_oid_cpy(&e->wt_oid, &oid);
- return 1;
- }
+/*
+ * Convenience method to enumerate a tree. Contrarily to the git_tree_entry_byindex()
+ * method, it allows the tree to be enumerated to be NULL. In this case, every returned
+ * tree entry will be NULL as well.
+ */
+static const git_tree_entry *git_tree_entry_bypos(git_tree *tree, unsigned int idx)
+{
+ if (tree == NULL)
+ return NULL;
- return 0;
+ return git_vector_get(&tree->entries, idx);
}
-static int set_status_flags(struct status_entry *e)
+/*
+ * Convenience method to enumerate the index. This method is not supposed to be exposed
+ * as part of the index API because it precludes that the index will not be altered
+ * while the enumeration is being processed. Which wouldn't be very API friendly :)
+ */
+static const git_index_entry *git_index_entry_bypos(git_index *index, unsigned int idx)
{
- git_oid zero;
- int head_zero, index_zero, wt_zero;
+ assert(index);
+ return git_vector_get(&index->entries, idx);
+}
- memset(&zero, 0x0, sizeof(git_oid));
+/* Greatly inspired from JGit IndexTreeWalker */
+/* https://github.com/spearce/jgit/blob/ed47e29c777accfa78c6f50685a5df2b8f5b8ff5/org.spearce.jgit/src/org/spearce/jgit/lib/IndexTreeWalker.java#L88 */
- head_zero = git_oid_cmp(&zero, &e->head_oid);
- index_zero = git_oid_cmp(&zero, &e->index_oid);
- wt_zero = git_oid_cmp(&zero, &e->wt_oid);
+static int dirent_cb(void *state, char *a)
+{
+ const git_tree_entry *m;
+ const git_index_entry *entry;
+ int path_type;
+ int cmpma, cmpmi, cmpai, error;
+ const char *pm, *pa, *pi;
+ const char *m_name, *i_name, *a_name;
- if (head_zero == 0 && index_zero == 0 && wt_zero == 0)
- return GIT_ENOTFOUND;
+ struct status_st *st = (struct status_st *)state;
- if (head_zero == 0 && index_zero != 0)
- e->status_flags |= GIT_STATUS_INDEX_NEW;
- else if (index_zero == 0 && head_zero != 0)
- e->status_flags |= GIT_STATUS_INDEX_DELETED;
- else if (git_oid_cmp(&e->head_oid, &e->index_oid) != 0)
- e->status_flags |= GIT_STATUS_INDEX_MODIFIED;
+ path_type = path_type_from(a, st->is_dir);
- if (index_zero == 0 && wt_zero != 0)
- e->status_flags |= GIT_STATUS_WT_NEW;
- else if (wt_zero == 0 && index_zero != 0)
- e->status_flags |= GIT_STATUS_WT_DELETED;
- else if (git_oid_cmp(&e->index_oid, &e->wt_oid) != 0)
- e->status_flags |= GIT_STATUS_WT_MODIFIED;
+ if (path_type == GIT_STATUS_PATH_IGNORE)
+ return GIT_SUCCESS; /* Let's skip the ".git" directory */
- return GIT_SUCCESS;
+ a_name = (path_type != GIT_STATUS_PATH_NULL) ? a + st->workdir_path_len : NULL;
+
+ while (1) {
+ m = git_tree_entry_bypos(st->tree, st->tree_position);
+ entry = git_index_entry_bypos(st->index, st->index_position);
+
+ if ((m == NULL) && (a == NULL) && (entry == NULL))
+ return GIT_SUCCESS;
+
+ if (m != NULL) {
+ st->head_tree_relative_path[st->head_tree_relative_path_len] = '\0';
+ git_path_join(st->head_tree_relative_path, st->head_tree_relative_path, m->filename);
+ m_name = st->head_tree_relative_path;
+ } else
+ m_name = NULL;
+
+ i_name = (entry != NULL) ? entry->path : NULL;
+
+ cmpma = compare(m_name, a_name);
+ cmpmi = compare(m_name, i_name);
+ cmpai = compare(a_name, i_name);
+
+ pm = ((cmpma <= 0) && (cmpmi <= 0)) ? m_name : NULL;
+ pa = ((cmpma >= 0) && (cmpai <= 0)) ? a_name : NULL;
+ pi = ((cmpmi >= 0) && (cmpai >= 0)) ? i_name : NULL;
+
+ if((error = determine_status(st, pm != NULL, pi != NULL, pa != NULL, m, entry, a, status_path(pm, pi, pa), path_type)) < GIT_SUCCESS)
+ return git__rethrow(error, "An error occured while determining the status of '%s'", a);
+
+ if (pa != NULL)
+ return GIT_SUCCESS;
+ }
+}
+
+static int status_cmp(const void *a, const void *b)
+{
+ const struct status_entry *entry_a = (const struct status_entry *)(a);
+ const struct status_entry *entry_b = (const struct status_entry *)(b);
+
+ return strcmp(entry_a->path, entry_b->path);
}
+#define DEFAULT_SIZE 16
+
int git_status_foreach(git_repository *repo, int (*callback)(const char *, unsigned int, void *), void *payload)
{
git_vector entries;
- struct status_entry *e;
- git_index *index;
- unsigned int i, cnt;
- git_index_entry *index_entry;
+ git_index *index = NULL;
char temp_path[GIT_PATH_MAX];
- int error;
- git_tree *tree;
+ char tree_path[GIT_PATH_MAX] = "";
struct status_st dirent_st;
+ int error = GIT_SUCCESS;
+ unsigned int i;
+ git_tree *tree;
+ struct status_entry *e;
- git_reference *head_ref, *resolved_head_ref;
- git_commit *head_commit;
-
- git_repository_index(&index, repo);
-
- cnt = git_index_entrycount(index);
- git_vector_init(&entries, cnt, status_cmp);
- for (i = 0; i < cnt; ++i) {
- index_entry = git_index_get(index, i);
-
- e = new_status_entry(&entries, index_entry->path);
- git_oid_cpy(&e->index_oid, &index_entry->oid);
- e->mtime = index_entry->mtime;
+ if ((error = git_repository_index(&index, repo)) < GIT_SUCCESS) {
+ return git__rethrow(error, "Failed to determine statuses. Index can't be opened");
}
- git_index_free(index);
-
- git_reference_lookup(&head_ref, repo, GIT_HEAD_FILE);
- git_reference_resolve(&resolved_head_ref, head_ref);
- git_commit_lookup(&head_commit, repo, git_reference_oid(resolved_head_ref));
+ if ((error = retrieve_head_tree(&tree, repo)) < GIT_SUCCESS) {
+ error = git__rethrow(error, "Failed to determine statuses");
+ goto exit;
+ }
- // recurse through tree entries
- git_commit_tree(&tree, head_commit);
- recurse_tree_entries(tree, &entries, "");
- git_tree_close(tree);
- git_commit_close(head_commit);
+ git_vector_init(&entries, DEFAULT_SIZE, status_cmp);
dirent_st.workdir_path_len = strlen(repo->path_workdir);
- dirent_st.entry.vector = &entries;
- strcpy(temp_path, repo->path_workdir);
- git_futils_direach(temp_path, GIT_PATH_MAX, dirent_cb, &dirent_st);
+ dirent_st.tree_position = 0;
+ dirent_st.index_position = 0;
+ dirent_st.tree = tree;
+ dirent_st.index = index;
+ dirent_st.vector = &entries;
+ dirent_st.head_tree_relative_path = tree_path;
+ dirent_st.head_tree_relative_path_len = 0;
+ dirent_st.is_dir = 1;
- for (i = 0; i < entries.length; ++i) {
- e = (struct status_entry *)git_vector_get(&entries, i);
+ strcpy(temp_path, repo->path_workdir);
- set_status_flags(e);
+ if (git_futils_isdir(temp_path)) {
+ error = git__throw(GIT_EINVALIDPATH, "Failed to determine status of file '%s'. Provided path doesn't lead to a folder", temp_path);
+ goto exit;
}
+ if ((error = alphasorted_futils_direach(temp_path, sizeof(temp_path), dirent_cb, &dirent_st)) < GIT_SUCCESS)
+ error = git__rethrow(error, "Failed to determine statuses. An error occured while processing the working directory");
+
+ if ((error == GIT_SUCCESS) && ((error = dirent_cb(&dirent_st, NULL)) < GIT_SUCCESS))
+ error = git__rethrow(error, "Failed to determine statuses. An error occured while post-processing the HEAD tree and the index");
for (i = 0; i < entries.length; ++i) {
e = (struct status_entry *)git_vector_get(&entries, i);
- if ((error = callback(e->path, e->status_flags, payload)) < GIT_SUCCESS)
- return git__throw(error, "Failed to list statuses. User callback failed");
- }
+ if (error == GIT_SUCCESS) {
+ error = callback(e->path, e->status_flags, payload);
+ if (error < GIT_SUCCESS)
+ error = git__rethrow(error, "Failed to determine statuses. User callback failed");
+ }
- for (i = 0; i < entries.length; ++i) {
- e = (struct status_entry *)git_vector_get(&entries, i);
free(e);
}
+
+exit:
git_vector_free(&entries);
+ git_tree_close(tree);
+ git_index_free(index);
+ return error;
+}
- return GIT_SUCCESS;
+static int recurse_tree_entry(git_tree *tree, struct status_entry *e, const char *path)
+{
+ char *dir_sep;
+ const git_tree_entry *tree_entry;
+ git_tree *subtree;
+ int error = GIT_SUCCESS;
+
+ dir_sep = strchr(path, '/');
+ if (!dir_sep) {
+ tree_entry = git_tree_entry_byname(tree, path);
+ if (tree_entry == NULL)
+ return GIT_SUCCESS; /* The leaf doesn't exist in the tree*/
+
+ status_entry_update_from_tree_entry(e, tree_entry);
+ return GIT_SUCCESS;
+ }
+
+ /* Retrieve subtree name */
+ *dir_sep = '\0';
+
+ tree_entry = git_tree_entry_byname(tree, path);
+ if (tree_entry == NULL)
+ return GIT_SUCCESS; /* The subtree doesn't exist in the tree*/
+
+ *dir_sep = '/';
+
+ /* Retreive subtree */
+ if ((error = git_tree_lookup(&subtree, tree->object.repo, &tree_entry->oid)) < GIT_SUCCESS)
+ return git__throw(GIT_EOBJCORRUPTED, "Can't find tree object '%s'", tree_entry->filename);
+
+ error = recurse_tree_entry(subtree, e, dir_sep+1);
+ git_tree_close(subtree);
+ return error;
}
int git_status_file(unsigned int *status_flags, git_repository *repo, const char *path)
{
struct status_entry *e;
- git_index *index;
- git_index_entry *index_entry;
+ git_index *index = NULL;
char temp_path[GIT_PATH_MAX];
- int idx, error;
- git_tree *tree;
- git_reference *head_ref, *resolved_head_ref;
- git_commit *head_commit;
- struct status_st dirent_st;
+ int error = GIT_SUCCESS;
+ git_tree *tree = NULL;
+
+ assert(status_flags && repo && path);
- assert(status_flags);
+ git_path_join(temp_path, repo->path_workdir, path);
+ if (git_futils_isdir(temp_path) == GIT_SUCCESS)
+ return git__throw(GIT_EINVALIDPATH, "Failed to determine status of file '%s'. Provided path leads to a folder, not a file", path);
- e = new_status_entry(NULL, path);
+ e = status_entry_new(NULL, path);
+ if (e == NULL)
+ return GIT_ENOMEM;
- // Find file in Index
- git_repository_index(&index, repo);
- idx = git_index_find(index, path);
- if (idx >= 0) {
- index_entry = git_index_get(index, idx);
- git_oid_cpy(&e->index_oid, &index_entry->oid);
- e->mtime = index_entry->mtime;
+ /* Find file in Workdir */
+ if (git_futils_exists(temp_path) == GIT_SUCCESS) {
+ if ((error = status_entry_update_from_workdir(e, temp_path)) < GIT_SUCCESS)
+ goto exit; /* The callee has already set the error message */
}
- git_index_free(index);
- // Find file in HEAD
- git_reference_lookup(&head_ref, repo, GIT_HEAD_FILE);
- git_reference_resolve(&resolved_head_ref, head_ref);
+ /* Find file in Index */
+ if ((error = git_repository_index(&index, repo)) < GIT_SUCCESS) {
+ error = git__rethrow(error, "Failed to determine status of file '%s'. Index can't be opened", path);
+ goto exit;
+ }
- git_commit_lookup(&head_commit, repo, git_reference_oid(resolved_head_ref));
+ status_entry_update_from_index(e, index);
+ git_index_free(index);
- git_commit_tree(&tree, head_commit);
- recurse_tree_entry(tree, e, path);
- git_tree_close(tree);
- git_commit_close(head_commit);
+ if ((error = retrieve_head_tree(&tree, repo)) < GIT_SUCCESS) {
+ error = git__rethrow(error, "Failed to determine status of file '%s'", path);
+ goto exit;
+ }
- // Find file in Workdir
- dirent_st.workdir_path_len = strlen(repo->path_workdir);
- dirent_st.entry.e = e;
- strcpy(temp_path, repo->path_workdir);
- git_futils_direach(temp_path, GIT_PATH_MAX, single_dirent_cb, &dirent_st);
+ /* If the repository is not empty, try and locate the file in HEAD */
+ if (tree != NULL) {
+ strcpy(temp_path, path);
- if ((error = set_status_flags(e)) < GIT_SUCCESS) {
- free(e);
- return git__throw(error, "Nonexistent file");
+ error = recurse_tree_entry(tree, e, temp_path);
+ if (error < GIT_SUCCESS) {
+ error = git__rethrow(error, "Failed to determine status of file '%s'. An error occured while processing the tree", path);
+ goto exit;
+ }
+ }
+
+ /* Determine status */
+ if ((error = status_entry_update_flags(e)) < GIT_SUCCESS) {
+ error = git__throw(error, "Nonexistent file");
+ goto exit;
}
*status_flags = e->status_flags;
+exit:
+ git_tree_close(tree);
free(e);
+ return error;
+}
+
+/*
+ * git_futils_direach is not supposed to return entries in an ordered manner.
+ * alphasorted_futils_direach wraps git_futils_direach and invokes the callback
+ * function by passing it alphabeticcally sorted paths parameters.
+ *
+ */
+
+struct alphasorted_dirent_info {
+ int is_dir;
+
+ char path[GIT_FLEX_ARRAY]; /* more */
+};
+
+static struct alphasorted_dirent_info *alphasorted_dirent_info_new(const char *path)
+{
+ int is_dir;
+ struct alphasorted_dirent_info *di;
+
+ is_dir = git_futils_isdir(path) == GIT_SUCCESS ? 1 : 0;
+
+ di = git__malloc(sizeof(*di) + (is_dir ? GIT_PATH_MAX : strlen(path)) + 1);
+ if (di == NULL)
+ return NULL;
+
+ memset(di, 0x0, sizeof(*di));
+
+ strcpy(di->path, path);
+ di->is_dir = is_dir;
+
+ return di;
+}
+
+int alphasorted_dirent_info_cmp(const void *a, const void *b)
+{
+ struct alphasorted_dirent_info *stra = (struct alphasorted_dirent_info *)a;
+ struct alphasorted_dirent_info *strb = (struct alphasorted_dirent_info *)b;
+
+ return strcmp(stra->path, strb->path);
+}
+
+static int alphasorted_dirent_cb(void *state, char *full_path)
+{
+ struct alphasorted_dirent_info *entry;
+ git_vector *entry_names;
+
+ entry_names = (git_vector *)state;
+ entry = alphasorted_dirent_info_new(full_path);
+
+ if (entry == NULL)
+ return GIT_ENOMEM;
+
+ if (git_vector_insert(entry_names, entry) < GIT_SUCCESS) {
+ free(entry);
+ return GIT_ENOMEM;
+ }
return GIT_SUCCESS;
}
+
+static int alphasorted_futils_direach(
+ char *path,
+ size_t path_sz,
+ int (*fn)(void *, char *),
+ void *arg)
+{
+ struct alphasorted_dirent_info *entry;
+ git_vector entry_names;
+ unsigned int idx;
+ int error = GIT_SUCCESS;
+
+ if (git_vector_init(&entry_names, 16, alphasorted_dirent_info_cmp) < GIT_SUCCESS)
+ return GIT_ENOMEM;
+
+ error = git_futils_direach(path, path_sz, alphasorted_dirent_cb, &entry_names);
+
+ git_vector_sort(&entry_names);
+
+ for (idx = 0; idx < entry_names.length; ++idx) {
+ entry = (struct alphasorted_dirent_info *)git_vector_get(&entry_names, idx);
+
+ if (error == GIT_SUCCESS) {
+ ((struct status_st *)arg)->is_dir = entry->is_dir;
+ error = fn(arg, entry->path);
+ }
+
+ free(entry);
+ }
+
+ git_vector_free(&entry_names);
+ return error;
+}
diff --git a/src/tag.c b/src/tag.c
index 21bc3c726..fc9f8b5e4 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "common.h"
@@ -245,7 +227,7 @@ static int git_tag_create__internal(
}
/** Ensure the tag name doesn't conflict with an already existing
- * reference unless overwriting has explictly been requested **/
+ * reference unless overwriting has explictly been requested **/
if (new_ref != NULL) {
if (!allow_ref_overwrite) {
git_oid_cpy(oid, git_reference_oid(new_ref));
@@ -330,7 +312,7 @@ int git_tag_create_frombuffer(git_oid *oid, git_repository *repo, const char *bu
}
/** Ensure the tag name doesn't conflict with an already existing
- * reference unless overwriting has explictly been requested **/
+ * reference unless overwriting has explictly been requested **/
if (new_ref != NULL) {
if (!allow_ref_overwrite) {
git_oid_cpy(oid, git_reference_oid(new_ref));
@@ -384,8 +366,8 @@ int git_tag__parse(git_tag *tag, git_odb_object *obj)
}
typedef struct {
- git_vector *taglist;
- const char *pattern;
+ git_vector *taglist;
+ const char *pattern;
} tag_filter_data;
#define GIT_REFS_TAGS_DIR_LEN strlen(GIT_REFS_TAGS_DIR)
diff --git a/src/tag.h b/src/tag.h
index eddf8fa3a..a537b1ee8 100644
--- a/src/tag.h
+++ b/src/tag.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_tag_h__
#define INCLUDE_tag_h__
diff --git a/src/thread-utils.c b/src/thread-utils.c
index 5e8220f46..f582f4311 100644
--- a/src/thread-utils.c
+++ b/src/thread-utils.c
@@ -1,11 +1,17 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#include "common.h"
#include "thread-utils.h"
#ifdef _WIN32
-# define WIN32_LEAN_AND_MEAN
-# include <windows.h>
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
#elif defined(hpux) || defined(__hpux) || defined(_hpux)
-# include <sys/pstat.h>
+# include <sys/pstat.h>
#endif
/*
@@ -14,11 +20,11 @@
* with this disgusting nest of #ifdefs.
*/
#ifndef _SC_NPROCESSORS_ONLN
-# ifdef _SC_NPROC_ONLN
-# define _SC_NPROCESSORS_ONLN _SC_NPROC_ONLN
-# elif defined _SC_CRAY_NCPU
-# define _SC_NPROCESSORS_ONLN _SC_CRAY_NCPU
-# endif
+# ifdef _SC_NPROC_ONLN
+# define _SC_NPROCESSORS_ONLN _SC_NPROC_ONLN
+# elif defined _SC_CRAY_NCPU
+# define _SC_NPROCESSORS_ONLN _SC_CRAY_NCPU
+# endif
#endif
int git_online_cpus(void)
diff --git a/src/thread-utils.h b/src/thread-utils.h
index 20d6022ea..3361ed8bc 100644
--- a/src/thread-utils.h
+++ b/src/thread-utils.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_thread_utils_h__
#define INCLUDE_thread_utils_h__
@@ -27,10 +33,10 @@ GIT_INLINE(void) git_atomic_set(git_atomic *a, int val)
/* Pthreads Mutex */
#define git_mutex pthread_mutex_t
-#define git_mutex_init(a) pthread_mutex_init(a, NULL)
-#define git_mutex_lock(a) pthread_mutex_lock(a)
+#define git_mutex_init(a) pthread_mutex_init(a, NULL)
+#define git_mutex_lock(a) pthread_mutex_lock(a)
#define git_mutex_unlock(a) pthread_mutex_unlock(a)
-#define git_mutex_free(a) pthread_mutex_destroy(a)
+#define git_mutex_free(a) pthread_mutex_destroy(a)
/* Pthreads condition vars -- disabled by now */
#define git_cond unsigned int //pthread_cond_t
diff --git a/src/transport.c b/src/transport.c
index 91f621c46..6be8f4058 100644
--- a/src/transport.c
+++ b/src/transport.c
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#include "common.h"
#include "git2/types.h"
#include "git2/transport.h"
diff --git a/src/transport.h b/src/transport.h
index 9489ac803..233cfb1db 100644
--- a/src/transport.h
+++ b/src/transport.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_transport_h__
#define INCLUDE_transport_h__
@@ -9,7 +15,7 @@
typedef struct git_transport_caps {
int common:1,
- ofs_delta:1;
+ ofs_delta:1;
} git_transport_caps;
/*
diff --git a/src/transport_git.c b/src/transport_git.c
index 7b0edcfef..ac268cd43 100644
--- a/src/transport_git.c
+++ b/src/transport_git.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "git2/net.h"
@@ -405,8 +387,8 @@ static int git_negotiate_fetch(git_transport *transport, git_repository *repo, g
error = gitno_recv(&buf);
if (error < GIT_SUCCESS) {
- error = git__rethrow(error, "Error receiving data");
- goto cleanup;
+ error = git__rethrow(error, "Error receiving data");
+ goto cleanup;
}
error = git_pkt_parse_line(&pkt, ptr, &line_end, buf.offset);
if (error == GIT_ESHORTBUFFER)
@@ -553,7 +535,7 @@ static int git_close(git_transport *transport)
int s = t->socket;
int error;
- /* Can't do anything if there's an error, so don't bother checking */
+ /* Can't do anything if there's an error, so don't bother checking */
git_pkt_send_flush(s);
error = close(s);
if (error < 0)
diff --git a/src/transport_local.c b/src/transport_local.c
index ab0922cf2..4975af9ad 100644
--- a/src/transport_local.c
+++ b/src/transport_local.c
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#include "common.h"
#include "git2/types.h"
#include "git2/transport.h"
diff --git a/src/tree.c b/src/tree.c
index e0225f90b..ce399a66a 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "common.h"
@@ -222,89 +204,101 @@ int git_tree__parse(git_tree *tree, git_odb_object *obj)
return tree_parse_buffer(tree, (char *)obj->raw.data, (char *)obj->raw.data + obj->raw.len);
}
-static int write_index_entry(char *buffer, int mode, const char *path, size_t path_len, const git_oid *oid)
+static int write_tree(git_oid *oid, git_index *index, const char *dirname, unsigned int start)
{
- int written;
- written = sprintf(buffer, "%o %.*s%c", mode, (int)path_len, path, 0);
- memcpy(buffer + written, &oid->id, GIT_OID_RAWSZ);
- return written + GIT_OID_RAWSZ;
-}
+ git_treebuilder *bld = NULL;
+ unsigned int i, entries = git_index_entrycount(index);
+ int error;
+ size_t dirname_len = strlen(dirname);
-static int write_index(git_oid *oid, git_index *index, const char *base, int baselen, int entry_no, int maxentries)
-{
- size_t size, offset;
- char *buffer;
- int nr, error;
-
- /* Guess at some random initial size */
- size = maxentries * 40;
- buffer = git__malloc(size);
- if (buffer == NULL)
+ error = git_treebuilder_create(&bld, NULL);
+ if (bld == NULL) {
return GIT_ENOMEM;
+ }
- offset = 0;
-
- for (nr = entry_no; nr < maxentries; ++nr) {
- git_index_entry *entry = git_index_get(index, nr);
-
- const char *pathname = entry->path, *filename, *dirname;
- int pathlen = strlen(pathname), entrylen;
-
- unsigned int write_mode;
- git_oid subtree_oid;
- git_oid *write_oid;
-
- /* Did we hit the end of the directory? Return how many we wrote */
- if (baselen >= pathlen || memcmp(base, pathname, baselen) != 0)
+ /*
+ * This loop is unfortunate, but necessary. The index doesn't have
+ * any directores, so we need to handle that manually, and we
+ * need to keep track of the current position.
+ */
+ for (i = start; i < entries; ++i) {
+ git_index_entry *entry = git_index_get(index, i);
+ char *filename, *next_slash;
+
+ /*
+ * If we've left our (sub)tree, exit the loop and return. The
+ * first check is an early out (and security for the
+ * third). The second check is a simple prefix comparison. The
+ * third check catches situations where there is a directory
+ * win32/sys and a file win32mmap.c. Without it, the following
+ * code believes there is a file win32/mmap.c
+ */
+ if (strlen(entry->path) < dirname_len ||
+ memcmp(entry->path, dirname, dirname_len) ||
+ (dirname_len > 0 && entry->path[dirname_len] != '/')) {
break;
+ }
- /* Do we have _further_ subdirectories? */
- filename = pathname + baselen;
- dirname = strchr(filename, '/');
-
- write_oid = &entry->oid;
- write_mode = entry->mode;
-
- if (dirname) {
- int subdir_written;
-
-#if 0
- if (entry->mode != S_IFDIR) {
- free(buffer);
- return GIT_EOBJCORRUPTED;
+ filename = entry->path + dirname_len;
+ if (*filename == '/')
+ filename++;
+ next_slash = strchr(filename, '/');
+ if (next_slash) {
+ git_oid sub_oid;
+ int written;
+ char *subdir, *last_comp;
+
+ subdir = git__strndup(entry->path, next_slash - entry->path);
+ if (subdir == NULL) {
+ error = GIT_ENOMEM;
+ goto cleanup;
}
-#endif
- subdir_written = write_index(&subtree_oid, index, pathname, dirname - pathname + 1, nr, maxentries);
- if (subdir_written < GIT_SUCCESS) {
- free(buffer);
- return subdir_written;
+ /* Write out the subtree */
+ written = write_tree(&sub_oid, index, subdir, i);
+ if (written < 0) {
+ error = git__rethrow(written, "Failed to write subtree %s", subdir);
+ } else {
+ i = written - 1; /* -1 because of the loop increment */
}
- nr = subdir_written - 1;
-
- /* Now we need to write out the directory entry into this tree.. */
- pathlen = dirname - pathname;
- write_oid = &subtree_oid;
- write_mode = S_IFDIR;
- }
-
- entrylen = pathlen - baselen;
- if (offset + entrylen + 32 > size) {
- size = alloc_nr(offset + entrylen + 32);
- buffer = git__realloc(buffer, size);
-
- if (buffer == NULL)
- return GIT_ENOMEM;
+ /*
+ * We need to figure out what we want toinsert
+ * into this tree. If we're traversing
+ * deps/zlib/, then we only want to write
+ * 'zlib' into the tree.
+ */
+ last_comp = strrchr(subdir, '/');
+ if (last_comp) {
+ last_comp++; /* Get rid of the '/' */
+ } else {
+ last_comp = subdir;
+ }
+ error = git_treebuilder_insert(NULL, bld, last_comp, &sub_oid, S_IFDIR);
+ free(subdir);
+ if (error < GIT_SUCCESS) {
+ error = git__rethrow(error, "Failed to insert dir");
+ goto cleanup;
+ }
+ } else {
+ error = git_treebuilder_insert(NULL, bld, filename, &entry->oid, entry->mode);
+ if (error < GIT_SUCCESS) {
+ error = git__rethrow(error, "Failed to insert file");
+ }
}
-
- offset += write_index_entry(buffer + offset, write_mode, filename, entrylen, write_oid);
}
- error = git_odb_write(oid, index->repository->db, buffer, offset, GIT_OBJ_TREE);
- free(buffer);
+ error = git_treebuilder_write(oid, index->repository, bld);
+ if (error < GIT_SUCCESS)
+ error = git__rethrow(error, "Failed to write tree to db");
+
+ cleanup:
+ git_treebuilder_free(bld);
- return (error == GIT_SUCCESS) ? nr : git__rethrow(error, "Failed to write index");
+ if (error < GIT_SUCCESS)
+ return error;
+ else
+ return i;
}
int git_tree_create_fromindex(git_oid *oid, git_index *index)
@@ -314,7 +308,8 @@ int git_tree_create_fromindex(git_oid *oid, git_index *index)
if (index->repository == NULL)
return git__throw(GIT_EBAREINDEX, "Failed to create tree. The index file is not backed up by an existing repository");
- error = write_index(oid, index, "", 0, 0, git_index_entrycount(index));
+ /* The tree cache didn't help us */
+ error = write_tree(oid, index, "", 0);
return (error < GIT_SUCCESS) ? git__rethrow(error, "Failed to create tree") : GIT_SUCCESS;
}
diff --git a/src/tree.h b/src/tree.h
index bff3f8edb..4f8c07f08 100644
--- a/src/tree.h
+++ b/src/tree.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_tree_h__
#define INCLUDE_tree_h__
diff --git a/src/tsort.c b/src/tsort.c
index 14b15c232..5dd99cc6e 100644
--- a/src/tsort.c
+++ b/src/tsort.c
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#include "common.h"
@@ -62,7 +68,7 @@ static int binsearch(void **dst, const void *x, size_t size, cmp_ptr_t cmp)
}
}
-/* Binary insertion sort, but knowing that the first "start" entries are sorted. Used in timsort. */
+/* Binary insertion sort, but knowing that the first "start" entries are sorted. Used in timsort. */
static void bisort(void **dst, size_t start, size_t size, cmp_ptr_t cmp)
{
size_t i;
@@ -201,7 +207,7 @@ static void merge(void **dst, const struct tsort_run *stack, int stack_curr, str
if (resize(store, MIN(A, B)) < 0)
return;
- storage = store->storage;
+ storage = store->storage;
/* left merge */
if (A < B) {
diff --git a/src/unix/map.c b/src/unix/map.c
index 5192c8e4c..2fb4be571 100644
--- a/src/unix/map.c
+++ b/src/unix/map.c
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#include <git2/common.h>
#ifndef GIT_WIN32
diff --git a/src/unix/posix.h b/src/unix/posix.h
index a49a5cfe7..5c74f0779 100644
--- a/src/unix/posix.h
+++ b/src/unix/posix.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_posix__w32_h__
#define INCLUDE_posix__w32_h__
diff --git a/src/util.c b/src/util.c
index 29bf755f8..b46a2a15c 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#include <git2.h>
#include "common.h"
#include <stdarg.h>
@@ -118,9 +124,9 @@ Return:
return GIT_SUCCESS;
}
-void git__strntolower(char *str, int len)
+void git__strntolower(char *str, size_t len)
{
- int i;
+ size_t i;
for (i = 0; i < len; ++i) {
str[i] = (char) tolower(str[i]);
@@ -208,7 +214,7 @@ void git__hexdump(const char *buffer, size_t len)
printf("%02X ", (unsigned char)*line & 0xFF);
for (j = 0; j < (LINE_WIDTH - last_line); ++j)
- printf(" ");
+ printf(" ");
printf("| ");
@@ -249,7 +255,7 @@ uint32_t git__hash(const void *key, int len, unsigned int seed)
case 3: h ^= data[2] << 16;
case 2: h ^= data[1] << 8;
case 1: h ^= data[0];
- h *= m;
+ h *= m;
};
h ^= h >> 13;
@@ -270,13 +276,13 @@ uint32_t git__hash(const void *key, int len, uint32_t seed)
{
#define MURMUR_BLOCK() {\
- k1 *= c1; \
- k1 = git__rotl(k1,11);\
- k1 *= c2;\
- h1 ^= k1;\
- h1 = h1*3 + 0x52dce729;\
- c1 = c1*5 + 0x7b7d159c;\
- c2 = c2*5 + 0x6bce6396;\
+ k1 *= c1; \
+ k1 = git__rotl(k1,11);\
+ k1 *= c2;\
+ h1 ^= k1;\
+ h1 = h1*3 + 0x52dce729;\
+ c1 = c1*5 + 0x7b7d159c;\
+ c2 = c2*5 + 0x6bce6396;\
}
const uint8_t *data = (const uint8_t*)key;
@@ -326,20 +332,20 @@ uint32_t git__hash(const void *key, int len, uint32_t seed)
*/
void **git__bsearch(const void *key, void **base, size_t nmemb, int (*compar)(const void *, const void *))
{
- int lim, cmp;
- void **p;
-
- for (lim = nmemb; lim != 0; lim >>= 1) {
- p = base + (lim >> 1);
- cmp = (*compar)(key, *p);
- if (cmp > 0) { /* key > p: move right */
- base = p + 1;
- lim--;
- } else if (cmp == 0) {
- return (void **)p;
- } /* else move left */
- }
- return NULL;
+ int lim, cmp;
+ void **p;
+
+ for (lim = nmemb; lim != 0; lim >>= 1) {
+ p = base + (lim >> 1);
+ cmp = (*compar)(key, *p);
+ if (cmp > 0) { /* key > p: move right */
+ base = p + 1;
+ lim--;
+ } else if (cmp == 0) {
+ return (void **)p;
+ } /* else move left */
+ }
+ return NULL;
}
/**
diff --git a/src/util.h b/src/util.h
index 78f9f8276..f24afb3ad 100644
--- a/src/util.h
+++ b/src/util.h
@@ -1,8 +1,14 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_util_h__
#define INCLUDE_util_h__
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
-#define bitsizeof(x) (CHAR_BIT * sizeof(x))
+#define bitsizeof(x) (CHAR_BIT * sizeof(x))
#define MSB(x, bits) ((x) & (~0ULL << (bitsizeof(x) - (bits))))
#ifndef min
# define min(a,b) ((a) < (b) ? (a) : (b))
@@ -90,7 +96,7 @@ GIT_INLINE(int) git__is_sizet(git_off_t p)
extern char *git__strtok(char **end, const char *sep);
-extern void git__strntolower(char *str, int len);
+extern void git__strntolower(char *str, size_t len);
extern void git__strtolower(char *str);
extern int git__fnmatch(const char *pattern, const char *name, int flags);
diff --git a/src/vector.c b/src/vector.c
index 0b83b8b0d..8b20bb8ef 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -1,26 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "common.h"
diff --git a/src/vector.h b/src/vector.h
index c43a7ce07..08f5a501c 100644
--- a/src/vector.h
+++ b/src/vector.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_vector_h__
#define INCLUDE_vector_h__
diff --git a/src/win32/dir.c b/src/win32/dir.c
index 069a41c3a..01339577b 100644
--- a/src/win32/dir.c
+++ b/src/win32/dir.c
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#define GIT__WIN32_NO_WRAP_DIR
#include "dir.h"
diff --git a/src/win32/fnmatch.c b/src/win32/fnmatch.c
index de2f3e74f..7d7c77d48 100644
--- a/src/win32/fnmatch.c
+++ b/src/win32/fnmatch.c
@@ -1,33 +1,8 @@
/*
- * Copyright (c) 1989, 1993, 1994
- * The Regents of the University of California. All rights reserved.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * This code is derived from software contributed to Berkeley by
- * Guido van Rossum.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
/*
@@ -41,165 +16,165 @@
#include "fnmatch.h"
-#define EOS '\0'
+#define EOS '\0'
-#define RANGE_MATCH 1
-#define RANGE_NOMATCH 0
-#define RANGE_ERROR (-1)
+#define RANGE_MATCH 1
+#define RANGE_NOMATCH 0
+#define RANGE_ERROR (-1)
static int rangematch(const char *, char, int, char **);
int
p_fnmatch(const char *pattern, const char *string, int flags)
{
- const char *stringstart;
- char *newp;
- char c, test;
-
- for (stringstart = string;;)
- switch (c = *pattern++) {
- case EOS:
- if ((flags & FNM_LEADING_DIR) && *string == '/')
- return (0);
- return (*string == EOS ? 0 : FNM_NOMATCH);
- case '?':
- if (*string == EOS)
- return (FNM_NOMATCH);
- if (*string == '/' && (flags & FNM_PATHNAME))
- return (FNM_NOMATCH);
- if (*string == '.' && (flags & FNM_PERIOD) &&
- (string == stringstart ||
- ((flags & FNM_PATHNAME) && *(string - 1) == '/')))
- return (FNM_NOMATCH);
- ++string;
- break;
- case '*':
- c = *pattern;
- /* Collapse multiple stars. */
- while (c == '*')
- c = *++pattern;
-
- if (*string == '.' && (flags & FNM_PERIOD) &&
- (string == stringstart ||
- ((flags & FNM_PATHNAME) && *(string - 1) == '/')))
- return (FNM_NOMATCH);
-
- /* Optimize for pattern with * at end or before /. */
- if (c == EOS) {
- if (flags & FNM_PATHNAME)
- return ((flags & FNM_LEADING_DIR) ||
- strchr(string, '/') == NULL ?
- 0 : FNM_NOMATCH);
- else
- return (0);
- } else if (c == '/' && (flags & FNM_PATHNAME)) {
- if ((string = strchr(string, '/')) == NULL)
- return (FNM_NOMATCH);
- break;
- }
-
- /* General case, use recursion. */
- while ((test = *string) != EOS) {
- if (!p_fnmatch(pattern, string, flags & ~FNM_PERIOD))
- return (0);
- if (test == '/' && (flags & FNM_PATHNAME))
- break;
- ++string;
- }
- return (FNM_NOMATCH);
- case '[':
- if (*string == EOS)
- return (FNM_NOMATCH);
- if (*string == '/' && (flags & FNM_PATHNAME))
- return (FNM_NOMATCH);
- if (*string == '.' && (flags & FNM_PERIOD) &&
- (string == stringstart ||
- ((flags & FNM_PATHNAME) && *(string - 1) == '/')))
- return (FNM_NOMATCH);
-
- switch (rangematch(pattern, *string, flags, &newp)) {
- case RANGE_ERROR:
- /* not a good range, treat as normal text */
- goto normal;
- case RANGE_MATCH:
- pattern = newp;
- break;
- case RANGE_NOMATCH:
- return (FNM_NOMATCH);
- }
- ++string;
- break;
- case '\\':
- if (!(flags & FNM_NOESCAPE)) {
- if ((c = *pattern++) == EOS) {
- c = '\\';
- --pattern;
- }
- }
- /* FALLTHROUGH */
- default:
- normal:
- if (c != *string && !((flags & FNM_CASEFOLD) &&
- (tolower((unsigned char)c) ==
- tolower((unsigned char)*string))))
- return (FNM_NOMATCH);
- ++string;
- break;
- }
- /* NOTREACHED */
+ const char *stringstart;
+ char *newp;
+ char c, test;
+
+ for (stringstart = string;;)
+ switch (c = *pattern++) {
+ case EOS:
+ if ((flags & FNM_LEADING_DIR) && *string == '/')
+ return (0);
+ return (*string == EOS ? 0 : FNM_NOMATCH);
+ case '?':
+ if (*string == EOS)
+ return (FNM_NOMATCH);
+ if (*string == '/' && (flags & FNM_PATHNAME))
+ return (FNM_NOMATCH);
+ if (*string == '.' && (flags & FNM_PERIOD) &&
+ (string == stringstart ||
+ ((flags & FNM_PATHNAME) && *(string - 1) == '/')))
+ return (FNM_NOMATCH);
+ ++string;
+ break;
+ case '*':
+ c = *pattern;
+ /* Collapse multiple stars. */
+ while (c == '*')
+ c = *++pattern;
+
+ if (*string == '.' && (flags & FNM_PERIOD) &&
+ (string == stringstart ||
+ ((flags & FNM_PATHNAME) && *(string - 1) == '/')))
+ return (FNM_NOMATCH);
+
+ /* Optimize for pattern with * at end or before /. */
+ if (c == EOS) {
+ if (flags & FNM_PATHNAME)
+ return ((flags & FNM_LEADING_DIR) ||
+ strchr(string, '/') == NULL ?
+ 0 : FNM_NOMATCH);
+ else
+ return (0);
+ } else if (c == '/' && (flags & FNM_PATHNAME)) {
+ if ((string = strchr(string, '/')) == NULL)
+ return (FNM_NOMATCH);
+ break;
+ }
+
+ /* General case, use recursion. */
+ while ((test = *string) != EOS) {
+ if (!p_fnmatch(pattern, string, flags & ~FNM_PERIOD))
+ return (0);
+ if (test == '/' && (flags & FNM_PATHNAME))
+ break;
+ ++string;
+ }
+ return (FNM_NOMATCH);
+ case '[':
+ if (*string == EOS)
+ return (FNM_NOMATCH);
+ if (*string == '/' && (flags & FNM_PATHNAME))
+ return (FNM_NOMATCH);
+ if (*string == '.' && (flags & FNM_PERIOD) &&
+ (string == stringstart ||
+ ((flags & FNM_PATHNAME) && *(string - 1) == '/')))
+ return (FNM_NOMATCH);
+
+ switch (rangematch(pattern, *string, flags, &newp)) {
+ case RANGE_ERROR:
+ /* not a good range, treat as normal text */
+ goto normal;
+ case RANGE_MATCH:
+ pattern = newp;
+ break;
+ case RANGE_NOMATCH:
+ return (FNM_NOMATCH);
+ }
+ ++string;
+ break;
+ case '\\':
+ if (!(flags & FNM_NOESCAPE)) {
+ if ((c = *pattern++) == EOS) {
+ c = '\\';
+ --pattern;
+ }
+ }
+ /* FALLTHROUGH */
+ default:
+ normal:
+ if (c != *string && !((flags & FNM_CASEFOLD) &&
+ (tolower((unsigned char)c) ==
+ tolower((unsigned char)*string))))
+ return (FNM_NOMATCH);
+ ++string;
+ break;
+ }
+ /* NOTREACHED */
}
static int
rangematch(const char *pattern, char test, int flags, char **newp)
{
- int negate, ok;
- char c, c2;
-
- /*
- * A bracket expression starting with an unquoted circumflex
- * character produces unspecified results (IEEE 1003.2-1992,
- * 3.13.2). This implementation treats it like '!', for
- * consistency with the regular expression syntax.
- * J.T. Conklin (conklin@ngai.kaleida.com)
- */
- if ((negate = (*pattern == '!' || *pattern == '^')) != 0)
- ++pattern;
-
- if (flags & FNM_CASEFOLD)
- test = (char)tolower((unsigned char)test);
-
- /*
- * A right bracket shall lose its special meaning and represent
- * itself in a bracket expression if it occurs first in the list.
- * -- POSIX.2 2.8.3.2
- */
- ok = 0;
- c = *pattern++;
- do {
- if (c == '\\' && !(flags & FNM_NOESCAPE))
- c = *pattern++;
- if (c == EOS)
- return (RANGE_ERROR);
- if (c == '/' && (flags & FNM_PATHNAME))
- return (RANGE_NOMATCH);
- if ((flags & FNM_CASEFOLD))
- c = (char)tolower((unsigned char)c);
- if (*pattern == '-'
- && (c2 = *(pattern+1)) != EOS && c2 != ']') {
- pattern += 2;
- if (c2 == '\\' && !(flags & FNM_NOESCAPE))
- c2 = *pattern++;
- if (c2 == EOS)
- return (RANGE_ERROR);
- if (flags & FNM_CASEFOLD)
- c2 = (char)tolower((unsigned char)c2);
- if (c <= test && test <= c2)
- ok = 1;
- } else if (c == test)
- ok = 1;
- } while ((c = *pattern++) != ']');
-
- *newp = (char *)pattern;
- return (ok == negate ? RANGE_NOMATCH : RANGE_MATCH);
+ int negate, ok;
+ char c, c2;
+
+ /*
+ * A bracket expression starting with an unquoted circumflex
+ * character produces unspecified results (IEEE 1003.2-1992,
+ * 3.13.2). This implementation treats it like '!', for
+ * consistency with the regular expression syntax.
+ * J.T. Conklin (conklin@ngai.kaleida.com)
+ */
+ if ((negate = (*pattern == '!' || *pattern == '^')) != 0)
+ ++pattern;
+
+ if (flags & FNM_CASEFOLD)
+ test = (char)tolower((unsigned char)test);
+
+ /*
+ * A right bracket shall lose its special meaning and represent
+ * itself in a bracket expression if it occurs first in the list.
+ * -- POSIX.2 2.8.3.2
+ */
+ ok = 0;
+ c = *pattern++;
+ do {
+ if (c == '\\' && !(flags & FNM_NOESCAPE))
+ c = *pattern++;
+ if (c == EOS)
+ return (RANGE_ERROR);
+ if (c == '/' && (flags & FNM_PATHNAME))
+ return (RANGE_NOMATCH);
+ if ((flags & FNM_CASEFOLD))
+ c = (char)tolower((unsigned char)c);
+ if (*pattern == '-'
+ && (c2 = *(pattern+1)) != EOS && c2 != ']') {
+ pattern += 2;
+ if (c2 == '\\' && !(flags & FNM_NOESCAPE))
+ c2 = *pattern++;
+ if (c2 == EOS)
+ return (RANGE_ERROR);
+ if (flags & FNM_CASEFOLD)
+ c2 = (char)tolower((unsigned char)c2);
+ if (c <= test && test <= c2)
+ ok = 1;
+ } else if (c == test)
+ ok = 1;
+ } while ((c = *pattern++) != ']');
+
+ *newp = (char *)pattern;
+ return (ok == negate ? RANGE_NOMATCH : RANGE_MATCH);
}
diff --git a/src/win32/fnmatch.h b/src/win32/fnmatch.h
index 1309c6e9a..1caac37fe 100644
--- a/src/win32/fnmatch.h
+++ b/src/win32/fnmatch.h
@@ -1,46 +1,25 @@
/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_fnmatch__w32_h__
#define INCLUDE_fnmatch__w32_h__
#include "common.h"
-#define FNM_NOMATCH 1 /* Match failed. */
-#define FNM_NOSYS 2 /* Function not supported (unused). */
+#define FNM_NOMATCH 1 /* Match failed. */
+#define FNM_NOSYS 2 /* Function not supported (unused). */
-#define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */
-#define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */
-#define FNM_PERIOD 0x04 /* Period must be matched by period. */
-#define FNM_LEADING_DIR 0x08 /* Ignore /<tail> after Imatch. */
-#define FNM_CASEFOLD 0x10 /* Case insensitive search. */
+#define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */
+#define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */
+#define FNM_PERIOD 0x04 /* Period must be matched by period. */
+#define FNM_LEADING_DIR 0x08 /* Ignore /<tail> after Imatch. */
+#define FNM_CASEFOLD 0x10 /* Case insensitive search. */
-#define FNM_IGNORECASE FNM_CASEFOLD
-#define FNM_FILE_NAME FNM_PATHNAME
+#define FNM_IGNORECASE FNM_CASEFOLD
+#define FNM_FILE_NAME FNM_PATHNAME
extern int p_fnmatch(const char *pattern, const char *string, int flags);
diff --git a/src/win32/map.c b/src/win32/map.c
index 76b926490..3e6b3d878 100644
--- a/src/win32/map.c
+++ b/src/win32/map.c
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#include "map.h"
#include <errno.h>
@@ -23,7 +29,7 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs
DWORD fmap_prot = 0;
DWORD view_prot = 0;
DWORD off_low = 0;
- DWORD off_hi = 0;
+ DWORD off_hi = 0;
git_off_t page_start;
git_off_t page_offset;
@@ -65,7 +71,7 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs
page_start = (offset / page_size) * page_size;
page_offset = offset - page_start;
- if (page_offset != 0) { /* offset must be multiple of page size */
+ if (page_offset != 0) { /* offset must be multiple of page size */
errno = EINVAL;
return git__throw(GIT_ERROR, "Failed to mmap. Offset must be multiple of page size");
}
diff --git a/src/win32/mingw-compat.h b/src/win32/mingw-compat.h
index 64d780b16..7207d882f 100644
--- a/src/win32/mingw-compat.h
+++ b/src/win32/mingw-compat.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_mingw_compat__
#define INCLUDE_mingw_compat__
@@ -11,7 +17,7 @@
/* stat: file mode type testing macros */
# define _S_IFLNK 0120000
# define S_IFLNK _S_IFLNK
-# define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK)
+# define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK)
#endif
diff --git a/src/win32/msvc-compat.h b/src/win32/msvc-compat.h
index df3e62d11..64ed18476 100644
--- a/src/win32/msvc-compat.h
+++ b/src/win32/msvc-compat.h
@@ -1,12 +1,18 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_msvc_compat__
#define INCLUDE_msvc_compat__
#if defined(_MSC_VER)
-/* access() mode parameter #defines */
-# define F_OK 0 /* existence check */
-# define W_OK 2 /* write mode check */
-# define R_OK 4 /* read mode check */
+/* access() mode parameter #defines */
+# define F_OK 0 /* existence check */
+# define W_OK 2 /* write mode check */
+# define R_OK 4 /* read mode check */
# define lseek _lseeki64
# define stat _stat64
@@ -16,16 +22,16 @@
# define _S_IFLNK 0120000
# define S_IFLNK _S_IFLNK
-# define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
-# define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
-# define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO)
-# define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK)
+# define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
+# define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
+# define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO)
+# define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK)
# define mode_t unsigned short
/* case-insensitive string comparison */
-# define strcasecmp _stricmp
-# define strncasecmp _strnicmp
+# define strcasecmp _stricmp
+# define strncasecmp _strnicmp
#if (_MSC_VER >= 1600)
# include <stdint.h>
diff --git a/src/win32/posix.c b/src/win32/posix.c
index 2d7b8390d..38e505e20 100644
--- a/src/win32/posix.c
+++ b/src/win32/posix.c
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#include "posix.h"
#include "path.h"
#include <errno.h>
@@ -138,13 +144,13 @@ int p_readlink(const char *link, char *target, size_t target_len)
"'GetFinalPathNameByHandleA' is not available in this platform");
}
- hFile = CreateFile(link, // file to open
- GENERIC_READ, // open for reading
- FILE_SHARE_READ, // share for reading
- NULL, // default security
- OPEN_EXISTING, // existing file only
+ hFile = CreateFile(link, // file to open
+ GENERIC_READ, // open for reading
+ FILE_SHARE_READ, // share for reading
+ NULL, // default security
+ OPEN_EXISTING, // existing file only
FILE_FLAG_BACKUP_SEMANTICS, // normal file
- NULL); // no attr. template
+ NULL); // no attr. template
if (hFile == INVALID_HANDLE_VALUE)
return GIT_EOSERR;
@@ -157,7 +163,7 @@ int p_readlink(const char *link, char *target, size_t target_len)
if (dwRet > 4) {
/* Skip first 4 characters if they are "\\?\" */
- if (target[0] == '\\' && target[1] == '\\' && target[2] == '?' && target[3] == '\\') {
+ if (target[0] == '\\' && target[1] == '\\' && target[2] == '?' && target[3] == '\\') {
char tmp[GIT_PATH_MAX];
unsigned int offset = 4;
dwRet -= 4;
@@ -183,7 +189,7 @@ int p_hide_directory__w32(const char *path)
int error;
error = SetFileAttributes(path, FILE_ATTRIBUTE_HIDDEN) != 0 ?
- GIT_SUCCESS : GIT_ERROR; /* MSDN states a "non zero" value indicates a success */
+ GIT_SUCCESS : GIT_ERROR; /* MSDN states a "non zero" value indicates a success */
if (error < GIT_SUCCESS)
error = git__throw(GIT_EOSERR, "Failed to hide directory '%s'", path);
@@ -236,16 +242,13 @@ extern int p_creat(const char *path, int mode);
int p_mkstemp(char *tmp_path)
{
- int r;
-
#if defined(_MSC_VER)
- r = _mktemp_s(tmp_path, GIT_PATH_MAX);
+ if (_mktemp_s(tmp_path, GIT_PATH_MAX) != 0)
+ return GIT_EOSERR;
#else
- r = _mktemp(tmp_path);
-#endif
-
- if (r != 0)
+ if (_mktemp(tmp_path) == NULL)
return GIT_EOSERR;
+#endif
return p_creat(tmp_path, 0744);
}
diff --git a/src/win32/posix.h b/src/win32/posix.h
index 28d978959..db4ec19ec 100644
--- a/src/win32/posix.h
+++ b/src/win32/posix.h
@@ -1,3 +1,9 @@
+/*
+ * Copyright (C) 2009-2011 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
#ifndef INCLUDE_posix__w32_h__
#define INCLUDE_posix__w32_h__
diff --git a/src/win32/pthread.c b/src/win32/pthread.c
index 41cf5b35b..e0f6c14a8 100644
--- a/src/win32/pthread.c
+++ b/src/win32/pthread.c
@@ -1,35 +1,15 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- *
- * Original code by Ramiro Polla (Public Domain)
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#include "pthread.h"
int pthread_create(pthread_t *GIT_RESTRICT thread,
- const pthread_attr_t *GIT_RESTRICT GIT_UNUSED(attr),
- void *(*start_routine)(void*), void *GIT_RESTRICT arg)
+ const pthread_attr_t *GIT_RESTRICT GIT_UNUSED(attr),
+ void *(*start_routine)(void*), void *GIT_RESTRICT arg)
{
GIT_UNUSED_ARG(attr);
*thread = (pthread_t) CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)start_routine, arg, 0, NULL);
@@ -38,48 +18,48 @@ int pthread_create(pthread_t *GIT_RESTRICT thread,
int pthread_join(pthread_t thread, void **value_ptr)
{
- int ret;
- ret = WaitForSingleObject(thread, INFINITE);
- if (ret && value_ptr)
- GetExitCodeThread(thread, (void*) value_ptr);
- return -(!!ret);
+ int ret;
+ ret = WaitForSingleObject(thread, INFINITE);
+ if (ret && value_ptr)
+ GetExitCodeThread(thread, (void*) value_ptr);
+ return -(!!ret);
}
int pthread_mutex_init(pthread_mutex_t *GIT_RESTRICT mutex,
- const pthread_mutexattr_t *GIT_RESTRICT GIT_UNUSED(mutexattr))
+ const pthread_mutexattr_t *GIT_RESTRICT GIT_UNUSED(mutexattr))
{
- GIT_UNUSED_ARG(mutexattr);
- InitializeCriticalSection(mutex);
- return 0;
+ GIT_UNUSED_ARG(mutexattr);
+ InitializeCriticalSection(mutex);
+ return 0;
}
int pthread_mutex_destroy(pthread_mutex_t *mutex)
{
- DeleteCriticalSection(mutex);
- return 0;
+ DeleteCriticalSection(mutex);
+ return 0;
}
int pthread_mutex_lock(pthread_mutex_t *mutex)
{
- EnterCriticalSection(mutex);
- return 0;
+ EnterCriticalSection(mutex);
+ return 0;
}
int pthread_mutex_unlock(pthread_mutex_t *mutex)
{
- LeaveCriticalSection(mutex);
- return 0;
+ LeaveCriticalSection(mutex);
+ return 0;
}
int pthread_num_processors_np(void)
{
- DWORD_PTR p, s;
- int n = 0;
+ DWORD_PTR p, s;
+ int n = 0;
- if (GetProcessAffinityMask(GetCurrentProcess(), &p, &s))
- for (; p; p >>= 1)
- n += p&1;
+ if (GetProcessAffinityMask(GetCurrentProcess(), &p, &s))
+ for (; p; p >>= 1)
+ n += p&1;
- return n ? n : 1;
+ return n ? n : 1;
}
diff --git a/src/win32/pthread.h b/src/win32/pthread.h
index 10949f1eb..3ea8c7ac1 100644
--- a/src/win32/pthread.h
+++ b/src/win32/pthread.h
@@ -1,28 +1,8 @@
/*
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2,
- * as published by the Free Software Foundation.
+ * Copyright (C) 2009-2011 the libgit2 contributors
*
- * In addition to the permissions in the GNU General Public License,
- * the authors give you unlimited permission to link the compiled
- * version of this file into combinations with other programs,
- * and to distribute those combinations without any restriction
- * coming from the use of this file. (The General Public License
- * restrictions do apply in other respects; for example, they cover
- * modification of the file, and distribution when not linked into
- * a combined executable.)
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- *
- * Original code by Ramiro Polla (Public Domain)
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef GIT_PTHREAD_H
@@ -45,8 +25,8 @@ typedef HANDLE pthread_t;
#define PTHREAD_MUTEX_INITIALIZER {(void*)-1};
int pthread_create(pthread_t *GIT_RESTRICT,
- const pthread_attr_t *GIT_RESTRICT,
- void *(*start_routine)(void*), void *__restrict);
+ const pthread_attr_t *GIT_RESTRICT,
+ void *(*start_routine)(void*), void *__restrict);
int pthread_join(pthread_t, void **);