Commit Graph

307 Commits

Author SHA1 Message Date
Vicent Marti
0ad6efa110 Build & write custom trees in memory 2011-04-04 19:25:33 +03:00
Carlos Martín Nieto
511b2370d9 tests: update NAMING file
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-04-04 17:24:37 +02:00
Carlos Martín Nieto
8cd767ef52 config: test for a variable on its own
If a variable is on its own, truth should be assumed. Check this is
true in our code.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-04-04 17:07:47 +02:00
Carlos Martín Nieto
0bf8ca8820 config: add tests
These tests are basic, but they should tell us when we've broken
something.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-04-04 16:44:23 +02:00
nulltoken
f3564e1e29 Fix tag reference name in testrepo.git
The git test repository was holding a wrongly named tag reference ("very-simple") pointing at a tag named "e90810b".
This mistake (mine :-/ ) originates back to https://github.com/libgit2/libgit2/commit/9282e92

Whole credit goes to @tclem for having spotted this.
2011-04-04 13:12:23 +03:00
Vicent Marti
3e3e4631a0 Merge branch 'tagging' of https://github.com/nulltoken/libgit2 into development
Conflicts:
	include/git2/tag.h
	src/tag.c
2011-04-02 12:50:25 +03:00
Vicent Marti
720d5472f8 Change parse methods to const buffer
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-04-02 12:42:04 +03:00
nulltoken
9e680bcc00 Add git_tag_delete() 2011-03-30 23:26:36 +02:00
nulltoken
a50c145855 Add git_tag_create_o_f() and git_tag_create_f() which overwrite existing tag reference, if any 2011-03-30 23:16:30 +02:00
nulltoken
74e50a2d3e Fix memory leak in tag releated tests 2011-03-30 22:46:52 +02:00
nulltoken
bf4c39f929 Prevent tag_create() from creating a conflicting reference 2011-03-30 22:30:55 +02:00
nulltoken
6d3160148b Add test demonstrating that one can create a tag pointing at a non existent target 2011-03-30 22:26:53 +02:00
nulltoken
8e9a3d4217 Enforce the testing of the correct creation of a tag 2011-03-30 21:46:19 +02:00
nulltoken
673de2cf59 Fix misleading comments 2011-03-30 21:29:10 +02:00
nulltoken
2b9b99b6ed Add test ensuring one can not create an oid reference which targets at an unknown id 2011-03-29 21:29:30 +02:00
nulltoken
4d00dfd438 Replace gitfo_unlink() calls with git_reference_delete() in refs related tests 2011-03-29 21:21:47 +02:00
Carlos Martín Nieto
553fbd640f Check for looser reference names
res/dummy/a and refs/stash must pass. The other rules are already
tested by the rest of the checks.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-29 19:58:19 +03:00
Vicent Marti
95cde17ca4 Enforce coding conventions in refs.c
Internal methods are static and without the git prefix.
'Force' methods have a `_f` prefix to match the other 'force' methods.
2011-03-29 19:58:19 +03:00
Carlos Martín Nieto
fc1eeb9dfc Make overwrite test more comprehensive
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-29 19:58:19 +03:00
Carlos Martín Nieto
ec99193655 force-rename test: check for the right name
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-29 19:58:19 +03:00
Carlos Martín Nieto
591a9423f5 Add tests covering overwriting references
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-29 19:58:18 +03:00
Vicent Marti
483526ebec Update the SQLite backend 2011-03-28 22:23:44 +03:00
nulltoken
a8375f5322 Add test exercising the opening of an standard repository initialized by git 2011-03-23 00:25:05 +02:00
nulltoken
2ce44b67f3 Add test exercising the opening of an empty bare repository initialized by git 2011-03-23 00:25:04 +02:00
nulltoken
29e1797c14 Add remove_placeholders() test helper function which recursively removes marker files from a directory structure 2011-03-23 00:25:04 +02:00
Vicent Marti
3fe9c60c6a Add empty bare and normal repos to test resources
We have removed the hooks folder because it takes a lot of space
2011-03-23 00:25:04 +02:00
nulltoken
f428ae615b Slightly enforce copy_recurs() behavior
The folder creation is now decorrelated from the recursive parsing of the source tree structure.
2011-03-23 00:25:04 +02:00
nulltoken
ba1bdf86e7 Improve test coverage of new path prettifying behavior 2011-03-23 00:24:51 +02:00
nulltoken
3644e98fd9 Fix detection of attempt to escape the root directory on Windows 2011-03-23 00:17:25 +02:00
nulltoken
c90292ce4f Change gitfo_prettify_dir_path() and gitfo_prettify_file_path() behavior
Those functions now return prettified rooted path.
2011-03-23 00:17:24 +02:00
nulltoken
677a3c07f4 Add failing test for issue 84
see https://github.com/libgit2/libgit2/issues#issue/84
2011-03-23 00:17:24 +02:00
nulltoken
56d8ca266c Switch from time_t to git_time_t
git_time_t is defined as a signed 64 integer. This allows a true predictable multiplatform behavior.
2011-03-23 00:07:58 +02:00
Vicent Marti
99baacfb56 Fix MSVC warnings 2011-03-21 19:27:45 +02:00
Vicent Marti
72a3fe42fb I broke your bindings
Hey. Apologies in advance -- I broke your bindings.

This is a major commit that includes a long-overdue redesign of the
whole object-database structure. This is expected to be the last major
external API redesign of the library until the first non-alpha release.

Please get your bindings up to date with these changes. They will be
included in the next minor release. Sorry again!

Major features include:

	- Real caching and refcounting on parsed objects
	- Real caching and refcounting on objects read from the ODB
	- Streaming writes & reads from the ODB
	- Single-method writes for all object types
	- The external API is now partially thread-safe

The speed increases are significant in all aspects, specially when
reading an object several times from the ODB (revwalking) and when
writing big objects to the ODB.

Here's a full changelog for the external API:

blob.h
------

	- Remove `git_blob_new`
	- Remove `git_blob_set_rawcontent`
	- Remove `git_blob_set_rawcontent_fromfile`
	- Rename `git_blob_writefile` -> `git_blob_create_fromfile`
	- Change `git_blob_create_fromfile`:
		The `path` argument is now relative to the repository's working dir
	- Add `git_blob_create_frombuffer`

commit.h
--------

	- Remove `git_commit_new`
	- Remove `git_commit_add_parent`
	- Remove `git_commit_set_message`
	- Remove `git_commit_set_committer`
	- Remove `git_commit_set_author`
	- Remove `git_commit_set_tree`

	- Add `git_commit_create`
	- Add `git_commit_create_v`
	- Add `git_commit_create_o`
	- Add `git_commit_create_ov`

tag.h
-----

	- Remove `git_tag_new`
	- Remove `git_tag_set_target`
	- Remove `git_tag_set_name`
	- Remove `git_tag_set_tagger`
	- Remove `git_tag_set_message`

	- Add `git_tag_create`
	- Add `git_tag_create_o`

tree.h
------

	- Change `git_tree_entry_2object`:
		New signature is `(git_object **object_out, git_repository *repo, git_tree_entry *entry)`

	- Remove `git_tree_new`
	- Remove `git_tree_add_entry`
	- Remove `git_tree_remove_entry_byindex`
	- Remove `git_tree_remove_entry_byname`
	- Remove `git_tree_clearentries`
	- Remove `git_tree_entry_set_id`
	- Remove `git_tree_entry_set_name`
	- Remove `git_tree_entry_set_attributes`

object.h
------------

	- Remove `git_object_new
	- Remove `git_object_write`

	- Change `git_object_close`:
		This method is now *mandatory*. Not closing an object causes a
		memory leak.

odb.h
-----

	- Remove type `git_rawobj`
	- Remove `git_rawobj_close`
	- Rename `git_rawobj_hash` -> `git_odb_hash`
	- Change `git_odb_hash`:
		New signature is `(git_oid *id, const void *data, size_t len, git_otype type)`

	- Add type `git_odb_object`
	- Add `git_odb_object_close`

	- Change `git_odb_read`:
		New signature is `(git_odb_object **out, git_odb *db, const git_oid *id)`
	- Change `git_odb_read_header`:
		New signature is `(size_t *len_p, git_otype *type_p, git_odb *db, const git_oid *id)`
	- Remove `git_odb_write`
	- Add `git_odb_open_wstream`
	- Add `git_odb_open_rstream`

odb_backend.h
-------------

	- Change type `git_odb_backend`:
		New internal signatures are as follows

			int (* read)(void **, size_t *, git_otype *, struct git_odb_backend *, const git_oid *)
			int (* read_header)(size_t *, git_otype *, struct git_odb_backend *, const git_oid *)
			int (* writestream)(struct git_odb_stream **, struct git_odb_backend *, size_t, git_otype)
			int (* readstream)( struct git_odb_stream **, struct git_odb_backend *, const git_oid *)

	- Add type `git_odb_stream`
	- Add enum `git_odb_streammode`

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-03-20 21:45:11 +02:00
Vicent Marti
bb3de0c472 Thread safe cache 2011-03-20 21:45:06 +02:00
Vicent Marti
b5c5f0f808 Fix headers for the new Revision Walker
The "oid.h" header is now included instead of "object.h".

The old "revwalk.h" header has been removed; it was empty.
2011-03-16 23:59:09 +02:00
Vicent Marti
36aaf1ff1a Change the Revwalk reset behavior to the old version
The `reset` call now removes the pushed commits so we can reuse
the revwalker. The API documentation has been updated with the details.
2011-03-16 01:53:25 +02:00
Vicent Marti
bbcc7ffc69 Add proper threading support to libgit2
We now depend on libpthread on all Unix platforms (should be installed
by default) and use a simple wrapper for Windows threads under Win32.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-03-15 21:14:07 +02:00
Vicent Marti
b5abb881a6 Do not segfault when listing unpacked references 2011-03-15 19:55:01 +02:00
Vicent Marti
7ad96e51ca Remove duplicate refs in git_reference_listall 2011-03-15 05:38:50 +02:00
Ben Noordhuis
1ee32c6dd9 Add test case for issue GH-86 2011-03-15 02:56:32 +02:00
Vicent Marti
6b2a19418c Fix the retarded object interdependency system
It's no longer retarded. All object interdependencies are stored as OIDs
instead of actual objects. This should be hundreds of times faster,
specially on big repositories. Heck, who knows, maye it doesn't even
segfault -- wouldn't that be awesome?

What has changed on the API?

	`git_commit_parent`, `git_commit_tree`, `git_tag_target` now return
	their values through a pointer-to-pointer, and have an error code.

	`git_commit_set_tree` and `git_tag_set_target` now return an error
	code and may fail.

	`git_repository_free__no_gc` has been deprecated because it's
	stupid. Since there are no longer any interdependencies between
	objects, we don't need internal reference counting, and GC
	never fails or double-free's pointers.

	`git_object_close` now does a very sane thing: marks an object
	as unused. Closed objects will be eventually free'd from the
	object cache based on LRU. Please use `git_object_close` from
	the garbage collector `destroy` method on your bindings. It's
	100% safe.

	`git_repository_gc` is a new method that forces a garbage collector
	pass through the repo, to free as many LRU objects as possible.
	This is useful if we are running out of memory.
2011-03-14 23:52:32 +02:00
Vicent Marti
0057182807 Add new method git_reference_listall
Lists all the references in a repository. Listing may be filtered by
reference type.

This should applease Lord Clem.
2011-03-14 23:52:32 +02:00
Vicent Marti
71db842fac Rewrite the Revision Walker
The new revision walker uses an internal Commit object storage system,
custom memory allocator and much improved topological and time sorting
algorithms. It's about 20x times faster than the previous implementation
when browsing big repositories.

The following external API calls have changed:

	`git_revwalk_next` returns an OID instead of a full commit object.
	The initial call to `git_revwalk_next` is no longer blocking when
	iterating through a repo with a time-sorting mode.

	Iterating with Topological or inverted modes still makes the initial
	call blocking to preprocess the commit list, but this block should be
	mostly unnoticeable on most repositories (topological preprocessing
	times at 0.3s on the git.git repo).

	`git_revwalk_push` and `git_revwalk_hide` now take an OID instead
	of a full commit object.
2011-03-14 23:52:15 +02:00
Vicent Marti
26022f0719 Add git_oid_shorten (unique OID minimzer)
Set of methods to find the minimal-length to uniquely identify every OID
in a list. Useful for GUI applications, commit logs and so on.

Includes stress test.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-03-14 23:36:10 +02:00
Tim Clem
45314a7e4a clean up temp repo for t12-repo tests
add actual must_pass calls back into the repo tests and remove ./ from
beginning of temp repo path
2011-03-04 23:31:28 -08:00
Vicent Marti
48c27f86bb Implement reference counting for git_objects
All `git_object` instances looked up from the repository are reference
counted. User is expected to use the new `git_object_close` when an
object is no longer needed to force freeing it.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-03-03 20:23:52 +02:00
Vicent Marti
86d7e1ca6f Fix searching in git_vector
We now store only one sorting callback that does entry comparison. This
is used when sorting the entries using a quicksort, and when looking for
a specific entry with the new search methods.

The following search methods now exist:

	git_vector_search(vector, entry)
	git_vector_search2(vector, custom_search_callback, key)

	git_vector_bsearch(vector, entry)
	git_vector_bsearch2(vector, custom_search_callback, key)

The sorting state of the vector is now stored internally.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-03-03 20:23:52 +02:00
Vicent Marti
5de079b86d Change the object creation/lookup API
The methods previously known as

	git_repository_lookup
	git_repository_newobject
	git_repository_lookup_ref

are now part of their respective namespaces:

	git_object_lookup
	git_object_new
	git_reference_lookup

This makes the API more consistent with the new references API.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-03-03 20:23:52 +02:00
Vicent Marti
3dccfed163 Cleanup the testing toolkit
Tests are now declared with detailed descriptions and a short test name:

	BEGIN_TEST(the_test0, "this is an example test that does something")
		...
	END_TEST

Modules are declared through a simple macro interface:

	BEGIN_MODULE(mod_name)
		ADD_TEST(the_test0);
		...
	END_MODULE

Error messages when tests fail have been greatly improved.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-03-03 20:23:52 +02:00
nulltoken
8fc050961c Add test deleteref::deleting_a_ref_which_is_both_packed_and_loose_should_remove_both_tracks_in_the_filesystem() 2011-03-03 20:23:52 +02:00
nulltoken
d561403f08 Add test for corner case in reference renaming 2011-03-03 20:23:52 +02:00
nulltoken
268bee3d4f Add test renameref::rename_a_loose_reference() 2011-03-03 20:23:52 +02:00
nulltoken
6b02b21516 Add test renameref::can_not_rename_a_reference_with_an_invalid_name() 2011-03-03 20:23:51 +02:00
nulltoken
65cc1f44e1 Add test renameref::can_not_rename_a_reference_with_an_invalid_name() 2011-03-03 20:23:51 +02:00
nulltoken
de05ff6c78 Add test renameref::renaming_a_packed_reference_makes_it_loose() 2011-03-03 20:23:51 +02:00
nulltoken
669db21b28 Slightly changed the behavior of git__joinpath() and git__joinpath_n(). 2011-03-03 20:23:51 +02:00
nulltoken
52b2c2092a Enhance the packrefs::create_packfile() test 2011-03-03 20:23:51 +02:00
nulltoken
e4029c5201 Added copydir_recurs() to test_helpers.c
Test helper function which recursively copies the content of a
directory. This function has been tweaked to prevent stack overflows by
reusing the same path buffers on all recursive calls.
2011-03-03 20:23:51 +02:00
nulltoken
7167422cbf Refactored some test related constants. 2011-03-03 20:23:50 +02:00
nulltoken
705a90ec9e Added tests to exercise the initialization and the opening of a repository. 2011-03-03 20:23:50 +02:00
nulltoken
c38f9013e4 Removed a duplicate constant. 2011-03-03 20:23:50 +02:00
nulltoken
3b3a10176e Added rmdir_recurs(), a test helper function which recursively removes the content of a directory. 2011-03-03 20:23:50 +02:00
nulltoken
47d0db78bb Added some dirname and basename tests to ensure that trailing slashes are ignored. 2011-03-03 20:23:50 +02:00
Vicent Marti
87d3acf45e Finish the References API
The following methods have been implemented:

	git_reference_packall
	git_reference_rename
	git_reference_delete

The library now has full support for packed references, including
partial and total writing. Internal documentation has been updated with
the details.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-03-03 20:23:50 +02:00
nulltoken
9b3985fa2f Slightly enhanced the readability of some reference related tests. 2011-03-03 20:23:49 +02:00
nulltoken
b0a8314340 Removed duplicate tests. 2011-03-03 20:23:49 +02:00
Vicent Marti
86194b2433 Split packed from unpacked references
These two reference types are now stored separately to eventually allow
the removal/renaming of loose references and rewriting of the refs
packfile.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-03-03 20:23:49 +02:00
nulltoken
2de3b35cd4 Added test covering creation of nested symbolic references. 2011-03-03 20:23:49 +02:00
nulltoken
1d8cc73123 Refactored the reference creation API. 2011-03-03 20:23:49 +02:00
nulltoken
e1be102816 Added some more tests to ensure the correct behavior of git_reference__normalize_name(). 2011-03-03 20:23:48 +02:00
nulltoken
77600378db Fixed line endings (CRLF->LF). 2011-03-03 20:23:48 +02:00
nulltoken
aa2120e9da Added git_reference__normalize_name() along with tests. 2011-03-03 20:23:48 +02:00
Vicent Marti
fc658755bf Rewrite git_hashtable internals
The old hash table with chained buckets has been replaced by a new one
using Cuckoo hashing, which offers guaranteed constant lookup times.
This should improve speeds on most use cases, since hash tables in
libgit2 are usually used as caches where the objects are stored once and
queried several times.

The Cuckoo hash implementation is based off the one in the Basekit
library [1] for the IO language, but rewritten to support an arbritrary
number of hashes. We currently use 3 to maximize the usage of the nodes pool.

[1]: https://github.com/stevedekorte/basekit/blob/master/source/CHash.c

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-22 21:59:36 +02:00
Vicent Marti
4378e8d470 Add unit test for writing a big index file
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-22 15:19:35 +02:00
Vicent Marti
348c7335dd Improve the performance when writing Index files
In response to issue #60 (git_index_write really slow), the write_index
function has been rewritten to improve its performance -- it should now
be in par with the performance of git.git.

On top of that, if Posix Threads are available when compiling libgit2, a
new threaded writing system will be used (3 separate threads take care
of solving byte-endianness, hashing the contents of the index and
writing to disk, respectively). For very long Index files, this method
is up to 3x times faster than git.git.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-17 23:20:47 +02:00
Vicent Marti
d4b5a4e23a Internal changes on the backend system
The priority value for different backends has been removed from the
public `git_odb_backend` struct. We handle that internally. The priority
value is specified on the `git_odb_add_alternate`.

This is convenient because it allows us to poll a backend twice with
different priorities without having to instantiate it twice.

We also differentiate between main backends and alternates; alternates have
lower priority and cannot be written to.

These changes come with some unit tests to make sure that the backend
sorting is consistent.

The libgit2 version has been bumped to 0.4.0.

This commit changes the external API:

CHANGED:
	struct git_odb_backend
		No longer has a `priority` attribute; priority for the backend
		in managed internally by the library.

	git_odb_add_backend(git_odb *odb, git_odb_backend *backend, int priority)
		Now takes an additional priority parameter, the priority that
		will be given to the backend.

ADDED:
	git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, int priority)
		Add a backend as an alternate. Alternate backends have always
		lower priority than main backends, and writing is disabled on
		them.

Signed-off-by: Vicent Marti <tanoku@gmail.com>

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-09 19:49:38 +02:00
Vicent Marti
995f9c34a5 Use the new git__joinpath to build paths in methods
The `git__joinpath` function has been changed to use a statically
allocated buffer; we assume the buffer to be 4096 bytes, because fuck
you.

The new method also supports an arbritrary number of paths to join,
which may come in handy in the future.

Some methods which were manually joining paths with `strcpy` now use the
new function, namely those in `index.c` and `refs.c`.

Based on Emeric Fermas' original patch, which was using the old
`git__joinpath` because I'm stupid. Thanks!

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-09 12:43:19 +02:00
nulltoken
1b7124f849 Added tests exercising git_reference_write() to create a new symbolic reference and a new object id reference. 2011-02-07 21:24:52 +01:00
Vicent Marti
2e75e15690 Merge branch 'refs-handling-tests' of https://github.com/nulltoken/libgit2 2011-02-07 08:04:32 +02:00
nulltoken
fc8afc87d7 Fix a memory leak in git__joinpath() tests. 2011-02-06 07:48:17 +01:00
nulltoken
a79e8e632a Fixed a small issue in git__join_path(). Added tests to exercise git__join_path(). 2011-02-05 19:23:51 +01:00
nulltoken
ca0fb40a6f Made test index_write_test() remove the test file it has created.
It can now be run twice in a row without failing.
2011-02-05 19:23:51 +01:00
Vicent Marti
c041af95a2 Add support for SQLite backends
Configure again the build system to look for SQLite3. If the library is
found, the SQLite backend will be automatically compiled.

Enjoy *very* fast reads and writes.

MASTER PROTIP: Initialize the backend with ":memory" as the path to the
SQLite database for fully-hosted in-memory repositories. Rejoice.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-05 19:45:57 +02:00
Vicent Marti
95901128b8 Move data from t03 to a separate header
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-05 18:17:01 +02:00
nulltoken
1af8c7488d Enforced refs handling tests.
- Added a test to ensure that a nested symbolic reference is properly resolved.
 - Added comparisons of object ids.
2011-02-05 15:24:08 +01:00
Vicent Marti
f725931b48 Fix directory/path manipulation methods
The `dirname` and `dirbase` methods have been replaced with the Android
implementation, which is actually compilant to some kind of standard.

A new method `topdir` has been added, which returns the topmost
directory in a path.

These changes fix issue #49:

	`gitfo_prettify_dir_path` converts "./.git/" to ".git/", so
	the code at src/repository.c:190 goes out of bounds when
	trying to find the topmost directory.

	The new `git__topdir` method handles this gracefully, and the
	fixed `git__dirname` now returns the proper value for the
	repository's working dir.

	E.g.

		/repo/.git/ ==> working dir '/repo/'
		.git/		==> working dir '.'

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-05 12:42:41 +02:00
Vicent Marti
c836c332f1 Make more methods return error codes
git_revwalk_next now returns an error code when the iteration is over.
git_repository_index now returns an error code when the index file could
not be opened.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-05 09:29:37 +02:00
Vicent Marti
87d82994be Make the test return an error code on failure
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-02 02:32:21 +02:00
Vicent Marti
2a1732b439 Rewrite the unit testing suite
NIH Enterprises presents: a new testing system based on CuTesT, which is
faster than our previous one and fortunately uses no preprocessing on
the source files, which means we can run that from CMake.

The test suites have been gathered together into bigger files (one file
per suite, testing each of the different submodules of the library).

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-02 02:15:25 +02:00
Vicent Marti
2f8a8ab24b Refactor reference parsing code
Several changes have been committed to allow the user to create
in-memory references and write back to disk. Peeling of symbolic
references has been made explicit. Added getter and setter methods for
all attributes on a reference. Added corresponding documentation.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-01-30 02:35:29 +02:00
nulltoken
9282e921a3 Merge nulltoken's reference parsing code
All the commits have been squashed into a single one before refactoring
the final code, to keep everything tidy.

Individual commit messages are as follows:

Added repository reference looking up functionality placeholder.

Added basic reference database definition and caching infrastructure.

Removed useless constant.

Added GIT_EINVALIDREFNAME error and description. Added missing description for GIT_EBAREINDEX.

Added GIT_EREFCORRUPTED error and description.

Added GIT_ETOONESTEDSYMREF error and description.

Added resolving of direct and symbolic references.

Prepared the packed-refs parsing.

Added parsing of the packed-refs file content.

When no loose reference has been found, the full content of the packed-refs file is parsed. All of the new (i.e. not previously parsed as a loose reference) references are eagerly stored in the cached references storage.

The method packed_reference_file__parse() is in deer need of some refactoring. :-)

Extracted to a method the parsing of the peeled target of a tag.

Extracted to a method the parsing of a standard packed ref.

Fixed leaky removal of the cached references.

Ensured that a previously parsed packed reference isn't returned if a more up-to-date loose reference exists.

Enhanced documentation of git_repository_reference_lookup().

Moved some refs related constants from repository.c to refs.h.

Made parsing of a packed tag reference more robust.

Updated git_repository_reference_lookup() documentation.

Added some references to the test repository.

Added some tests covering tag references looking up.

Added some tests covering symbolic and head references looking up.

Added some tests covering packed references looking up.
2011-01-29 03:39:02 +02:00
nulltoken
2e6fd09c5d Fixed naming convention related issue. 2011-01-29 03:29:33 +02:00
nulltoken
618818dcb7 Added git_prettify_file_path(). 2011-01-29 03:29:32 +02:00
nulltoken
ae7ffea961 Fixed a parsing issue in git_prettify_dir_path(). 2011-01-29 03:29:32 +02:00
Vicent Marti
b29e8f1930 Return the created entry in git_tree_add_entry()
Yes, we are breaking the API. Alpha software, deal with it.

We need a way of getting a pointer to each newly added entry to the
index, because manually looking up the entry after creation is
outrageously expensive.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-01-29 02:12:59 +02:00
nulltoken
e16c2f6a4c Small enhancements to git_prettify_dir_path().
- Secured buffer ahead reading.
 - Guard against potential multiple dot path traversal (cf http://cwe.mitre.org/data/definitions/33.html)
2011-01-20 13:03:49 -08:00
Vicent Marti
e08b246cec Fix signed/unsigned comparison warning
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-01-19 17:20:39 -08:00
nulltoken
170d3f2fbb Added git_prettify_dir_path().
Clean up a provided absolute or relative directory path.

This prettification relies on basic operations such as coalescing multiple forward slashes into a single slash, removing '.' and './' current directory segments, and removing parent directory whenever '..' is encountered. If not empty, the returned path ends with a forward slash.

For instance, this will turn "d1/s1///s2/..//../s3" into "d1/s3/".

This only performs a string based analysis of the path. No checks are done to make sure the path actually makes sense from the file system perspective.
2011-01-11 20:12:53 +01:00
Alex Budovski
a17777d161 Fixed two buffer handling errors in vector.c
- remove() would read one-past array bounds.
- resize() would fail if the initial size was 1, because it multiplied by 1.75
  and truncated the resulting value. The buffer would always remain at size 1,
  but elements would repeatedly be appended (via insert()) causing a crash.
2011-01-08 22:17:52 +02:00
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