Commit Graph

30 Commits

Author SHA1 Message Date
Vicent Marti
45e79e3701 Rename all _close methods
There's no difference between `_free` and `_close` semantics: keep
everything with the same name to avoid confusions.
2011-11-26 08:48:00 +01:00
schu
75abd2b924 Free all used references in the source tree
Since references are not owned by the repository anymore we have to free
them manually now.

Signed-off-by: schu <schu-github@schulog.org>
2011-11-06 03:15:26 +01:00
Vicent Martí
89fb8f025a Merge pull request #456 from brodie/perm-fixes
Create objects, indexes, and directories with the right file permissions
2011-10-28 19:04:23 -07:00
Vicent Marti
3286c408ec global: Properly use git__ memory wrappers
Ensure that all memory related functions (malloc, calloc, strdup, free,
etc) are using their respective `git__` wrappers.
2011-10-28 19:02:36 -07:00
Brodie Rao
01ad7b3a9e *: correct and codify various file permissions
The following files now have 0444 permissions:

- loose objects
- pack indexes
- pack files
- packs downloaded by fetch
- packs downloaded by the HTTP transport

And the following files now have 0666 permissions:

- config files
- repository indexes
- reflogs
- refs

This brings libgit2 more in line with Git.

Note that git_filebuf_commit() and git_filebuf_commit_at() have both
gained a new mode parameter.

The latter change fixes an important issue where filebufs created with
GIT_FILEBUF_TEMPORARY received 0600 permissions (due to mkstemp(3)
usage). Now we chmod() the file before renaming it into place.

Tests have been added to confirm that new commit, tag, and tree
objects are created with the right permissions. I don't have access to
Windows, so for now I've guarded the tests with "#ifndef GIT_WIN32".
2011-10-14 16:07:47 -07:00
Brodie Rao
6f2856f308 signature: don't blow up trying to parse names containing '>'
When trying to find the end of an email, instead of starting at the
beginning of the signature, we start at the end of the name (after the
first '<').

This brings libgit2 more in line with Git's behavior when reading out
existing signatures.

However, note that Git does not allow names like these through the
usual porcelain; instead, it silently strips any '>' characters it
sees.
2011-10-12 16:19:46 -07:00
Brodie Rao
04f788023f commit: properly parse empty commit messages
This ensures commit->message is always non-NULL, even if the commit
message is empty or consists of only a newline.

One such commit can be found in the wild in the jQuery repository:

25b424134f
2011-10-12 15:14:25 -07:00
Kirill A. Shutemov
d568d5856b CMakefile: add -Wmissing-prototypes and fix warnings
Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-08-30 23:55:22 +03:00
Vicent Marti
5ae2f0c013 commit: Add support for Encoding header 2011-08-12 16:24:19 -07:00
Vicent Marti
f6867e639a Fix compilation in Windows 2011-08-08 16:56:28 -07:00
Lambert CLARA
9d76b934f1 Fix wrong test in t04-commit
Replace all must_pass(strcmp()) by must_be_true(strcmp()==0)
2011-08-04 22:49:39 +02:00
schu
63396a3998 signature: adjust API to return error codes
git_signature_new() and git_signature_now() currently don't return error
codes. Change the API to return error codes and not pointers to let the
user handle errors properly.

Signed-off-by: schu <schu-github@schulog.org>
2011-08-03 16:05:32 +02:00
schu
5274c31a89 signature.c: fix off-by-one error
Signed-off-by: schu <schu-github@schulog.org>
2011-08-03 01:17:31 +02:00
Kirill A. Shutemov
84ef7f3636 tests: fix cast warnings
/home/kas/git/public/libgit2/tests/t00-core.c: In function ‘test_cmp’:
/home/kas/git/public/libgit2/tests/t00-core.c:78:10: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual]
/home/kas/git/public/libgit2/tests/t00-core.c:78:22: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual]
/home/kas/git/public/libgit2/tests/t07-hashtable.c: In function ‘hash_func’:
/home/kas/git/public/libgit2/tests/t07-hashtable.c:42:7: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual]
/home/kas/git/public/libgit2/tests/t08-tag.c: In function ‘_gittest__write0’:
/home/kas/git/public/libgit2/tests/t08-tag.c:141:21: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual]
/home/kas/git/public/libgit2/tests/t08-tag.c: In function ‘_gittest__write2’:
/home/kas/git/public/libgit2/tests/t08-tag.c:192:21: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual]
/home/kas/git/public/libgit2/tests/t08-tag.c: In function ‘_gittest__write3’:
/home/kas/git/public/libgit2/tests/t08-tag.c:227:21: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual]
/home/kas/git/public/libgit2/tests/t04-commit.c: In function ‘_gittest__write0’:
/home/kas/git/public/libgit2/tests/t04-commit.c:650:21: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual]
/home/kas/git/public/libgit2/tests/t04-commit.c:651:21: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual]
/home/kas/git/public/libgit2/tests/t04-commit.c: In function ‘_gittest__root0’:
/home/kas/git/public/libgit2/tests/t04-commit.c:723:21: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual]
/home/kas/git/public/libgit2/tests/t04-commit.c:724:21: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual]
/home/kas/git/public/libgit2/tests/t12-repo.c: In function ‘write_file’:
/home/kas/git/public/libgit2/tests/t12-repo.c:360:24: warning: cast discards ‘__attribute__((const))’ qualifier from pointer target type [-Wcast-qual]

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-07-25 21:12:47 +02:00
nulltoken
7757be33a2 reflog: Fix reflog writer/reader
- Use a space to separate oids and signature
 - Enforce test coverage
 - Make test run in a temporary folder in order not to alter the test repository
2011-07-10 19:17:07 +02:00
Vicent Marti
06c43821b9 Remove unused methods
The direct-writes commit left some (slow) internals methods that
were no longer needed. These have been removed.

Also, the Reflog code was using the old `git_signature__write`, so
it has been rewritten to use a normal buffer and the new `writebuf`
signature writer. It's now slightly simpler and faster.
2011-07-09 02:40:16 +02:00
nulltoken
a01acc47bb signature: straighten the creation of a signature
- Fails on empty name and/or email
 - Trims leading and trailing spaces of name and email
2011-07-05 02:21:26 +02:00
nulltoken
42a1b5e1ad signature: enhance relaxed parsing of bogus signatures
Final fix for issue #278
2011-07-05 02:21:26 +02:00
schu
60caf02465 t04-commit: add tests for git_signature__parse
git_signature__parse used to be very strict about what's a well-formed
signature. Add tests checking git_signature__parse can stick with
"unexpected" signatures (IOW no author name and / or no email, etc).

Signed-off-by: schu <schu-github@schulog.org>
2011-07-05 02:21:26 +02:00
Kirill A. Shutemov
932d1baf29 cleanup: remove trailing spaces
Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-07-01 18:02:56 +02:00
Vicent Marti
d5afc0390c Remove redundant methods from the API
A bunch of redundant methods have been removed from the external API.

- All the reference/tag creation methods with `_f` are gone. The force
flag is now passed as an argument to the normal create methods.

- All the different commit creation methods are gone; commit creation
now always requires a `git_commit` pointer for parents and a `git_tree`
pointer for tree, to ensure that corrupted commits cannot be generated.

- All the different tag creation methods are gone; tag creation now
always requires a `git_object` pointer to ensure that tags are not
created to inexisting objects.
2011-06-28 19:36:27 +02:00
Vicent Marti
fa48608ec3 oid: Rename methods
Yeah. Finally. Fuck the old names, this ain't POSIX
and they don't make any sense at all.
2011-06-16 02:36:21 +02:00
Carlos Martín Nieto
79b6155736 Add root commit test
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-04-29 12:08:24 +02:00
Carlos Martín Nieto
2fe3692c23 tests: don't leak objects
If we don't create any leaks in the tests, we can use them to search
for leaks in the implementation.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-04-13 21:50:11 +02: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
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
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
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
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
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