Commit Graph

518 Commits

Author SHA1 Message Date
Vicent Marti
5ca2f58057 Do not set error message on GIT_EREVWALKOVER
This is not really an error, just a special return code to mark the end
of an iteration.
2011-05-15 23:48:05 +03:00
Vicent Marti
7cadd1f6a7 Check error code from git_cache_init 2011-05-15 23:46:22 +03:00
Vicent Marti
4edf3e099a Return success code on git_cache_init 2011-05-15 23:45:24 +03:00
Vicent Martí
3fe2e770ca Merge pull request #184 from nulltoken/repo-error-handling
Updated fileops.c and repository.c to new error handling mechanism
2011-05-15 13:34:43 -07:00
Shuhei Tanuma
71747bcae0 fix git_otype typo when calling git_odb_read_header. 2011-05-15 20:07:54 +09:00
nulltoken
81201a4c4d Move cache.c to the new error handling 2011-05-15 06:57:34 +02:00
nulltoken
3abe3bba5a Move repository.c to the new error handling 2011-05-14 16:05:33 +02:00
nulltoken
77c3999ca9 Move fileops.c to the new error handling 2011-05-14 14:46:22 +02:00
Vicent Martí
f02f4b536c Merge pull request #183 from schu/errors
Replace errors
2011-05-13 15:25:19 -07:00
Vicent Marti
098173c52a Check Redis replies for NULL 2011-05-13 04:19:53 +03:00
schu
b51c92693d Move revwalk.c to the new error handling
Signed-off-by: schu <schu-github@schulog.org>
2011-05-11 14:44:44 +02:00
schu
86f5fa7810 Move vector.c to the new error handling
Remove "redundant" check for v->_cmp in wrapper function
git_vector_bsearch().

Signed-off-by: schu <schu-github@schulog.org>
2011-05-11 14:00:53 +02:00
schu
d6de92b6fe Move tree.c to the new error handling
Signed-off-by: schu <schu-github@schulog.org>
2011-05-11 12:40:04 +02:00
schu
cbcaf0c09c Move blob.c to the new error handling
Signed-off-by: schu <schu-github@schulog.org>
2011-05-11 12:39:31 +02:00
Vicent Marti
6810bf28f8 Move all error-related defines to git2/errors.h 2011-05-11 00:40:07 +03:00
Vicent Marti
f4a936b56a Bring back git_strerror
We cannot totally deprecate this until the new error handling mechanisms
are all in place.
2011-05-11 00:35:40 +03:00
Carlos Martín Nieto
44dc0d261b Move tag.c to the new error handling
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-05-10 18:56:44 +02:00
Carlos Martín Nieto
5de24ec736 Move signature.c to the new error handling
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-05-10 17:38:41 +02:00
Vicent Marti
5711ca93d1 Merge branch 'error-handling' into development 2011-05-09 21:58:26 +03:00
Vicent Marti
fa59f18d0d Change error handling mechanism once again
Ok, this is the real deal. Hopefully. Here's how it's going to work:

- One main method, called `git__throw`, that sets the error
	code and error message when an error happens.

	This method must be called in every single place where an error
	code was being returned previously, setting an error message
	instead.

	Example, instead of:

		return GIT_EOBJCORRUPTED;

	Use:

		return git__throw(GIT_EOBJCORRUPTED,
			"The object is missing a finalizing line feed");

	And instead of:

		[...] {
			error = GIT_EOBJCORRUPTED;
			goto cleanup;
		}

	Use:

		[...] {
			error = git__throw(GIT_EOBJCORRUPTED, "What an error!");
			goto cleanup;
		}

	The **only** exception to this are the allocation methods, which
	return NULL on failure but already set the message manually.

		/* only place where an error code can be returned directly,
		   because the error message has already been set by the wrapper */
		if (foo == NULL)
			return GIT_ENOMEM;

- One secondary method, called `git__rethrow`, which can be used to
fine-grain an error message and build an error stack.

	Example, instead of:

		if ((error = foobar(baz)) < GIT_SUCCESS)
			return error;

	You can now do:

		if ((error = foobar(baz)) < GIT_SUCCESS)
			return git__rethrow(error, "Failed to do a major operation");

	The return of the `git_lasterror` method will be a string in the
	shape of:

		"Failed to do a major operation. (Failed to do an internal
		operation)"

	E.g.

		"Failed to open the index. (Not enough permissions to access
		'/path/to/index')."

	NOTE: do not abuse this method. Try to write all `git__throw`
	messages in a descriptive manner, to avoid having to rethrow them to
	clarify their meaning.

	This method should only be used in the places where the original
	error message set by a subroutine is not specific enough.

	It is encouraged to continue using this style as much possible to
	enforce error propagation:

		if ((error = foobar(baz)) < GIT_SUCCESS)
			return error; /* `foobar` has set an error message, and
							 we are just propagating it */

The error handling revamp will take place in two phases:

	- Phase 1: Replace all pieces of code that return direct error codes
	with calls to `git__throw`. This can be done semi-automatically
	using `ack` to locate all the error codes that must be replaced.

	- Phase 2: Add some `git__rethrow` calls in those cases where the
	original error messages are not specific enough.

Phase 1 is the main goal. A minor libgit2 release will be shipped once
Phase 1 is ready, and the work will start on gradually improving the
error handling mechanism by refining specific error messages.

OTHER NOTES:

	- When writing error messages, please refrain from using weasel
	words. They add verbosity to the message without giving any real
	information. (<3 Emeric)

	E.g.

		"The reference file appears to be missing a carriage return"
			Nope.

		"The reference file is missing a carriage return"
			Yes.

	- When calling `git__throw`, please try to use more generic error
	codes so we can eventually reduce the list of error codes to
	something more reasonable. Feel free to add new, more generic error
	codes if these are going to replace several of the old ones.

	E.g.

		return GIT_EREFCORRUPTED;

	Can be turned into:

		return git__throw(GIT_EOBJCORRUPTED,
			"The reference is corrupted");
2011-05-09 21:58:02 +03:00
Vicent Marti
5eb0fab846 errors: Update external API with new git_lasterror 2011-05-09 21:58:02 +03:00
Vicent Marti
3f53c97113 errors: Set error messages on memory allocation 2011-05-09 21:58:02 +03:00
Vicent Marti
02f9e637a1 errors: Add error handling function 2011-05-09 21:58:01 +03:00
Vicent Martí
cd2cc2dc36 Merge pull request #170 from jasonrm/development
Fix misspelling of git_index_append2 (was git_index_apppend2).
2011-05-08 14:00:57 -07:00
Vicent Martí
5f94b77cd1 Merge pull request #174 from carlosmn/backend-static
odb backend_sort_cmp should be static
2011-05-08 13:59:47 -07:00
kelly.leahy
16a5c30465 Fix bug in the way pthead_mutex_t was being destroyed in win32.
Win32 critical section objects (CRITICAL_SECTION) are not kernel objects.
Only kernel objects are destroyed by using CloseHandle.  Critical sections
are supposed to be deleted with the DeleteCriticalSection API
(http://msdn.microsoft.com/en-us/library/ms682552(VS.85).aspx).
2011-05-08 12:32:35 -07:00
Carlos Martín Nieto
d8e1d038b3 Fix two warnings from Clang
Both are about not reading the value stored in a variable.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-05-06 12:47:21 +02:00
Carlos Martín Nieto
39e1032cfc odb backend_sort_cmp should be static
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-05-06 12:43:37 +02:00
Jason R. McNeil
773bc20dd3 Fix misspelling of git_index_append2 (was git_index_apppend2). 2011-05-03 22:22:42 -07:00
Vicent Martí
cc3b82e376 Merge pull request #151 from carlosmn/root-commit.
Support root commits
2011-05-02 15:29:50 -07:00
Vicent Martí
fde97669ec Merge pull request #146 from nordsturm/fix_subtrees.
Fix tree-entry attribute convertion (fix corrupted trees)
2011-05-02 15:26:16 -07:00
Vicent Marti
1648fbd344 Re-apply missing patches 2011-05-02 01:12:53 +03:00
Vicent Martí
d4ad0771e4 Merge pull request #145 from schu/fix-unused-warnings.
Fix -Wunused-but-set-variable warnings
2011-05-01 14:59:50 -07:00
Vicent Martí
273c8bc044 Merge pull request #147 from nordsturm/fix_pack_backend_leak.
Fix memory leak in pack_backend__free
2011-05-01 14:59:11 -07:00
Vicent Marti
c7b79af3f0 pack-odb: Check mtime instead of folder size
Do not check the folder's size to detect new packfiles at runtime. This
doesn't work on Win32.
2011-05-01 21:31:58 +03:00
Carlos Martín Nieto
8381238e00 commit: support a root commits
A root commit is a commit whose branch (usually what HEAD points to)
doesn't exist (yet). This situation can happen when the commit is the
first after 1) a repository is initialized or 2) a orphan checkout has
been performed.

Take this opportunity to remove the symbolic link check, as
git_reference_resolve works on OID refs as well.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-04-29 11:50:39 +02:00
Carlos Martín Nieto
68a146c1ae refs: don't loose info on resolve error
Typical use is git_reference_resolve(&ref, ref). Currently, if there is
an error, ref will point to NULL, causing the user to lose that
reference.

Always update resolved_ref instead of just on finding an OID ref,
storing the last valid reference in it.

This change helps simplify the code for allowing root commits.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-04-29 11:50:39 +02:00
Sergey Nikishin
ed6c462c20 Fix memory leak in pack_backend__free 2011-04-27 17:30:45 +04:00
Sergey Nikishin
555ce56819 Fix tree-entry attribute convertion (fix corrupted trees)
Magic constant replaced by direct to-string covertion because of:
1) with value length 6 (040000 - subtree) final tree will be corrupted;
2) for wrong values length <6 final tree will be corrupted too.
2011-04-26 15:32:11 +04:00
schu
402a47a7fa Fix -Wunused-but-set-variable warnings
As of gcc 4.6 -Wall includes -Wunused-but-set-variable. Use GIT_UNUSED
or remove actually unused variables to prevent those warnings.
2011-04-26 11:29:05 +02:00
Vicent Martí
7df49e9e5f Merged pull request #139 from jpfender/merge-head-file.
refs: Allow MERGE_HEAD in normalize_name()
2011-04-23 14:36:01 -07:00
Vicent Marti
f7a5058aaf index: Refactor add/replace methods
Removed the optional `replace` argument, we now have 4 add methods:

	`git_index_add`: add or update from path
	`git_index_add2`: add or update from struct
	`git_index_append`: add without replacing from path
	`git_index_append2`: add without replacing from struct

Yes, this breaks the bindings.
2011-04-24 00:31:43 +03:00
Vicent Martí
f16c0a9db7 Merged pull request #140 from jpfender/insert-replace.
index: Allow user to toggle whether to replace an index entry
2011-04-23 14:08:17 -07:00
Vicent Martí
5ba7c4cbae Merged pull request #143 from nordsturm/fix_loop.
Fix going into infinite loop in read_header_loose()
2011-04-23 14:01:01 -07:00
Vicent Marti
1d0087816e Fix conversion warning in MSVC 2011-04-23 23:59:38 +03:00
Sergey Nikishin
a3ced63792 Fix going into infinite loop in read_header_loose()
read_header_loose causes infinite loop on this file:
$ cat ../libcppgit/bin/sample-repo/test_mailbox/.git/objects/8f/e274605cbc740a2a957f44b2722a8a73915a09 | base64
eAErKUpNVTAzYzA0MDAzMVHISUxKzSlmWLgkuyN5+rxr6juMPR2EmN8s7Vl9D6oiN7UkkcHJdLbl
7Z3N/oxfE0W8wrSbuFRkAwDFfBn1
2011-04-22 17:41:36 +04:00
Jakob Pfender
729b6f4900 index: Allow user to toggle whether to replace an index entry
When in the middle of a merge, the index needs to contain several files
with the same name. git_index_insert() used to prevent this by not adding a new entry if an entry with the same name already existed.
2011-04-21 10:40:54 +02:00
Jakob Pfender
df30eac1eb refs: Allow MERGE_HEAD in normalize_name()
Do not return with EINVALIDREFNAME when trying to normalize MERGE_HEAD's
name.
2011-04-21 10:38:37 +02:00
Vicent Marti
2571cc3cff Close file descriptor when writing a blob 2011-04-15 20:32:31 +03:00
Vicent Marti
90d743cd5d Refresh the list of packfiles on each ODB query
Fixes the issue where object lookups were failing right after a pull on
an open repository.
2011-04-15 15:12:37 +03:00