Commit Graph

4488 Commits

Author SHA1 Message Date
Ramsay Jones
28f9832928 Fix inconsistent definition of off_t on Linux
In order to avoid inconsistent definitions of type off_t, all
compilation units should include the "common.h" header file
before certain system headers (those which directly or indirectly
lead to the definition of off_t). The "common.h" header contains
the definition of _FILE_OFFSET_BITS to select 64-bit file offsets.

The symptom of this inconsistency, while compiling with -Wextra, is
the following warning:

    In file included from src/common.h:50,
                     from src/commit.c:28:
    src/util.h: In function git__is_sizet:
    src/util.h:41: warning: comparison between signed and unsigned

In order to fix the problem, we simply remove the #include <time.h>
statement at the head of src/commit.c.  Note that src/commit.h also
includes <time.h>.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 11:18:56 +02:00
Ramsay Jones
c1b62b2ede Fix a "dereference of type-punned pointer" compiler warning
gcc (4.4.0) issues the following warning:

    src/revobject.c:33: warning: dereferencing type-punned pointer \
        will break strict-aliasing rules

We suppress the warning by copying the first 4 bytes from the oid
structure into an 'unsigned int' using memcpy(). This will also
fix any potential alignment issues on certain platforms.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 11:18:56 +02:00
Ramsay Jones
6e0fa05b58 Fix a doxygen warning
In particular, doxygen issues the following warning:

    .../src/git/revwalk.h:86: Warning: The following parameters of \
        gitrp_sorting(git_revpool *pool, unsigned int sort_mode) are \
        not documented:
          parameter 'pool'

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 11:18:56 +02:00
Ramsay Jones
84b9cec72c Fix sparse warnings: "symbol not declared. Should it be static?"
In particular, sparse issues the following warnings:

    src/revobject.c:29:14: warning: symbol 'max_load_factor' was \
        not declared. Should it be static?
    src/revobject.c:31:14: warning: symbol 'git_revpool_table__hash' was \
        not declared. Should it be static?

In order to suppress these warnings, we simply declare them as
static, since they are not (currently) referenced outside of this
file.

In the case of max_load_factor, this is probably correct. However,
this may not be appropriate for git_revpool_table__hash(), given
how it is named. So, this should either be re-named to reflect it's
non-external status, or a declaration needs to be added to the
revobject.h header file.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 11:18:55 +02:00
Ramsay Jones
ee1765e529 Fix sparse warnings: "Using plain integer as NULL pointer"
In order to suppress this warning, we could simply replace the
constant 0 with NULL. However, in this case, replacing the
comparison with 0 by !buffer is more idiomatic.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 11:18:55 +02:00
Ramsay Jones
468b12adb1 msvc: tests/t0403-lists.c: Fix a compiler warning
For more recent versions of msvc, the time_t type, as returned by
the time() function, is a 64-bit type. The srand() function, however,
expects an 'unsigned int' input parameter, leading to the warning.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 11:18:55 +02:00
Ramsay Jones
4e0d6d864d msvc: Fix an "conversion, loss of data" compiler warning
In particular, the compiler issues the following warning:

    src/revwalk.c(61) : warning C4244: '=' : conversion from \
        'unsigned int' to 'unsigned char', possible loss of data

In order to suppress the warning, we change the type of the
sorting "enum" field of the git_revpool structure to be consistent
with the sort_mode parameter of the gitrp_sorting() function.

Note that if the size of the git_revpool structure is an issue,
then we could change the type of the sort_mode parameter instead.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 11:18:55 +02:00
Ramsay Jones
5440906feb msvc: Fix some compiler warnings
In particular, the compiler issues the following warnings:

    src/revobject.c(29) : warning C4305: 'initializing' : truncation \
        from 'double' to 'const float'
    src/revobject.c(56) : warning C4244: '=' : conversion from \
        'const float' to 'unsigned int', possible loss of data
    src/revobject.c(149) : warning C4244: '=' : conversion from \
        'const float' to 'unsigned int', possible loss of data

In order to suppress the warnings we change the type of max_load_factor
to double, rather than change the initialiser to 0.65f, and cast the
result type of the expressions to 'unsigned int' as expected by the
assignment operators. Note that double should be able to represent all
unsigned int values without loss.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 11:18:55 +02:00
Ramsay Jones
8a7d625f53 Fix some "signed/unsigned comparison" compilation warnings
These warnings are issued by both gcc (-Wextra) and msvc (-W3).

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 11:18:55 +02:00
Ramsay Jones
5b7487bee6 Fix a memory corruption runtime error
On the msvc build, the tests t0401-parse and t0501-walk both
crash with a runtime error (ACCESS_VIOLATION). This is caused
by writing to un-allocated memory due to an under-allocation
of a git_revpool_table data structure.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 11:18:55 +02:00
Ramsay Jones
331578fb1d msvc: Fix a "declaration after statement" compilation error
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 11:18:55 +02:00
Vicent Marti
de141d4bb9 Improved error handling on auxilirary functions.
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:07 +02:00
Vicent Marti
c2550609e3 Use the first 4 bytes of an OID as hash, instead of full hashing.
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:07 +02:00
Vicent Marti
6bb7aa1318 Added new error codes. Improved error handling.
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:07 +02:00
Vicent Marti
0daa6cdcad Removed trailing whitespace.
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:07 +02:00
Vicent Marti
9b3577eda0 Fixed brace placement and converted spaces to tabs.
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:07 +02:00
Vicent Marti
0cf02ff92d Added t0501-walk (simple test for all revision pool walking modes)
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:07 +02:00
Vicent Marti
1d1be8ee22 Fixed topological commit sorting (no longerd reversed) and commit time
sorting ('prev' pointers in the linked list are no longer lost).

Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:07 +02:00
Vicent Marti
1f798df229 Fixed topological sorting stuck in infinite loop.
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:07 +02:00
Vicent Marti
69dca95950 Fixed parsing commit times (they weren't being stored at all!)
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:07 +02:00
Vicent Marti
82b1db3b35 Changed commit time sorting to be descending (from newest to oldest).
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:07 +02:00
Vicent Marti
e5d1faefab Add external API for revision sorting.
The GIT_RPSORT_XXX flags have been moved to the external API,
and a new method 'gitrp_sorting(...)' has been added to safely
change the sorting method of a revision pool.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:07 +02:00
Vicent Marti
9bdb759471 Properly reset all commit properties when doing a gitrp_reset().
Add git_revpool_table_free() method.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:07 +02:00
Vicent Marti
655d381a19 Add topological sorting and new insertion methods for commit lists.
'git_commit_list_toposort()' and 'git_commit_list_timesort()' now
sort a commit list by topological and time order respectively.
Both sorts are stable and in place.

'git_commit_list_append' has been replaced by 'git_commit_list_push_back'
and 'git_commit_list_push_front'.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:07 +02:00
Vicent Marti
47c31f584e Fixed linked list tail being lost when sorting.
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:07 +02:00
Vicent Marti
a7c182c594 Add object cache to the revision pool.
Fixed issue when generating pending commits list during iteration.

The 'git_commit_lookup' function will now check the pool's cache
for commits which have been previously loaded/parsed; there can only
be a single 'git_commit' structure for each commit on the same pool.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:07 +02:00
Vicent Marti
d047b47aad Updated t0401 (commit parsing) to reflect the new API changes.
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:07 +02:00
Vicent Marti
089c2d931b Add unit tests for list sorting.
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:07 +02:00
Vicent Marti
b60488e1d7 Added sort method for commit lists.
Fixed bug when parsing time headers from commits.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:06 +02:00
Vicent Marti
5e15176dac Add commit caching on the commit table.
Properly initialize the pending commits list.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:06 +02:00
Vicent Marti
c5696427b6 Add 'git_revpool_object' and 'git_revpool_table' structures.
All the objects which will will be eventually transversable from
a revision pool (commits, trees, etc) now inherit from the
'git_revpool_object' structure which identifies them with their
own OID.

Furthermore, the 'git_revpool_table' and related functions have
been added, which allow for constant time lookup (hash table)
of the loaded revpool objects based on their OID.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:06 +02:00
Vicent Marti
36b7cdb6a1 Changed 'git_commit_list' from a linked list to a doubly-linked list.
Changed 'git_commit' to use bit fields instead of flags.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:06 +02:00
Vicent Marti
8903968265 Removed 'git_commit_uninteresting' from the public API.
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:06 +02:00
Vicent Marti
1a895dd787 Add arbritrary ordering revision walking.
The 'gitrp_next()' method now correctly does a revision walking
of all the pushed revisions in arbritary ordering.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:06 +02:00
Vicent Marti
8add015392 Split git_commit_lookup into separate functions.
git_commit_lookup() now creates commit references
without loading them from the ODB.

git_commit_parse() creates a commit reference, loads
it and parses it from the ODB.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:06 +02:00
Vicent Marti
08d5d00056 Add commit parents to parsed commits and commit lists to the revpool.
Basic support for iterating the revpool.

The following functions of the revwalk API have been partially
implemented:

    void gitrp_reset(git_revpool *pool);
    void gitrp_push(git_revpool *pool, git_commit *commit);
    void gitrp_prepare_walk(git_revpool *pool);
    git_commit *gitrp_next(git_revpool *pool);

Parsed commits' parents are now also parsed and stored in a
"git_commit_list" structure (linked list).

Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:06 +02:00
Vicent Marti
42281e007e Add unit tests for Commit parsing
A few initial tests for commit parsing:

    "parse_buffer_test" tests git_commit__parse_buffer() with
    several malformed commit messages and a few corner cases
    which should pass.

    "parse_oid_test" tests git_commit__parse_oid() with several
    malformed commit lines containing broken SHA1 OIDs.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:06 +02:00
Vicent Marti
4caa8962a6 Fixed indentation issues in commit.c
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:06 +02:00
Vicent Marti
417f0abc9b Add basic functionality for commit lookup/parsing
The external API function "git_commit_parse" has been renamed
to "git_commit_lookup" and has been partially implemented with
support for loading commits straight from the ODB. It still lacks
the functionality to lookup cached commits in the revpool and to
resolve tags to commits.

The following internal functions have been partially implemented:

int git_commit__parse_buffer(...);
int git_commit__parse_time(...);
int git_commit__parse_oid(...);

Commits are now fully parsed but the generated parent and tree
references are not handled yet.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:06 +02:00
Vicent Marti
1bb1185935 Fixed typos in the revwalk API documentation
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2010-06-02 10:32:06 +02:00
Ramsay Jones
38c513b9d1 Add support to enable the library to use OpenSSL SHA1 functions
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-05-04 21:36:12 +02:00
Ramsay Jones
89217d8f1a Add functions to open a '*.pack' file and perform some basic validation
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-04-30 09:48:07 +02:00
Ramsay Jones
3cc606359d Add some more (macro) file operation wrappers
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-04-30 09:47:58 +02:00
Ramsay Jones
54b9460fee Fix the memory leak caused by failing to free the 'offset index'
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-04-30 09:47:53 +02:00
Ramsay Jones
19d13c65e1 Makefile(s): Don't include the OpenSSL crypto library in the link
Also, fully purge the NO_OPENSSL build variable.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-04-28 20:58:24 +01:00
Ramsay Jones
f019bd17a1 Makefile: 'make clean' wipe all editor backup files in src/*/
In a similar way to commit 9b17380 ("Make 'make clean' wipe all
object files in src/*/", 2010-04-14), we use a shell glob when
removing editor backup files.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-04-28 20:57:54 +01:00
Ramsay Jones
44debd80c4 Makefile: Add source for the built-in SHA1 routines to $(SRC_C)
This results in the 'sparse' and 'coverage' targets including the
C source files for the built-in SHA1 routines. In addition to the
sparse check, this results in the generation of the '.gcov' file
and inclusion in the test coverage report.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-04-28 20:57:03 +01:00
Ramsay Jones
70aab459aa win32: Remove wsock32 from the list of libraries to link
Commit 5dddf7c (Add block-sha1 in favour of the mozilla routines
2010-04-14) introduced the "bswap.h" header file which, for x86
or x86-64 machines, provides a "sane" implementation of ntohl()
and htonl().

The wsock32 library, on the msvc and MinGW build, is only included
in the link to supply the ntohl()/htonl() routines.  Since we now
have a built-in implementation, we can remove the wsock32 library
from the link.

[This will break a Windows build on a non-intel machine]

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-04-28 20:56:19 +01:00
Ramsay Jones
e272b10388 MSVC: Fix some compiler warnings
In particular, using the normal (or production) compiler
warning level (-W3), msvc complains as follows:

.../sha1.c(244) : warning C4018: '<' : signed/unsigned mismatch
.../sha1.c(270) : warning C4244: 'function' : conversion from \
   'unsigned __int64' to 'unsigned long', possible loss of data
.../sha1.c(271) : warning C4244: 'function' : conversion from \
   'unsigned __int64' to 'unsigned long', possible loss of data

Note that gcc issues a similar complaint about line 244 when
compiling with -Wextra.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-04-28 20:55:56 +01:00
Ramsay Jones
e2337f39c3 MSVC: Fix a syntax error caused by an inline function definition
Commit 5dddf7c (Add block-sha1 in favour of the mozilla routines
2010-04-14) introduced the "bswap.h" header file which contains
an inline function (default_swab32()).  The msvc compiler does
not support the inline keyword which causes the build to fail
with a syntax error.

However, msvc does support inline functions using the __inline
keyword language extension.  We already have the GIT_INLINE()
macro that allows us to hide this syntatic difference. In order
to fix the build, we simply use GIT_INLINE() in the definition
of the default_swab32() function.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-04-28 20:55:04 +01:00