Shawn O. Pearce [Wed, 31 Dec 2008 21:20:21 +0000 (13:20 -0800)]
Add a mutex and atomic counter abstraction and implementations
These abstractions can be used to implement an efficient resource
reference counter and simple mutual exclusion. On pthreads we use
pthread_mutex_t, except when we are also on glibc and can directly
use its asm/atomic.h definitions.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce [Wed, 31 Dec 2008 21:16:31 +0000 (13:16 -0800)]
Cleanup our header inclusion order to ensure pthread.h is early
If we are using threads we need to make sure pthread.h comes
in before just about anything else. Some platforms enable
macros that alter what other headers define.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce [Wed, 31 Dec 2008 19:16:41 +0000 (11:16 -0800)]
Rename the test cases to run in specific orders
This way we can be fairly certain we run tests of lower-level
parts of the library before we run tests of higher-level more
complex parts. If there is any problem in a lower-level part
of the library, the earlier test will identify it and stop,
making it easire to troubleshoot the failure.
A rough naming guide has been added for the test suite to
explain the current category structure.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce [Wed, 31 Dec 2008 07:26:38 +0000 (23:26 -0800)]
Set GIT_EOSERR when the OS errno should be consulted
This error code indicates the OS error code has a better value
describing the last error, as it is likely a network or local
file IO problem identified by a C library function call.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce [Wed, 31 Dec 2008 07:21:36 +0000 (23:21 -0800)]
Wrap malloc and friends and report out of memory as GIT_ENOMEM
We now forbid direct use of malloc, strdup or calloc within the
library and instead use wrapper functions git__malloc, etc. to
invoke the underlying library malloc and set git_errno to a no
memory error code if the allocation fails.
In the future once we have pack objects in memory we are likely
to enhance these routines with garbage collection logic to purge
cached pack data when allocations fail. Because the size of the
function will grow somewhat large, we don't want to mark them for
inline as gcc tends to aggressively inline, creating larger than
expected executables.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce [Wed, 31 Dec 2008 06:29:04 +0000 (22:29 -0800)]
Rename the path of the objects directory to be more specific
We're likely to add additional path data, like the path of the
refs or the path to the config file into the git_odb structure,
as it may grow into the repository wrapper. Changing the name
of the objects directory reference makes it more clear should
we later add something else.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce [Wed, 31 Dec 2008 06:07:56 +0000 (22:07 -0800)]
Fix size_t snprintf warning by using PRIuPTR format macro
This is the correct C99 format code for the size_t type when passed
as an argument to the *printf family. If the platform doesn't
define it, we assume %lu and just cross our fingers that its the
proper setting for a size_t on this system. On most sane platforms,
"unsigned long" is the underlying type of "size_t".
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce [Wed, 31 Dec 2008 05:49:38 +0000 (21:49 -0800)]
Support building on Mac OS X by using pthread_getspecific for TLS
The Mach-O format does not permit gcc to implement the __thread
TLS specification, so we must instead emulate it using a single
int cell allocated from memory and stored inside of the thread
specific data associated with the current pthread.
What makes this tricky is git_errno must be a valid lvalue, so
we really need to return a pointer to the caller and deference it
as part of the git_errno macro.
The GCC-specific __attribute__((constructor)) extension is used
to ensure the pthread_key_t is allocated before any Git functions
are executed in the library, as this is necessary to access our
thread specific storage.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Ramsay Jones [Sat, 27 Dec 2008 18:56:16 +0000 (18:56 +0000)]
Fix a bug in gitfo_read_file()
In particular, when asked to read an empty file, this function
calls malloc() with a zero size allocation request. Standard C
says that the behaviour of malloc() in this case is implementation
defined.
[C99, 7.20.3 says "... If the size of the space requested is zero,
the behavior is implementation-defined: either a null pointer is
returned, or the behavior is as if the size were some nonzero
value, except that the returned pointer shall not be used to
access an object."]
Finesse the issue by over-allocating by one byte. Setting the extra
byte to '\0' may also provide a useful sentinel for text files.
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Ramsay Jones [Thu, 18 Dec 2008 22:56:14 +0000 (22:56 +0000)]
Add a file reading routine along with an io buffer type
In particular, the gitfo_read_file() routine can be used to slurp
the complete file contents into an gitfo_buf structure. The buffer
content will be allocated by malloc() and may be released by the
gitfo_free_buf() routine. The io buffer type can be initialised
on the stack with the GITFO_BUF_INIT macro.
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce [Thu, 18 Dec 2008 16:17:05 +0000 (08:17 -0800)]
Run tests in their own subdirectory
This way tests can run in parallel without stepping on each other's
temporary work files. If a test passes the directory is removed
completely; if a test fails only empty directories are removed.
This permits inspection of the failed test's left behind state.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Ramsay Jones [Wed, 3 Dec 2008 23:53:55 +0000 (23:53 +0000)]
Add a GIT_PATH_MAX constant
The PATH_MAX symbol is often, but not always, defined
in the <limits.h> header. In particular, on cygwin you
need to include this header to avoid a compilation error.
However, some systems define PATH_MAX to be something as
small as 256, which POSIX is happy to allow, while others
allow much larger values. In general it can vary from
one filesystem to another.
In order to avoid the vagaries of different systems, define
our own symbol.
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce [Tue, 2 Dec 2008 17:56:23 +0000 (09:56 -0800)]
Add routines to convert git_oid to hex strings
[sp: Credit for some of this implementation goes to Pieter, I
started off a patch he proposed for libgit2 but reworked
enough of it that I don't want to blame him for any bugs.]
Suggested-by: Pieter de Bie <pdebie@ai.rug.nl> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Ramsay Jones [Sat, 29 Nov 2008 19:19:31 +0000 (19:19 +0000)]
Use cgcc in the sparse target
cgcc is the recommended way to run sparse, since it provides
many -Defines suitable to the given gcc platform. For example,
on some Ubuntu/glibc versions, a plain sparse invocation gives
the following warning:
"warning: This machine appears to be neither x86_64 nor i386."
Using "cgcc -no-compile" instead eliminates this warning.
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Acked-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Ramsay Jones [Sat, 29 Nov 2008 19:18:43 +0000 (19:18 +0000)]
Fixup documentation to reflect the "git_obj" rename
commit dff79e27d3d2cdc09790ded80fe2ea8ff5d61034 renamed
the (small object) "git_sobj" to a plain "git_obj", but
neglected to update some of the documentation to reflect
that change.
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Andreas Ericsson [Sat, 29 Nov 2008 14:34:20 +0000 (15:34 +0100)]
Add a dirent walker to the fileops API
Since at least MS have something like GetFirstDirEnt() and
GetNextDirEnt() (presumably with superior performance), we
can let MS hackers add support for a dirent walker using
that API instead, while we stick with the posix-style
readdir() calls.
Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Andreas Ericsson [Sat, 29 Nov 2008 14:28:12 +0000 (15:28 +0100)]
Add an io caching layer to the gitfo api
The idea is taken from Junio's work in read-cache.c, where
it's used for writing out the index without tap-dancing on
the poor harddrive. Since it's almost certainly useful for
cached writing of packfiles too, we turn it into a generic
API, making it perfectly simple to reuse it later.
gitfo_write_cached() has the same contract as gitfo_write(), it
returns GIT_SUCCESS if all bytes are successfully written (or were
at least buffered for later writing), and <0 if an error occurs
during buffer writing.
Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Andreas Ericsson [Sun, 23 Nov 2008 21:37:55 +0000 (22:37 +0100)]
Remove config.h and make fileops an internal API
Since it doesn't make sense to make the disk access stuff
portable *AND* public (that's a job for each application
imo), we can take a shortcut and just support unixy stuff
for now and get away with coding most of it as macros.
Since we go with an internal API for starters and only
provide higher-level API's to the libgit users, we'll be
ok with this approach.
Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Andreas Ericsson [Thu, 27 Nov 2008 08:26:52 +0000 (09:26 +0100)]
doxygen config: Update path to public headers
In d4043ee9d97031e94f205110996d2381dd26c540, public headers
were moved from include/git to src/git, but the doxygen
configuration wasn't updated to reflect this. This patch
amends that slippage, making documentation generation once
again work as intended.
Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Andreas Ericsson [Sat, 22 Nov 2008 13:04:25 +0000 (14:04 +0100)]
Add a new author state "ign" to git.git-authors
This is to be used for application code that currently
resides in git, but only for authors whose only not
insignificant contributions are for that code (such as
"imap-send").
Presently, this is used for Mike McCormack and Robert
Shearman.
Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Andreas Ericsson [Sat, 22 Nov 2008 14:35:31 +0000 (15:35 +0100)]
Make using CFLAGS a bit simpler
This patch introduces the $(ALL_CFLAGS) variable, which holds
$(BASIC_CFLAGS) as well as userdefined $(CFLAGS) and then
consistently uses that variable where both were used anyway.
Since we're in the area, we optimize the sparse running a
bit, getting rid of the shell and just letting sparse iterate
over the files.
Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Andreas Ericsson [Sat, 22 Nov 2008 14:17:17 +0000 (15:17 +0100)]
Remove license top-comment from public header files
Since it's being added when we install the headers anyway,
we might as well get rid of it. If anything, we should point
coders to the COPYING file in the project's root directory
instead of duplicating the same (large-ish) text everywhere.
Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Andreas Ericsson [Tue, 18 Nov 2008 21:17:40 +0000 (22:17 +0100)]
Add a 'sparse' make target
Given the confusion on git@vger, we'd better not name
this target "check" or (worse) "test", but it's still
useful to have. As "sparse", noone should have problems
understanding what it does.
Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Andreas Ericsson [Tue, 18 Nov 2008 20:28:55 +0000 (21:28 +0100)]
Get rid of GIT__PRIVATE macro
Using it in the first place means something's wrong.
This patch replaces it with an internal header which
carries the previously "protected" code instead.
Internal source-files simply include "commit.h" and
they're done. The internal header includes the public
one to make sure we always use the proper prototype.
Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
It doesn't cover all cases, but we can work on those as
we go along. For now, gcc, MSVC++, Intel C/C++, IBM XL C/C++,
Sun Studio C/C++ and Borland C++ Builder are the supported
compilers (although we boldly assume that they all are of
a recent enough version to support thread-local storage).
This is intended to be used in upcoming patches that implement
graceful (but TLS-dependant) error-handling in the library.
As an added bonus, we also bring the online_cpus() function
from git.git to detect the number of usable cpu's.
Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Andreas Ericsson [Tue, 18 Nov 2008 00:18:52 +0000 (01:18 +0100)]
Move public headers to src/git
It's arguably smoother to keep them close to the source,
as that's where one's working when modifying them. More
importantly, though, is the ability to use private headers
in the src/ dir that simply include "git/$samename.h" to
get to the public API at the same time.
Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Andreas Ericsson [Tue, 18 Nov 2008 00:02:27 +0000 (01:02 +0100)]
s/git_revp/git_revpool/
git_revp is something I personally can't stop pronouncing
"rev pointer". I'm sure others would suffer the same
problem.
Also, rename the git_revp_ sub-api "gitrp_". This is the
first of many such renames, primarily done to prevent
extreme inflation in the "git_" namespace, which we'd like
to reserve for a higher-level API.
While we're at it, we remove the noise-char "c" from a lot
of functions. Since revision walking is all about commits,
the common case should be that we're dealing with commits.
Exceptions can get a more mnemonic description as needed.
Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Andreas Ericsson [Mon, 17 Nov 2008 23:58:02 +0000 (00:58 +0100)]
Use same-directory include for public headers
It doesn't make sense to use "git/somefile.h" in the
public git headers, as it's quite likely that projects
using them will have a git directory themselves. This
alters it, making the public headers look for headers
in the same directory they themselves are in.
Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Andreas Ericsson [Mon, 17 Nov 2008 22:15:30 +0000 (23:15 +0100)]
List git.git authors consenting to relicense their code
Since re-using code from git.git proper is the quick way
forward, we need to list those who have given their consent
to do just that. The relicense permission is only valid for
use with libgit2, and only for GPLv2 + gcc-exception (as
specified by 'COPYING'.
Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce [Tue, 4 Nov 2008 01:31:16 +0000 (17:31 -0800)]
Add git_oid_cpy, git_oid_cmp as inline functions
These are easily built off the standard C library functions memcpy
and memcmp. By marking these inline we stand a good chance of
the C compiler replacing the entire thing with tight machine code,
because many compilers will actually inline a memcmp or memcpy when
the 3rd argument (the size) is a constant value.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce [Tue, 4 Nov 2008 02:38:12 +0000 (18:38 -0800)]
Change test_main to run a single test case out of the suite
By passing the name of the test function on the command line
we execute exactly that one test, and then exit successfully
if the test did not fail. This permits multiple functions in
the same .c file, so they could be called from a shell script
or debugged independently externally.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce [Tue, 4 Nov 2008 01:00:54 +0000 (17:00 -0800)]
Fix Makefile to correctly handle 'make -j4 test'
If we have more than one test build running we cannot use the same
file for each test case; instead we need to use a per-test path so
there aren't any collisions.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce [Tue, 4 Nov 2008 00:29:56 +0000 (16:29 -0800)]
Move GIT_NORETURN into test_lib.h only
We should never have a noreturn style function in the library
itself, as such a function would prevent the calling application
from handling error conditions the way it wants.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce [Sun, 2 Nov 2008 01:14:22 +0000 (18:14 -0700)]
Create a basic test suite for the library and test oid functions
This is a horribly simple test suite that makes it fairly easy to
put together some basic function level unit tests on the library.
Its patterned somewhat after the test suite in git.git, but also
after the "Check" test library.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce [Sat, 1 Nov 2008 23:53:06 +0000 (16:53 -0700)]
Create a micro abstraction around the POSIX file APIs
This way we can start to write IO code to read and write files in the
Git object database, but provide a hook to inject native Win32 APIs
instead so libgit2 can be ported to run natively on that platform.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce [Sat, 1 Nov 2008 01:34:02 +0000 (18:34 -0700)]
Scratch the git_revp_attr configuration of a git_revp
This isn't the best idea I've head. Pierre Habouzit was suggesting
a technique of assigning a unique integer to each commit and then
allocating storage out of auxiliary pools, using the commit's unique
integer to index into any auxiliary pool in constant time. This way
both applications and the library can efficiently attach arbitrary
data onto a commit, such as rewritten parents, or flags, and have
them disconnected from the main object hash table.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce [Fri, 31 Oct 2008 17:57:04 +0000 (10:57 -0700)]
Hide git_odb's internal structure from applcation code
This way only structures we ask the caller to allocate on their
call stack or which we want to allow them to use members from
are shown in the API docs.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce [Fri, 31 Oct 2008 17:43:20 +0000 (10:43 -0700)]
Rename git_odb_sread to just git_odb_read
Most read calls will use the small object format, as the
majority of the content within the database is very small
objects (under 20 KB when inflated).
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>