Commit Graph

3381 Commits

Author SHA1 Message Date
Ramsay Jones
608d33fa67 Add a pack index 'virtual function' to search by file offset
In addition to searching the index by oid, we need to search by
'.pack' file offset, particularly when processing OBJ_OFS_DELTA
objects. Since the v1 and v2 file formats differ in the layout
of the object records, we provide two implementations of the
search function and initialise the (virtual) function pointer
appropriately.

Note that, as part of the creation of the 'offset index', we also
add a check that the offset data in the index is within the bounds
of the '.pack' file. Having sorted the file offsets, while creating
the index, we only need to check the smallest and largest values.

The offset index consists of the im_off_idx array, which contains
the index entry numbers sorted into file offset order, and the
im_off_next mapping array. The im_off_next array maps an index
entry number to the 'next' index entry in file offset order.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-02-28 20:13:29 +00:00
Ramsay Jones
abf5681c03 Change the interface of the pack index search function
In particular, on a successful search, we now return the index
entry number of the object rather than the '.pack' file offset.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-02-28 20:12:32 +00:00
Ramsay Jones
238e54bcff Add an 64-bit offset table index bounds check for v2 pack index
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-02-28 20:12:04 +00:00
Ramsay Jones
255a0dabb2 Add a minimum size check when opening an v2 pack index file
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-02-28 20:11:33 +00:00
Ramsay Jones
e8cc449fe9 win32: Add separate MinGW and MSVC compatability header files
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-02-28 20:10:56 +00:00
Ramsay Jones
56931d1ab4 Makefile: Add support for custom build options in config.mak file
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-02-28 20:10:35 +00:00
Ramsay Jones
1e5dd57214 Fix some coding style issues
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-02-28 20:09:45 +00:00
Ramsay Jones
74eff33f8b Makefile: Add support for building with MSVC
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-02-01 10:39:10 +01:00
Ramsay Jones
73dcf2876f msvc: Fix some "unreferenced formal parameter" warnings
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-01-20 20:22:10 +00:00
Ramsay Jones
e8a952561c msvc: Fix some -W4 warnings
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-01-20 20:20:47 +00:00
Ramsay Jones
1a7bae4d0f Fix some "unused parameter" warnings with -Wextra
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-01-20 20:19:55 +00:00
Ramsay Jones
e3fe32b6a4 Fix "'__thread' not at start of declaration" warnings (-Wextra)
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-01-20 20:19:06 +00:00
Ramsay Jones
0ef9d2aa93 Fix some "signed v unsigned comparison" warnings with -Wextra
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-01-20 20:18:36 +00:00
Ramsay Jones
a4f863af4d Fix an always false comparison "unsigned < 0" warning
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-01-20 20:18:15 +00:00
Ramsay Jones
803a6b4d41 Save the git_file in the gitfo_cache when enabling caching
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-01-20 20:17:56 +00:00
Ramsay Jones
1cfb0ff4b6 Makefile: Add some missing $(GIT_LIB) dependencies
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-01-20 20:17:18 +00:00
Ramsay Jones
e97179b6de win32: Add a 'git__' prefix to the directory reading routines
This reduces the global namespace pollution and allows for
a win32 compiler (eg. Open Watcom) to provide these routines
in a header other than <dirent.h> (eg in <io.h>).

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-01-20 20:16:34 +00:00
Ramsay Jones
90d4d2f0fc win32: Use an 64-bit file offset type
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-01-20 20:15:57 +00:00
Ramsay Jones
a1c0728d12 Add support for the MinGW platform
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-01-20 20:15:07 +00:00
Ramsay Jones
cfe3a027ab Use a 64 bit off_t throughout the library and tests on POSIX
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-01-20 20:13:07 +00:00
Ramsay Jones
960ca1d779 Add the git_oid_to_string() utility function
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2009-10-13 16:27:33 +01:00
Ramsay Jones
e45535849c Add test-suite coverage testing using gcov
Add a new "coverage" Makefile target that re-builds the
library and tests using the gcc compiler/linker flags
required by gcov, runs the test suite to capture the
runtime data, then compiles a coverage report.

The report, which is saved in a file named "untested",
consists of a list of untested files, followed by a list
of untested functions. More detailed execution statistics
are given in the gcov log files which are saved in the
top-level directory (named like src#hash.c.gcov).

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2009-10-13 16:26:05 +01:00
Ramsay Jones
d2ef83fcdc t0101-oid.c: Fix a memory leak reported by valgrind
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2009-10-13 16:25:26 +01:00
Ramsay Jones
cac5d927b5 Add support for running the tests via valgrind
Add some makefile targets, which use valgrind's memcheck tool to
run the tests, in order to help diagnose memory problems in the
library.

In addition, we enable the '--leak-check' option to report on any
memory leaks. However, unlike the other memory problems reported
by memcheck, memory leak reports do not result in an error exit
from valgrind. (So memory leaks are reported on stderr, but don't
halt the test run.)

A suppressions file (tests.supp) is included since libz triggers
some false positives.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2009-10-13 16:23:54 +01:00
Ramsay Jones
04e8824004 win32: Define the ssize_t type using SSIZE_T if supported
Some win32 compilers define the SSIZE_T type, with the same
meaning and intent as ssize_t. If available, make ssize_t a
synonym of SSIZE_T.

At present, the Digital-Mars compiler is known not to define
SSIZE_T, so we provide an SSIZE_T macro to use in the typedef.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2009-10-13 16:22:58 +01:00
Ramsay Jones
5cae6c2527 Disable some msvc "deprecated function" warnings again
In addition to removing the inline #define, commit 209849a also
removed a #pragma to disable msvc deprecated function warnings.
Without this #pragma, msvc currently issues 19 warnings related
to "deprecated insecure c-library functions", such as strcpy()
and 22 warnings related to "deprecated POSIX function names",
such as open().

In order to supress these warnings, re-instate the #pragma.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2009-10-13 16:22:18 +01:00
Julio Espinoza-Sokal
209849a449 Use GIT_INLINE macro instead of keyword inline.
No need to define inline as __inline because libgit2 code
should be using GIT_INLINE instead.

Signed-off-by: Julio Espinoza-Sokal <julioes@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2009-06-16 11:40:48 +02:00
Julio Espinoza-Sokal
73c4dd9253 Add noreturn declaration compatible with the MSVC compiler.
MSVC provides a compiler declaration to declare that a function
never returns. This declaration is required in front of the
function definition rather than at the end, but fortunately gcc
is compatible with this location as well.

Explicit returns are no longer required after calls to test_die.

Signed-off-by: Julio Espinoza-Sokal <julioes@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2009-06-16 11:40:14 +02:00
Ramsay Jones
c79dded300 win32: Add an fsync() implementation for windows
For information on FlushFileBuffers(), see the msdn document
at msdn.microsoft.com/en-us/library/aa364439(VS.85).aspx

Note that Windows 2000 is shown as the minimum windows version
to support FlushFileBuffers(), so if we wish to support Win9X
and NT4, we will need to add code to dynamically check if
kernel32.dll contains the function.

The only error return mentioned in the msdn document is
ERROR_INVALID_HANDLE, which is returned if the file/device
(eg console) is not buffered. The fsync(2) manpage says that
EINVAL is returned in errno, if "fd is bound to a special
file which does not support synchronization".

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2009-06-15 07:34:43 +02:00
Ramsay Jones
8a086f872a win32: Add support for the MS Visual C/C++ compiler
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2009-06-15 07:34:28 +02:00
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