1. 10 May, 2011 1 commit
  2. 09 May, 2011 5 commits
    • Change error handling mechanism once again · fa59f18d
      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");
      Vicent Marti committed
  3. 08 May, 2011 7 commits
  4. 06 May, 2011 3 commits
  5. 05 May, 2011 1 commit
  6. 04 May, 2011 1 commit
  7. 02 May, 2011 2 commits
  8. 01 May, 2011 6 commits
  9. 29 Apr, 2011 3 commits
    • Add root commit test · 79b61557
      Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
      Carlos Martín Nieto committed
    • commit: support a root commits · 8381238e
      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>
      Carlos Martín Nieto committed
    • refs: don't loose info on resolve error · 68a146c1
      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>
      Carlos Martín Nieto committed
  10. 27 Apr, 2011 1 commit
  11. 26 Apr, 2011 2 commits
  12. 23 Apr, 2011 7 commits
  13. 22 Apr, 2011 1 commit