]> git.proxmox.com Git - libgit2.git/log
libgit2.git
15 years agoAvoid using a gcc compiler language extension
Ramsay Jones [Wed, 18 Feb 2009 18:50:36 +0000 (18:50 +0000)]
Avoid using a gcc compiler language extension

In particular, using pointer arithmetic on void pointers,
despite being quite useful, is not legal in standard C.
Avoiding non-standard C constructs will help in porting
the library to other compilers/platforms.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd built-in (Mozilla) SHA1 routines
Ramsay Jones [Thu, 26 Feb 2009 20:37:20 +0000 (20:37 +0000)]
Add built-in (Mozilla) SHA1 routines

Paul agreed to the GCC-exception license by email:
|
| From: Paul Kocher <paul@cryptography.com>
| Date: Sun, 15 Mar 2009 11:37:23 -0700
| Subject: Re: Adding Mozilla SHA1 implementation to libgit2
|
| Yes - that's fine.
|
| At 01:56 AM 3/5/2009, Andreas Ericsson wrote:
| > Hi Paul. We spoke earlier about this, if you remember?
| > We'd like to add the GCC-exception to the GPL license
| > for these files.

Signed-off-by: Paul Kocher <paul@cryptography.com>
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoCorrect some comments in readloose tests
Ramsay Jones [Tue, 3 Feb 2009 18:16:11 +0000 (18:16 +0000)]
Correct some comments in readloose tests

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd the git_odb_exists() object query function
Ramsay Jones [Tue, 10 Feb 2009 21:49:48 +0000 (21:49 +0000)]
Add the git_odb_exists() object query function

This function determines if the given object can be found
in the object database. At present, only the local object
database is searched.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoRearrange some code to improve clarity
Ramsay Jones [Tue, 3 Feb 2009 18:25:13 +0000 (18:25 +0000)]
Rearrange some code to improve clarity

In particular, the test for z-stream input completion
(zs.avail_in != 0) logically belongs with the test for
the Z_STREAM_END stream status. This is also consistent
with the identical check in finish_inflate().

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoCheck for error returns from inflateInit()
Ramsay Jones [Tue, 3 Feb 2009 18:23:50 +0000 (18:23 +0000)]
Check for error returns from inflateInit()

At present, it is sufficient to ensure that an error return
from inflateInit() is not ignored. Most error returns, like
Z_VERSION_ERROR and Z_STREAM_ERROR, indicate programming or
build errors. These errors could, perhaps, be handled with
simple asserts. However, for a Z_MEM_ERROR, we may want to
perform some further error handling in the future.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoFix a potential memory leak
Ramsay Jones [Tue, 3 Feb 2009 18:22:09 +0000 (18:22 +0000)]
Fix a potential memory leak

In particular, neglecting to call inflateEnd() along various
codepaths in the inflate_tail() routine, would result in the
failure to release zlib internal state.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoUse install instead of 'cp -f' and 'mkdir -p'.
Ingmar Vanhassel [Fri, 30 Jan 2009 22:55:56 +0000 (22:55 +0000)]
Use install instead of 'cp -f' and 'mkdir -p'.

Signed-off-by: Ingmar Vanhassel <ingmar@exherbo.org>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd libgit2.pc to make clean rule.
Ingmar Vanhassel [Fri, 30 Jan 2009 22:55:55 +0000 (22:55 +0000)]
Add libgit2.pc to make clean rule.

Signed-off-by: Ingmar Vanhassel <ingmar@exherbo.org>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd support for installing to a libdir other than 'lib'.
Ingmar Vanhassel [Fri, 30 Jan 2009 22:55:54 +0000 (22:55 +0000)]
Add support for installing to a libdir other than 'lib'.

Signed-off-by: Ingmar Vanhassel <ingmar@exherbo.org>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd DESTDIR support.
Ingmar Vanhassel [Fri, 30 Jan 2009 22:55:53 +0000 (22:55 +0000)]
Add DESTDIR support.

Signed-off-by: Ingmar Vanhassel <ingmar@exherbo.org>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoTidy up the readloose tests
Ramsay Jones [Mon, 12 Jan 2009 19:51:17 +0000 (19:51 +0000)]
Tidy up the readloose tests

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd some (macro) file operation wrappers
Ramsay Jones [Mon, 12 Jan 2009 19:44:51 +0000 (19:44 +0000)]
Add some (macro) file operation wrappers

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd git__dirname and git__basename utility routines
Ramsay Jones [Mon, 12 Jan 2009 19:42:13 +0000 (19:42 +0000)]
Add git__dirname and git__basename utility routines

These routines are intended to extract the directory and
base name from a path string. Note that these routines
do not interact with any filesystem and work only on the
text of the path.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoFix a sparse "symbol not declared" warning
Ramsay Jones [Mon, 12 Jan 2009 19:38:37 +0000 (19:38 +0000)]
Fix a sparse "symbol not declared" warning

In particular, the git__delta_apply() function has not been
declared prior to it's definition. In order to suppress the
warning, include the delta-apply.h header which provides the
public interface. This ensures that the declaration and
definition are consistent.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd the binary delta apply algorithm for pack style deltas
Shawn O. Pearce [Sat, 3 Jan 2009 12:21:30 +0000 (04:21 -0800)]
Add the binary delta apply algorithm for pack style deltas

The git__delta_apply() function can be used to apply a Git style
delta, such as those used in pack files or in git patch files,
to recover the original object stream.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoPrecompute the fanout decoding and the oid offset in a pack-*.idx
Shawn O. Pearce [Sat, 3 Jan 2009 11:34:09 +0000 (03:34 -0800)]
Precompute the fanout decoding and the oid offset in a pack-*.idx

The fanout table is fairly commonly accessed, we need to read it
twice for each object we lookup in any given pack file.  Most of
the processors running Git are running in little-endian mode, as
they are variants of the x86 platform, so reading the fanout is
a costly operation as we need to convert from network byte order
to local byte order.  By decoding the fanout table into a malloc
obtained buffer we can save these 2 decode operations per lookup
and make search go more quickly.

This also cleans up the initialization of the search functions
by cutting out a few instructions, saving a small amount of time.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd basic support to read pack-*.idx v1 and v2 files
Shawn O. Pearce [Sat, 3 Jan 2009 10:41:26 +0000 (02:41 -0800)]
Add basic support to read pack-*.idx v1 and v2 files

The index data is mapped into memory and then scanned using a
binary search algorithm to locate the matching entry for the
supplied git_oid.  The standard fanout hash trick is applied to
reduce the search space by 8 iterations.

Since the v1 and v2 file formats differ in their search function,
due to the different layouts used for the object records, we use
two different search implementations and a virtual function pointer
to jump to the correct version of code for the current pack index.
The single function jump per-pack should be faster then computing
a branch point inside the inner loop of a common binary search.

To improve concurrency during read operations the pack lock is only
held while verifying the index is actually open, or while opening
the index for the first time.  This permits multiple concurrent
readers to scan through the same index.

If an invalid index file is opened we close it and mark the
git_pack's invalid bit to true.  The git_pack structure is kept
around in its parent git_packlist, but the invalid bit will cause
all future readers to skip over the pack entirely.  Pruning the
invalid entries is relatively unimportant because they shouldn't
be very common, a $GIT_DIRECTORY/objects/pack directory tends to
only have valid pack files.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd a simple mmap wrapper for cross-platform mmap usage
Shawn O. Pearce [Sat, 3 Jan 2009 08:36:10 +0000 (00:36 -0800)]
Add a simple mmap wrapper for cross-platform mmap usage

Win32 has a variant of mmap that is harder to use than POSIX, but
to run natively and efficiently on Win32 we need some form of it.

gitfo_map_ro() provides a basic mmap function for use in locations
where we need read-only random data access to large ranges of a file,
such as a pack-*.idx.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoRefactor pack memory management and locking to be safer
Shawn O. Pearce [Sat, 3 Jan 2009 08:02:25 +0000 (00:02 -0800)]
Refactor pack memory management and locking to be safer

Using an atomic reference counter is difficult to make
cross-platform, as the reference count implementations
are generally processor specific.  Its also hard to do
a proper multi-read/single-write implementation.

We now use a simple mutex around the reference count for the list
of packs.  Readers grab the mutex and either build the list, or
increment the existing one's reference count.  When the reader is
done with the list, the reference count is decremented.  In this way
parallel readers are able to operate on the list without worrying
about it being deallocated out from under them.

Individual pack structures are held by reference counts, but we
only care about the list the pack structure is held in.  There is
no need to increment/decrement the pack reference counts as we
scan through them during a read operation, the caller holds the
git_packlist and that is sufficient to hold the packs it references.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoFix snprintf compiler warning on cygwin
Ramsay Jones [Fri, 2 Jan 2009 20:51:47 +0000 (20:51 +0000)]
Fix snprintf compiler warning on cygwin

As far as gcc is concerned, the "z size specifier" is available as
an extension to the language, which is available with or without any
-std= switch.  (I think you have to go back to 2.95 for a version
of gcc which doesn't work.)  Many other compilers have this as an
extension as well (ie without the equivalent of -std=c99).

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoChange the use of asm/atomic.h to require -DGIT_HAS_ASM_ATOMIC
Shawn O. Pearce [Sat, 3 Jan 2009 05:48:40 +0000 (21:48 -0800)]
Change the use of asm/atomic.h to require -DGIT_HAS_ASM_ATOMIC

These headers aren't always available; they typically come from the
Linux kernel, but aren't supposed to be exported into the userspace
/usr/include.  Modern kernels won't install these and some distros
rm -rf the directory post kernel header install.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoFix pthread_mutex based gitrc_dec
Shawn O. Pearce [Sat, 3 Jan 2009 05:41:52 +0000 (21:41 -0800)]
Fix pthread_mutex based gitrc_dec

The function should return true only when the counter drops to 0.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoFind pack files in $GIT_DIR/objects/pack directory on git_odb_open
Shawn O. Pearce [Thu, 1 Jan 2009 00:20:05 +0000 (16:20 -0800)]
Find pack files in $GIT_DIR/objects/pack directory on git_odb_open

Currently we only catalog the available pack files into a table,
storing their path names relative to the pack directory.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoDefine gitfo_exists to determine file presence
Shawn O. Pearce [Thu, 1 Jan 2009 00:07:38 +0000 (16:07 -0800)]
Define gitfo_exists to determine file presence

When scanning the pack directory we need to see if the path
name is present for ".idx" when we discover a ".pack" file.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd git__fmt as an easier to use snprintf
Shawn O. Pearce [Thu, 1 Jan 2009 00:06:48 +0000 (16:06 -0800)]
Add git__fmt as an easier to use snprintf

Checking the return value of snprintf is a pain, as it must be
>= 0 and < sizeof(buffer).  git__fmt is a simple wrapper to
perform these checks.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoRewrite git_foreach_dirent into gitfo_dirent
Shawn O. Pearce [Wed, 31 Dec 2008 23:35:36 +0000 (15:35 -0800)]
Rewrite git_foreach_dirent into gitfo_dirent

Our fileops API is currently private.  We aren't planning on supplying
a cross-platform file API to applications that link to us.  If we did,
we'd probably whole-sale publish fileops, not just the dirent code.

By moving it to be private we can also change the call signature to
permit the buffer to be passed down through the call chain.  This is
very helpful when we are doing a recursive scan as we can reuse just
one buffer in all stack frames, reducing the impact the recursion has
on the stack frames in the data cache.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd string utility functions for prefix and suffix compares
Shawn O. Pearce [Wed, 31 Dec 2008 22:35:39 +0000 (14:35 -0800)]
Add string utility functions for prefix and suffix compares

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd a build variable to allow supression of -fvisibility
Ramsay Jones [Wed, 31 Dec 2008 21:34:03 +0000 (21:34 +0000)]
Add a build variable to allow supression of -fvisibility

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoRun ranlib on libgit2.a after archiving it
Shawn O. Pearce [Wed, 31 Dec 2008 21:38:47 +0000 (13:38 -0800)]
Run ranlib on libgit2.a after archiving it

Some linkers require ranlib to build a symbol table on the archive
in order to work with it.  Most platforms that don't have this
requirement permit ranlib as a noop.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd basic locking to the git_odb structure
Shawn O. Pearce [Wed, 31 Dec 2008 21:27:51 +0000 (13:27 -0800)]
Add basic locking to the git_odb structure

We grab the lock while accessing the alternates list, ensuring that
we only initialize it once for the given git_odb.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd a mutex and atomic counter abstraction and implementations
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>
15 years agoCleanup our header inclusion order to ensure pthread.h is early
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>
15 years agoRename the test cases to run in specific orders
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>
15 years agoUndefine malloc,strdup,calloc before redefining them
Shawn O. Pearce [Wed, 31 Dec 2008 15:34:43 +0000 (07:34 -0800)]
Undefine malloc,strdup,calloc before redefining them

Some systems may use cpp macros to define these functions, glibc
appears to be one of them.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoSet GIT_EOSERR when the OS errno should be consulted
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>
15 years agoWrap malloc and friends and report out of memory as GIT_ENOMEM
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>
15 years agoRename the path of the objects directory to be more specific
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>
15 years agoChange git_odb__read_packed to return ENOTFOUND until implemented
Shawn O. Pearce [Wed, 31 Dec 2008 06:25:30 +0000 (22:25 -0800)]
Change git_odb__read_packed to return ENOTFOUND until implemented

We didn't search for the object, so we cannot possibly promise it
to the caller of git_odb_read().

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoFix size_t snprintf warning by using PRIuPTR format macro
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>
15 years agoSupport building on Mac OS X by using pthread_getspecific for TLS
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>
15 years agoRemove unnecessary import of stdlib.h from revwalk.h
Shawn O. Pearce [Wed, 31 Dec 2008 05:50:10 +0000 (21:50 -0800)]
Remove unnecessary import of stdlib.h from revwalk.h

OS headers are best imported from a more central location anyway.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoCleanup formatting in our head files to be more consistent
Shawn O. Pearce [Wed, 31 Dec 2008 05:25:13 +0000 (21:25 -0800)]
Cleanup formatting in our head files to be more consistent

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoChange usages of static inline to GIT_INLINE
Julio Espinoza-Sokal [Sun, 21 Dec 2008 01:47:41 +0000 (20:47 -0500)]
Change usages of static inline to GIT_INLINE

Signed-off-by: Julio Espinoza-Sokal <julioes@gmail.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoFix pkgconfig file wrt last added dependencies
Steve Frécinaux [Wed, 31 Dec 2008 00:48:36 +0000 (01:48 +0100)]
Fix pkgconfig file wrt last added dependencies

libz and libcrypto dependencies were added recently while libgit2.pc
did not get updated.

Signed-off-by: Steve Frécinaux <code@istique.net>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd a routine to determine a git_oid given an git_obj
Ramsay Jones [Sat, 27 Dec 2008 18:59:43 +0000 (18:59 +0000)]
Add a routine to determine a git_oid given an git_obj

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd some routines for SHA1 hash computation
Ramsay Jones [Sat, 27 Dec 2008 18:58:25 +0000 (18:58 +0000)]
Add some routines for SHA1 hash computation

[sp: Changed signature for output to use git_oid, and added
     a test case to verify an allocated git_hash_ctx can be
     reinitialized and reused.]

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoFix a bug in gitfo_read_file()
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>
15 years agoAdd pkg-config support.
Steve Frécinaux [Tue, 30 Dec 2008 11:10:01 +0000 (12:10 +0100)]
Add pkg-config support.

The libgit2.pc is generated on make install and installed, to allow
using the lib through the pkg-config helper.

Signed-off-by: Steve Frécinaux <code@istique.net>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd make install and uninstall targets.
Steve Frécinaux [Tue, 30 Dec 2008 11:10:00 +0000 (12:10 +0100)]
Add make install and uninstall targets.

It accepts a prefix= parameter (default: /usr/local).

Signed-off-by: Steve Frécinaux <code@istique.net>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoImplement git_odb__read_loose()
Ramsay Jones [Thu, 18 Dec 2008 22:58:10 +0000 (22:58 +0000)]
Implement git_odb__read_loose()

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd a file reading routine along with an io buffer type
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>
15 years agoRemove references to src/git/config.h
Shawn O. Pearce [Thu, 18 Dec 2008 16:20:50 +0000 (08:20 -0800)]
Remove references to src/git/config.h

It was removed in ec250c6e18e56d12714f9010e1b15e5feec5f473.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoRun tests in their own subdirectory
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>
15 years agoAdd some git_otype string conversion and testing routines
Ramsay Jones [Wed, 10 Dec 2008 18:31:28 +0000 (18:31 +0000)]
Add some git_otype string conversion and testing routines

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoFix an "implicit function definition" warning on cygwin
Ramsay Jones [Wed, 3 Dec 2008 23:54:47 +0000 (23:54 +0000)]
Fix an "implicit function definition" warning on cygwin

In particular, the warning relates to malloc(), which is
declared in <stdlib.h>.  This header is now included,
indirectly, via the "common.h" header.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd a GIT_PATH_MAX constant
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>
15 years agoFix some doxygen warnings and errors
Ramsay Jones [Wed, 3 Dec 2008 23:52:57 +0000 (23:52 +0000)]
Fix some doxygen warnings and errors

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd Adam Simpkins to list of consenting authors
Andreas Ericsson [Wed, 3 Dec 2008 09:27:48 +0000 (10:27 +0100)]
Add Adam Simpkins to list of consenting authors

Signed-off-by: Andreas Ericsson <ae@op5.se>
15 years agoAdd routines to convert git_oid to hex strings
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>
15 years agoDiasble TLS on cygwin
Ramsay Jones [Sat, 29 Nov 2008 19:21:24 +0000 (19:21 +0000)]
Diasble TLS on cygwin

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>
15 years agoUse __CHECKER__ to detect when sparse is running
Ramsay Jones [Sat, 29 Nov 2008 19:20:07 +0000 (19:20 +0000)]
Use __CHECKER__ to detect when sparse is running

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>
15 years agoUse cgcc in the sparse target
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>
15 years agoFixup documentation to reflect the "git_obj" rename
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>
15 years agoAdd a dirent walker to the fileops API
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>
15 years agoAdd an io caching layer to the gitfo api
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>
15 years agoRemove config.h and make fileops an internal API
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>
15 years agodoxygen config: Update path to public headers
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>
15 years agoAdd a new author state "ign" to git.git-authors
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>
15 years agoAdd Kristian Høgsberg to the list of consenting authors
Andreas Ericsson [Tue, 25 Nov 2008 15:28:51 +0000 (16:28 +0100)]
Add Kristian Høgsberg to the list of consenting authors

Signed-off-by: Andreas Ericsson <ae@op5.se>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd Adam Simpkins as ??? to git.git-authors
Andreas Ericsson [Sat, 22 Nov 2008 13:03:06 +0000 (14:03 +0100)]
Add Adam Simpkins as ??? to git.git-authors

Adam has made significant contributions to the http
transport code, but his listed email address is no longer
valid.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd René Scharfe to git.git-authors
Andreas Ericsson [Sat, 22 Nov 2008 13:02:07 +0000 (14:02 +0100)]
Add René Scharfe to git.git-authors

Signed-off-by: Andreas Ericsson <ae@op5.se>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd Matthieu Moy and Steffen Prohaska to git.git-authors
Andreas Ericsson [Fri, 21 Nov 2008 08:26:57 +0000 (09:26 +0100)]
Add Matthieu Moy and Steffen Prohaska to git.git-authors

Signed-off-by: Andreas Ericsson <ae@op5.se>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd Sven Verdoolaege to git.git-authors
Andreas Ericsson [Thu, 20 Nov 2008 15:25:41 +0000 (16:25 +0100)]
Add Sven Verdoolaege to git.git-authors

Signed-off-by: Andreas Ericsson <ae@op5.se>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoMake using CFLAGS a bit simpler
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>
15 years agoAdd $(CONFIG_H) as a build-dependency for sparse
Andreas Ericsson [Sat, 22 Nov 2008 14:33:15 +0000 (15:33 +0100)]
Add $(CONFIG_H) as a build-dependency for sparse

Signed-off-by: Andreas Ericsson <ae@op5.se>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoMake src/git/config.h a macro in Makefile
Andreas Ericsson [Sat, 22 Nov 2008 14:25:59 +0000 (15:25 +0100)]
Make src/git/config.h a macro in Makefile

This makes it far more convenient to reference as a dependency
for other targets.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoRemove license top-comment from public header files
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>
15 years agoAdd an embryo of a TLS-aware error handling system
Andreas Ericsson [Tue, 18 Nov 2008 21:20:15 +0000 (22:20 +0100)]
Add an embryo of a TLS-aware error handling system

This adds the per-thread global variable git_errno to the
system, which callers can examine to get information about
an error.

Two helper functions are added to reduce LoC-count for the
library code itself.

Also, some exceptions are made for running sparse on GIT_TLS
definitions, since it doesn't grok thread-local variables at
all.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd util.h - utility macros
Andreas Ericsson [Sat, 22 Nov 2008 13:44:47 +0000 (14:44 +0100)]
Add util.h - utility macros

ARRAY_SIZE() et al go in util.h, included from common.h

Signed-off-by: Andreas Ericsson <ae@op5.se>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd internal common.h file
Andreas Ericsson [Sat, 22 Nov 2008 13:42:12 +0000 (14:42 +0100)]
Add internal common.h file

This one pulls in compiler compatibility macros, some
common header files, and also the public common.h header.

C source files are modified to use the private common.h
in favour of the public one.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd cc-compat.h - C compiler compat macros for internal use
Andreas Ericsson [Sat, 22 Nov 2008 13:40:51 +0000 (14:40 +0100)]
Add cc-compat.h - C compiler compat macros for internal use

Holds things such as FLEX_ARRAY and whatnot.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoRename git_revpool_* functions gitrp_*
Andreas Ericsson [Sat, 22 Nov 2008 13:57:40 +0000 (14:57 +0100)]
Rename git_revpool_* functions gitrp_*

Otherwise their prototypes don't match their declarations.

Detected by 'sparse', which is obviously good to run
before each commit.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd a 'sparse' make target
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>
15 years agos/COPYING/.HEADER/ for install-headers target
Andreas Ericsson [Sat, 22 Nov 2008 12:05:32 +0000 (13:05 +0100)]
s/COPYING/.HEADER/ for install-headers target

We don't want to prepend the entire license; Only the
file header part of it.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoGet rid of GIT__PRIVATE macro
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>
15 years agoAdd compiler/platform agnostic thread-local storage
Andreas Ericsson [Tue, 18 Nov 2008 18:06:25 +0000 (19:06 +0100)]
Add compiler/platform agnostic thread-local storage

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>
15 years agoAdd a fake and phony install-headers target
Andreas Ericsson [Tue, 18 Nov 2008 00:27:29 +0000 (01:27 +0100)]
Add a fake and phony install-headers target

It actually does what it's supposed to (more or less),
but not very portably and not to the correct directory.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoMove public headers to src/git
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>
15 years agos/git_revp/git_revpool/
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>
15 years agoRename "git_sobj" "git_obj"
Andreas Ericsson [Mon, 17 Nov 2008 23:59:36 +0000 (00:59 +0100)]
Rename "git_sobj" "git_obj"

The 's' never really made sense, since it's not a "small"
object at all, but rather a plain object. As such, it should
have a "plain" object name.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoUse same-directory include for public headers
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>
15 years agoList git.git authors consenting to relicense their code
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>
15 years agoAdd a zlib support shell
Shawn O. Pearce [Tue, 4 Nov 2008 02:53:09 +0000 (18:53 -0800)]
Add a zlib support shell

Some versions of zlib don't have a deflateBound defined, so
we define it ourselves after including zlib.h.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoImplement some of the basic git_odb open and close API
Shawn O. Pearce [Tue, 4 Nov 2008 02:39:37 +0000 (18:39 -0800)]
Implement some of the basic git_odb open and close API

Far from being complete, but its a good start.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd git_fsize to the os file API
Shawn O. Pearce [Tue, 4 Nov 2008 02:38:57 +0000 (18:38 -0800)]
Add git_fsize to the os file API

This permits us to get the size of an opened file.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoRedefine git_fread, git_fwrite to transfer the whole unit
Shawn O. Pearce [Tue, 4 Nov 2008 01:14:25 +0000 (17:14 -0800)]
Redefine git_fread, git_fwrite to transfer the whole unit

We never want to accept a short read or a short write when
transferring data to or from a local file.

Either the entire read (or write) completes or the operation
failed and we will not recover gracefully from it.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoAdd git_oid_cpy, git_oid_cmp as inline functions
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>
15 years agoAdd an extra oid test to verify control characters aren't read
Shawn O. Pearce [Tue, 4 Nov 2008 02:19:02 +0000 (18:19 -0800)]
Add an extra oid test to verify control characters aren't read

We only want hex digits to be read, any other character in the 8-bit
character set is invalid within an id string.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
15 years agoChange test_main to run a single test case out of the suite
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>