Commit Graph

5401 Commits

Author SHA1 Message Date
Ramsay Jones
2bf93fa107 Correct the spelling of the FLEX_ARRAY macro
When setting the default value, the macro name was specified
as GIT_FLEX_ARRAY, which is inconsistent with it's earlier
usage in the file. This caused a compilation error, using the
MS Visual C/C++ compiler, when compiling the git_packlist
struct definition in src/odb.c.

In addition to changing the spelling of the FLEX_ARRAY macro
to GIT_FLEX_ARRAY, including it's use in src/odb.c, we also
rename the TYPEOF macro to GIT_TYPEOF.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2009-06-15 07:33:44 +02:00
Ramsay Jones
10aa3fa72a Fix some "signed/unsigned mismatch" (msvc) compiler warnings
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2009-06-05 12:14:24 +02:00
Ramsay Jones
4c9a397329 Improve the portability of the gitfo_cache code (to 64-bit systems)
This supresses some "conversion from 'size_t' to 'unsigned int',
possible loss of data" warning messages from the MS Visual C/C++
compiler with -Wp64.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2009-06-05 12:14:07 +02:00
Ramsay Jones
3e0fb8fb56 thread-utils.h: Avoid using a non-standard C construct
In particular, in standard C, a struct or union must have at
least one member declared (ie. structs and unions cannot be
empty). Some compilers allow empty structs as an extension
and won't even issue a warning unless asked for it (eg, gcc
requires -pedantic). Some compilers allow empty structs as
an extension and will only treat it as an error if asked for
strict checking (eg Digital-Mars with -A). Some compilers
simply treat it as an error (eg MS Visual C/C++).

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2009-06-05 12:13:48 +02:00
Ramsay Jones
c8d42b9bd1 t0020-dirent.c: Add explicit returns to the callback functions
In particular, the one_entry() and dont_call_me() callback
functions require explicit returns, in order to suppress
some "control path" compiler warnings (from MS Visual C/C++).

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2009-06-05 12:12:42 +02:00
Ramsay Jones
aee8b26e63 Makefile: move test related targets to a new tests/Makefile
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2009-06-05 12:12:42 +02:00
Ramsay Jones
cf33ac7a3d Makefile: Add CFLAGS to the "test_main.c" compile target
Also, add the <string.h> include to test_main.c, in order to
suppress the resulting "implicit declaration of strcmp()" warning.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2009-06-05 12:12:42 +02:00
Ramsay Jones
e17a3f5673 Implement git_odb_write()
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2009-06-05 10:22:20 +02:00
Ramsay Jones
ca481fc4f1 Add the git_move_file() function
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2009-06-05 10:21:52 +02:00
Ramsay Jones
4319860c60 win32: Add some file operation stubs and wrapper functions
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2009-06-05 10:21:39 +02:00
Ramsay Jones
4d503f884a gitfo_exists: replace call to stat() with access()
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2009-06-05 10:21:25 +02:00
Ramsay Jones
ac04bdf6e0 Fix a usage error in a call to the object_file_name() function
In 82324ac, the new static function exists_loose() called
object_file_name() and, in order to detect an error return,
tested for a negative value. This usage is incorrect, as
the error return is indicated by a positive return value.
(A successful call is indicated by a zero return value)

The only error return from object_file_name() relates to
insufficient buffer space and the return value gives the
required minimum buffer size (which will always be >0).

If the caller requires a dynamically allocated buffer,
this allows something like the following call sequence:

    size_t len = object_file_name(NULL, 0, db->object_dir, id);
    char *buf = git__malloc(len);
    if (!buf)
        error(...);
    object_file_name(buf, len, db->object_dir,id);
    ...

No current callers take advantage of this capability.

Fix up the call site and change the return type of the
function, from int to size_t, which more accurately
reflects the implementation.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2009-06-05 10:21:11 +02:00
Ramsay Jones
fd0ec03339 Fix comments in renamed t020?-readloose tests
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-03-30 07:18:42 -07:00
Ramsay Jones
498bc09068 t0020-dirent.c: allow test to be run standalone
This test assumed that it was invoked in an empty directory,
which is true when run from the Makefile, and so would fail
if run standalone. In order to allow the test to work when
run from any directory, create a sub directory "dir-walk"
and chdir() into this directory while running the tests.

Also, add some additional tests.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-03-30 07:18:42 -07:00
Ramsay Jones
502acd164f win32: Add missing include for mkdir() and rmdir()
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-03-30 07:18:42 -07:00
Ramsay Jones
0234c186ba win32: Add <dirent.h> directory reading routines
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-03-20 14:39:03 -07:00
Ramsay Jones
79ca2edcd4 win32: Add routines to abstract memory-mapped file functions
In particular, the git__mmap() and git__munmap() routines provide
the interface to platform specific memory-mapped file facilities.
We provide implementations for unix and win32, which can be found
in their own sub-directories.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-03-20 14:39:02 -07:00
Ramsay Jones
7a6cf81537 win32: Open or create files in binary mode
On windows, unless we use the O_BINARY flag in the open()
call, the file I/O routines will perform line ending
conversion (\r\n => \n on input, \n => \r\n on output).
In addition to the performance penalty, most files in the
object database are binary and will, therefore, become
corrupted by this conversion.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-03-17 19:10:51 -07:00
Julio Espinoza-Sokal
0f39781c25 Add a test to check existence of loose objects.
Signed-off-by: Julio Espinoza-Sokal <julioes@gmail.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-03-17 19:08:00 -07:00
Julio Espinoza-Sokal
491442f97e Factor out test helper methods for creating/deleting loose objects
Signed-off-by: Julio Espinoza-Sokal <julioes@gmail.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-03-17 19:06:37 -07:00
Ramsay Jones
840fb8b7cb win32: fixup some headers to improve win32 compilation
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-03-17 19:00:08 -07:00
Ramsay Jones
a9984a4e60 Fix some (digital-mars) compiler warnings
In particular, conditional expressions which contain an
assignment statement, where the expression type is not
explicitly made to be boolean, elicits the following
message:
    warning 2: possible unintended assignment

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-03-17 18:59:26 -07:00
Ramsay Jones
fc3c3a2083 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>
2009-03-17 18:58:30 -07:00
Ramsay Jones
1906f2369d 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>
2009-03-17 18:54:42 -07:00
Ramsay Jones
04c9c16e55 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>
2009-02-11 11:20:57 -08:00
Ramsay Jones
82324ac1a5 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>
2009-02-11 11:04:55 -08:00
Ramsay Jones
e9f5e87781 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>
2009-02-11 10:47:03 -08:00
Ramsay Jones
236e7579fe 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>
2009-02-11 10:46:29 -08:00
Ramsay Jones
c94eb4aa76 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>
2009-02-11 10:45:50 -08:00
Ingmar Vanhassel
357bf82371 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>
2009-02-01 15:00:10 -08:00
Ingmar Vanhassel
3f84b7d30b Add libgit2.pc to make clean rule.
Signed-off-by: Ingmar Vanhassel <ingmar@exherbo.org>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-02-01 15:00:10 -08:00
Ingmar Vanhassel
19af3949ca 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>
2009-02-01 15:00:10 -08:00
Ingmar Vanhassel
521b4e69c6 Add DESTDIR support.
Signed-off-by: Ingmar Vanhassel <ingmar@exherbo.org>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-02-01 15:00:09 -08:00
Ramsay Jones
4730b72242 Tidy up the readloose tests
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-01-28 12:43:37 -08:00
Ramsay Jones
cfe96f31df 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>
2009-01-28 12:43:34 -08:00
Ramsay Jones
ced645ea9c 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>
2009-01-28 12:25:24 -08:00
Ramsay Jones
66a4bfac99 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>
2009-01-28 11:32:49 -08:00
Shawn O. Pearce
c23841c833 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>
2009-01-03 04:21:30 -08:00
Shawn O. Pearce
bed3229b55 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>
2009-01-03 03:34:09 -08:00
Shawn O. Pearce
a7c60cfc6d 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>
2009-01-03 02:56:16 -08:00
Shawn O. Pearce
20e7f426c3 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>
2009-01-03 01:16:02 -08:00
Shawn O. Pearce
098ac57a13 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>
2009-01-03 00:02:25 -08:00
Ramsay Jones
3a33c7b37f 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>
2009-01-02 21:53:47 -08:00
Shawn O. Pearce
51eb2f90a1 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>
2009-01-02 21:48:40 -08:00
Shawn O. Pearce
11bb049bdd 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>
2009-01-02 21:41:52 -08:00
Shawn O. Pearce
b438016ecd 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>
2008-12-31 16:20:05 -08:00
Shawn O. Pearce
7350e6337a 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>
2008-12-31 16:07:38 -08:00
Shawn O. Pearce
2c4b7707f7 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>
2008-12-31 16:06:48 -08:00
Shawn O. Pearce
5690f02e87 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>
2008-12-31 15:35:36 -08:00
Shawn O. Pearce
9eb7976448 Add string utility functions for prefix and suffix compares
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-12-31 14:35:39 -08:00