Commit Graph

1171 Commits

Author SHA1 Message Date
Vicent Martí
86b74ea0ab Merge pull request #180 from kellypleahy/bug/fix_issue_79
Fix issue #79 - git_lasterror() isn't appearing in git2.dll in windows.
2011-05-10 14:26:16 -07:00
Vicent Martí
97ce36e700 Merge pull request #181 from carlosmn/errors
Move signature.c and tag.c to the new error handling
2011-05-10 14:23:01 -07: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
Carlos Martín Nieto
c033500549 Move config to a backend structure
Configuration options can come from different sources. Currently,
there is only support for reading them from a flat file, but it might
make sense to read it from a database at some point.

Move the parsing code into src/config_file.c and create an include
file include/git2/config_backend.h to allow for other backends to be
developed.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-05-10 14:47:20 +02:00
kelly.leahy
ab86f159e5 Fix issue #79 - git_lasterror() isn't appearing in git2.dll in windows.
The GIT_EXPORT macro is used to declare a function to be externally
accessible to other libraries.  This commit uses GIT_EXPORT to declare
the git_lasterror() function as externally exported.  I verified with
depends.exe that the function is available to external callers (i.e.
in the exports table of the PE file).
2011-05-09 23:39:32 -07: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í
c912229e1f Merge pull request #172 from carlosmn/valgrind
ref test: update a forgotten repo -> repo2
2011-05-08 14:00:06 -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
Vicent Martí
f26f2b80a7 Merge pull request #177 from kellypleahy/topic/fix-delete-mutex
Fix bug in the way pthead_mutex_t was being destroyed in win32.
2011-05-08 13:56:09 -07:00
Scott Chacon
cd7ad3c6fb Merge pull request #176 from kellypleahy/topic/force-line-endings
Add git attributes settings for *.c and *.h to force line endings to LF.
2011-05-08 12:39:21 -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
kelly.leahy
560cd27ef3 Add git attributes settings for *.c and *.h to force line endings to LF. 2011-05-08 12:30:16 -07:00
Vicent Martí
cfba137707 Merge pull request #175 from carlosmn/analyzer
Fix two warnings from Clang.

Fixes issue #173
2011-05-06 09:09:50 -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
Carlos Martín Nieto
ca8d2dfc0c Merge remote-tracking branch 'upstream/development' into config 2011-05-05 16:22:06 +02:00
Carlos Martín Nieto
094aaaaee9 config: store the section name separately
The section and variable names use different rules, so store them as
two different variables internally.

This will simplify the configuration-writing code as well later on,
but even with parsing, the code is simpler.

Take this opportunity to add a variable to the list directly when
parsing instead of passing through config_set.
2011-05-05 16:18:11 +02:00
Carlos Martín Nieto
bbd68c6768 ref test: update a forgotten repo -> repo2
Commit 34e5d87e05 left one of these unchanged we're trying
to read from a free'd repository.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-05-05 11:40:39 +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 Martí
7fba6a79ba Merge pull request #168 from nulltoken/isolate_refs_tests.
Isolate "writing" refs tests in a temporary folder
2011-05-01 12:43:30 -07:00
nulltoken
34e5d87e05 Change implementation of refs tests that alter the current repository to make them run against a temporary clone of the test repository 2011-05-01 21:35:32 +02: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
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
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
Jakob Pfender
e3c7786b22 index.c: Remove duplicate function declaration
read_unmerged_internal() was present twice.
2011-04-28 17:31:13 +02:00
Sergey Nikishin
ed6c462c20 Fix memory leak in pack_backend__free 2011-04-27 17:30:45 +04:00
Carlos Martín Nieto
0130d8184e Fix git__strntolower
Obviously, the whole string should be lower-cased and not just the
last char.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-04-27 11:20:38 +02: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
Sergey Nikishin
1d1735fe03 Add error processing in git_blob_create_frombuffer() 2011-04-24 18:43:08 +04:00
Sergey Nikishin
411823a3d0 Fix whole buffer writing in fake wstream 2011-04-24 18:43:08 +04:00
Vicent Martí
7c37aa3ac5 Merged pull request #115 from jpfender/index-flags.
index.h: Add IDXENTRY flags needed for index operations
2011-04-23 14:39:04 -07:00
Vicent Martí
5a74d16048 Merged pull request #135 from carlosmn/valgrind.
Fix memory leaks in the tests
2011-04-23 14:37:56 -07: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