Commit Graph

307 Commits

Author SHA1 Message Date
Vicent Marti
9f54fe482d Remove git_errno
It was not being used by any methods (only by malloc and calloc), and
since it needs to be TLS, it cannot be exported on DLLs on Windows.

Burn it with fire. The API always returns error codes!

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-12-23 00:15:09 +02:00
Vicent Marti
638c2ca428 Rename 'git_person' to 'git_signature'
The new signature struct is public, and contains information about the
timezone offset. Must be free'd manually by the user.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-12-18 02:35:33 +02:00
Vicent Marti
5cccfa8999 Merge branch 'timezone-offset' of https://github.com/nulltoken/libgit2 into timezone 2010-12-12 00:33:57 +02:00
Peter Drahos
5b8bb8e7c6 Minor modifications for MinGW/Cygwin compatibility. 2010-12-12 00:20:31 +02:00
nulltoken
b76d984e0b Added more person parsing tests. 2010-12-11 16:20:57 +01:00
nulltoken
5a386e4d0a Added timezone checks to person parsing tests. 2010-12-11 15:50:07 +01:00
nulltoken
7161beb11e Fixed too much faked timezone offset.
An offset of more than 14 hours makes no sense (cf. http://www.worldtimezone.com/faq.html).
2010-12-11 15:38:22 +01:00
nulltoken
13710f1e86 Added timezone offset parsing and outputting. 2010-12-10 16:30:06 +01:00
Vicent Marti
2cd6d6866e Tests now run with the resources folder as a hardcoded path
Each tests expects a "TEST_RESOURCES" define with the full path to the
resources folder.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-12-10 05:53:39 +02:00
Vicent Marti
a44fc1d413 Fix type-conversion warnings
The types in the git_index_entry struct are now system-defaults, and get
truncated to uint32_t's when written back on the index.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-12-06 23:36:21 +02:00
Vicent Marti
44908fe763 Change the library include file
Libgit2 is now officially include as

	#include "<git2.h>"

or indidividual files may be included as

	#include <git2/index.h>

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-12-06 23:03:16 +02:00
Vicent Marti
d12299fe22 Change include structure for the project
The maze with include dependencies has been fixed.
There is now a global include:

	#include <git.h>

The git_odb_backend API has been exposed.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-12-06 01:14:15 +02:00
Vicent Marti
7d7cd8857a Decouple storage from ODB logic
Comes with two default backends: loose object and packfiles.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-12-06 01:14:15 +02:00
Vicent Marti
654cd5ff7b Fix segfault in t0603 (unitialized pointer)
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-12-02 21:50:28 +02:00
Vicent Marti
599955586d Fix segfault handler in Mac OS X
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-12-02 21:48:03 +02:00
Vicent Marti
eec9523513 Commit parents now use the common 'vector' code
No more linked lists, no more O(n) access.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-12-02 04:58:22 +02:00
Vicent Marti
41109a7e7e Merge branch 'commitparents' of https://github.com/JustinLove/libgit2 into JustinLove-commitparents 2010-12-02 04:42:33 +02:00
Vicent Marti
c4034e63f3 Refactor all 'vector' functions into common code
All the operations on the 'git_index_entry' array and the
'git_tree_entry' array have been refactored into common code in the
src/vector.c file.

The new vector methods support:
	- insertion:	O(1) (avg)
	- deletion:		O(n)
	- searching:	O(logn)
	- sorting:		O(logn)
	- r. access:	O(1)

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-12-02 04:31:54 +02:00
Vicent Marti
1e35f929ef Add stack trace to the tests when building with GCC
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-12-02 04:19:14 +02:00
Justin Love
eb095435f3 add git_commit_parent to retrieve a parent by index 2010-11-30 21:28:39 -06:00
Justin Love
12114415ab add git_commit_parentcount 2010-11-30 21:27:12 -06:00
Vicent Marti
277e45f486 Remove the Makefile from the tests/ folder too
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-11-24 00:23:15 +02:00
Vicent Marti
6b1eab3976 Fix MSVC warnings and errors
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-11-24 00:23:15 +02:00
Vicent Marti
d7c7cab8a4 Fix memory leak in t0401
Commit object must be internally free'd after each parse attempt, even
it fails.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-11-16 03:25:26 +02:00
Vicent Marti
c3a20d5cab Add support for 'index add'
Actually add files to the index by creating their corresponding blob and
storing it on the repository, then getting the hash and updating the
index file.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-11-16 02:59:28 +02:00
Colin Timmermans
1081d90945 Fix parsing of commits that have no newlines in the message. 2010-11-07 01:31:28 +02:00
Dave Borowitz
88d035bd15 Update commit_time along with committer. 2010-11-05 03:55:14 +02:00
Dave Borowitz
f24fa0880c Test that commit attributes are set correctly. 2010-11-05 03:55:14 +02:00
Vicent Marti
a8bfce69dc Add string descriptions for all error codes
Old descriptions have been updated and new ones have been added for the
'git_strerror' function.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-11-05 03:55:04 +02:00
Vicent Marti
1795f87952 Improve error handling
All initialization functions now return error codes instead of pointers.
Error codes are now properly propagated on most functions. Several new
and more specific error codes have been added in common.h

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-11-05 03:20:17 +02:00
Vicent Marti
6fd195d76c Change git_repository initialization to use a path
The constructor to git_repository is now called

	'git_repository_open(path)'

and takes a path to a git repository instead of an existing ODB object.
Unit tests have been updated accordingly and the two test repositories
have been merged into one.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-11-02 18:42:42 +02:00
Vicent Marti
aaf68dc443 Add unit tests for git_odb_read_header
Test the new method by loading all the objects in the sample ODB with a
full-read and a header-only read, and comparing the types and sizes.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-10-29 00:47:53 +03:00
Vicent Marti
585190183b Fix internal memory management on the library
String mememory is now managed in a much more sane manner.

Fixes include:

	- git_person email and name is no longer limited to 64 characters
	- git_tree_entry filename is no longer limited to 255 characters
	- raw objects are properly opened & closed the minimum amount of
	times required for parsing
	- unit tests no longer leak
	- removed 5 other misc memory leaks as reported by Valgrind
	- tree writeback no longer segfaults on rare ocassions

The git_person struct is no longer public. It is now managed by the
library, and getter methods are in place to access its internal
attributes.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-10-28 02:07:18 +03:00
Ramsay Jones
2d16373cb8 msvc: Fix an "conversion, possible loss of data" warning
In particular, msvc complains thus:

    t0603-sort.c(23) : warning C4244: 'function' : conversion from \
        'time_t' to 'unsigned int', possible loss of data

Note that msvc, by default, defines time_t as a 64-bit type, whereas
srand() is expecting an (32-bit) unsigned int. In order to suppress
the warning, we simply cast the return value of the time() function
call to 'unsigned int'.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-10-27 00:59:09 +03:00
Vicent Marti
e4def81aab Fix issue 3 (memory corruption resize_tree_array)
The tree array wasn't being initialized when instantiating a tree object
in memory instead of loading it from disk.

New unit tests added to check for the problem.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-10-08 13:52:17 +03:00
Vicent Marti
0ba7a03186 Add unit tests for object write-back
Basic write-back & in-memory editing for objects is now tested in t0403
(commits), t0802 (tags) and t0902 (trees).

Add new helper functions in test_helpers.c to remove the loose objects
created when doing write-back tests.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-10-07 00:42:55 +03:00
Vicent Marti
c4b5bedc97 Fix possible segfaults in src/tree.c (issue 1)
git_tree_entry_byname was dereferencing a NULL pointer when the searched
file couldn't be found on the tree.

New test cases have been added to check for entry access methods.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-10-07 00:14:09 +03:00
Vicent Marti
2a884588b4 Add write-back support for git_tree
All the setter methods for git_tree have been added, including the
setters for attributes on each git_tree_entry and methods to add/remove
entries of the tree.

Modified trees and trees created in-memory from scratch can be written
back to the repository using git_object_write().

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-09-21 17:17:10 +03:00
Vicent Marti
0c3596f18a Add setter methods & write support for git_commit
All the required git_commit_set_XXX methods have been implemented; all
the attributes of a commit object can now be modified in-memory.

The new method git_object_write() automatically writes back the
in-memory changes of any object to the repository. So far it only
supports git_commit objects.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-09-20 02:04:06 +03:00
Vicent Marti
f49a2e4981 Give object structures more descriptive names
The 'git_obj' structure is now called 'git_rawobj', since
it represents a raw object read from the ODB.

The 'git_repository_object' structure is now called 'git_object',
since it's the base object class for all objects.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-09-19 03:21:06 +03:00
Vicent Marti
003c269094 Finish the tree object API
The interface for loading and parsing tree objects from a repository has
been completed with all the required accesor methods for attributes,
support for manipulating individual tree entries and a new unit test
t0901-readtree which tries to load and parse a tree object from a
repository.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-08-12 18:49:04 +02:00
Vicent Marti
ff17642dc2 Add unit tests for index manipulation
Three new unit tests, t06XX files have been added.

	t0601-read: tests for loading index files from disk,
				for creating in-memory indexes and for accessing
				index entries.
	t0602-write: tests for writing index files back to disk
	t0603-sort: tests for properly sorting the entries array of an index

Two test indexes have been added in 'tests/resources/':

	test/resources/index: a sample index from a libgit2 repository

	test/resources/gitgit.index: a sample index from a git.git
		repository (includes TREE extension data)

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-08-12 18:49:04 +02:00
Vicent Marti
1baa25ee9b Move test resources to a common directory
All the external resources used by the tests are now placed inside the
common 'tests/resources' directory.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-08-12 18:49:04 +02:00
Vicent Marti
3315782cb4 Redesigned the walking/object lookup interface
The old 'git_revpool' object has been removed and
split into two distinct objects with separate
functionality, in order to have separate methods for
object management and object walking.

*	A new object 'git_repository' does the high-level
	management of a repository's objects (commits, trees,
	tags, etc) on top of a 'git_odb'.

	Eventually, it will also manage other repository
	attributes (e.g. tag resolution, references, etc).

	See: src/git/repository.h

*	A new external method
		'git_repository_lookup(repo, oid, type)'
	has been added to the 'git_repository' API.

	All object lookups (git_XXX_lookup()) are now
	wrappers to this method, and duplicated code
	has been removed. The method does automatic type
	checking and returns a generic 'git_revpool_object'
	that can be cast to any specific object.

	See: src/git/repository.h

*	The external methods for object parsing of repository
	objects (git_XXX_parse()) have been removed.

	Loading objects from the repository is now managed
	through the 'lookup' functions. These objects are
	loaded with minimal information, and the relevant
	parsing is done automatically when the user requests
	any of the parsed attributes through accessor methods.

	An attribute has been added to 'git_repository' in
	order to force the parsing of all the repository objects
	immediately after lookup.

	See: src/git/commit.h
	See: src/git/tag.h
	See: src/git/tree.h

*	The previous walking functionality of the revpool
	is now found in 'git_revwalk', which does the actual
	revision walking on a repository; the attributes
	when walking through commits in a database have been
	decoupled from the actual commit objects.
	This increases performance when accessing commits
	during the walk and allows to have several
	'git_revwalk' instances working at the same time on
	top of the same repository, without having to load
	commits in memory several times.

	See: src/git/revwalk.h

*	The old 'git_revpool_table' has been renamed to
	'git_hashtable' and now works as a generic hashtable
	with support for any kind of object and custom hash
	functions.

	See: src/hashtable.h

*	All the relevant unit tests have been updated, renamed
	and grouped accordingly.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-08-12 18:48:55 +02:00
Vicent Marti
f875804487 Add loading and parsing of tag objects
Tag objects are now properly loaded from the revision pool.
New test t0801 checks for loading a parsing a series of tags, including
the tag of a tag.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-08-12 04:40:43 +02:00
Vicent Marti
364788e1d1 Refactor parsing methods
The 'parse_oid' and 'parse_person' methods which were used by the commit
parser are now global so they can be used when parsing other objects.

The 'git_commit_person' struct has been changed to a generic
'git_person'.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-08-07 00:59:58 +02:00
Vicent Marti
7e4f56a5bb Add packfile reading
Packed objects inside packfiles are now properly unpacked when calling
the git_odb__read_packed() method; delta'ed objects are also properly
generated when needed.

A new unit test 0204-readpack tries to read a couple hundred packed
objects from a standard packed repository.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-08-06 18:37:59 +02:00
Vicent Marti
3e590fb222 Changed test files to use tabs instead of spaces
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-07-15 23:41:31 +02:00
Vicent Marti
52f2390b43 Add external API to access detailed commit attributes
The following new external methods have been added:

GIT_EXTERN(const char *) git_commit_message_short(git_commit *commit);
GIT_EXTERN(const char *) git_commit_message(git_commit *commit);
GIT_EXTERN(time_t) git_commit_time(git_commit *commit);
GIT_EXTERN(const git_commit_person *) git_commit_committer(git_commit *commit);
GIT_EXTERN(const git_commit_person *) git_commit_author(git_commit *commit);
GIT_EXTERN(const git_tree *) git_commit_tree(git_commit *commit);

A new structure, git_commit_person has been added to represent a
commit's author or committer.

The parsing of a commit has been split in two phases.
When adding a commit to the revision pool:
	- the commit's ODB object is opened
	- its raw contents are parsed for commit TIME, PARENTS and TREE
		(the minimal amount of data required to traverse the pool)
	- the commit's ODB object is closed

When querying for extended information on a commit:
	- the commit's ODB object is reopened
	- its raw contents are parsed for the requested information
	- the commit's ODB object remains open to handle additional queries

New unit tests have been added for the new functionality:

	In t0401-parse: parse_person_test
	In t0402-details: query_details_test

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-07-15 23:40:52 +02:00
Vicent Marti
b231ef3acd Add new tests: t0502-table, t0503-tableit
"t0502-table" tests for basic functionality of the objects
table:
	table_create	(creating a new object table)
	table_populate	(fill & lookup on the object table)
	table_resize	(dynamically resize the table)

"t0503-tableit" tests the iterator for object tables:
	table_iterator (make sure the iterator reaches all objects)

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-07-15 23:37:05 +02:00
Vicent Marti
088a731f00 Fixed memory leaks in test suite
Created commit objects in t0401-parse weren't being freed properly.
Updated the API documentation to note that commit objects are owned
by the revision pool and should not be freed manually.

The parents list of each commit was being freed twice after each test.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-07-10 12:15:12 -07:00
Ramsay Jones
ca3939e682 msvc: Disable a level 4 warning and change -W3 to -W4
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-06-07 19:46:17 +01:00
Ramsay Jones
0aaf8708b0 Makefile(s): Add -Wextra to CFLAGS
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-06-07 19:45:57 +01:00
Ramsay Jones
552e23ba56 Fix a bug in the git_oid_to_string() function
When git_oid_to_string() was passed a buffer size larger than
GIT_OID_HEXSZ+1, the function placed the c-string NUL char at
the wrong position. Fix the code to place the NUL at the end
of the (possibly truncated) oid string.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-06-07 19:44:04 +01:00
Ramsay Jones
f29249340c Style: Do not use (C99) // comments
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
b2bc567f25 Style: Fix brace placement and spacing
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Shawn O. Pearce
028ef0de72 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>
2008-12-31 13:36:55 -08:00
Shawn O. Pearce
4260699b37 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>
2008-12-31 11:16:41 -08:00
Shawn O. Pearce
a1d34bc000 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>
2008-12-30 21:56:11 -08:00
Ramsay Jones
c960d6a3f9 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>
2008-12-30 07:52:55 -08:00
Ramsay Jones
007e075337 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>
2008-12-30 07:48:10 -08:00
Ramsay Jones
3d3552e8fd Implement git_odb__read_loose()
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-12-19 07:23:00 -08:00
Ramsay Jones
7b6e8067ec 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>
2008-12-10 11:49:06 -08:00
Shawn O. Pearce
af795e498d 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>
2008-12-02 10:02:29 -08:00
Shawn O. Pearce
b7c891c629 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>
2008-11-03 18:43:04 -08:00
Shawn O. Pearce
367ab010d6 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>
2008-11-03 18:43:04 -08:00
Shawn O. Pearce
b81dd80e8c 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>
2008-11-03 18:42:54 -08:00
Shawn O. Pearce
b923f2f97d Fix Makefile to correctly handle 'make -j4 test'
If we have more than one test build running we cannot use the same
file for each test case; instead we need to use a per-test path so
there aren't any collisions.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-11-03 18:42:54 -08:00
Shawn O. Pearce
fbbfdf9f13 Move GIT_NORETURN into test_lib.h only
We should never have a noreturn style function in the library
itself, as such a function would prevent the calling application
from handling error conditions the way it wants.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-11-03 18:42:54 -08:00
Shawn O. Pearce
15bffce9f7 Create a basic test suite for the library and test oid functions
This is a horribly simple test suite that makes it fairly easy to
put together some basic function level unit tests on the library.
Its patterned somewhat after the test suite in git.git, but also
after the "Check" test library.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-11-01 18:24:39 -07:00