Commit Graph

93 Commits

Author SHA1 Message Date
Vicent Marti
e16e268457 No longer needed 2013-04-22 16:50:51 +02:00
Michael Schubert
f5e28202cb opts: allow configuration of odb cache size
Currently, the odb cache has a fixed size of 128 slots as defined by
GIT_DEFAULT_CACHE_SIZE. Allow users to set the size of the cache via
git_libgit2_opts().

Fixes #1035.
2013-03-25 15:45:56 +01:00
Russell Belfer
41954a49c1 Switch search paths to classic delimited strings
This switches the APIs for setting and getting the global/system
search paths from using git_strarray to using a simple string with
GIT_PATH_LIST_SEPARATOR delimited paths, just as the environment
PATH variable would contain.  This makes it simpler to get and set
the value.

I also added code to expand "$PATH" when setting a new value to
embed the old value of the path.  This means that I no longer
require separate actions to PREPEND to the value.
2013-03-18 14:19:35 -07:00
Russell Belfer
5540d9477e Implement global/system file search paths
The goal of this work is to expose the search logic for "global",
"system", and "xdg" files through the git_libgit2_opts() interface.

Behind the scenes, I changed the logic for finding files to have a
notion of a git_strarray that represents a search path and to store
a separate search path for each of the three tiers of config file.
For each tier, I implemented a function to initialize it to default
values (generally based on environment variables), and then general
interfaces to get it, set it, reset it, and prepend new directories
to it.

Next, I exposed these interfaces through the git_libgit2_opts
interface, reusing the GIT_CONFIG_LEVEL_SYSTEM, etc., constants
for the user to control which search path they were modifying.
There are alternative designs for the opts interface / argument
ordering, so I'm putting this phase out for discussion.

Additionally, I ended up doing a little bit of clean up regarding
attr.h and attr_file.h, adding a new attrcache.h so the other two
files wouldn't have to be included in so many places.
2013-03-15 16:39:00 -07:00
Vicent Marti
a0f777c87f opts: Add getters too 2013-01-23 23:44:34 +01:00
Vicent Marti
59853eff99 Global options setter 2013-01-23 02:58:58 +01:00
Edward Thomson
359fc2d241 update copyrights 2013-01-08 17:31:27 -06:00
Philip Kelley
613d5eb939 Push! By schu, phkelley, and congyiwu, et al 2012-11-28 11:42:37 -05:00
Paul Thompson
b46708aaf9 Separated git_strarray from common.h. Added doxy comments. 2012-10-11 23:04:08 +11:00
Sascha Cunz
e564e4969c Add function to query for compile time settings. 2012-08-01 20:02:32 +02:00
Chris Young
a8df98c6fb Updates from comments on OS4 compatibility pull request http://github.com/libgit2/libgit2/pull/766 2012-06-14 18:57:24 +01:00
Chris Young
327fb51cec Fix gethostbyname compatibility 2012-06-09 18:13:07 +01:00
Chris Young
fa56478fb8 Generic needs compat files 2012-06-08 19:15:11 +01:00
Chris Young
aa5a92d121 OS4 compatibility 2012-06-08 18:57:35 +01:00
Chris Young
0f5e1f3b68 Network byte order is big-endian - the way it should be :) 2012-06-07 21:56:19 +01:00
Vicent Martí
79fdde494f Revert "Specifiy dllimport to MSVC if we're not building libgit2.dll"
This reverts commit 1093e2de22.
2012-05-14 22:15:53 +02:00
Sascha Cunz
1093e2de22 Specifiy dllimport to MSVC if we're not building libgit2.dll
Building a "shared object" (DLL) in Windows includes 2 steps:

- specify __declspec(dllexport)
  when building the library itself. MSVC will disallow itself from
  optimizing these symbols out and reference them in the PE's
  Exports-Table.
  Further, a static link library will be generated. This library
  contains the symbols which are exported via the declsepc above.
  The __declspec(dllexport) becomes part of the symbol-signature
  (like parameter types in C++ are 'mangled' into the symbol name,
  the export specifier is mingled with the name)

- specify __declspec(dllimport)
  when using the library. This again mingles the declspec into the
  name and declares the function / variable with external linkage.

cmake automatically adds -Dgit2_EXPORTS to the compiler arguments
when compiling the libgit2 project.
The 'git2' is the name specified via PROJECT() in CMakeLists.txt.
2012-05-14 20:22:50 +02:00
Scott J. Goldman
b1ec25facc Fix comment typo in common.h 2012-05-10 17:16:38 -07:00
Vicent Martí
40879facad Merge branch 'new-error-handling' into development
Conflicts:
	.travis.yml
	include/git2/diff.h
	src/config_file.c
	src/diff.c
	src/diff_output.c
	src/mwindow.c
	src/path.c
	tests-clar/clar_helpers.c
	tests-clar/object/tree/frompath.c
	tests/t00-core.c
	tests/t03-objwrite.c
	tests/t08-tag.c
	tests/t10-refs.c
	tests/t12-repo.c
	tests/t18-status.c
	tests/test_helpers.c
	tests/test_main.c
2012-05-02 15:59:02 -07:00
Sven Strickroth
c02f13925a Check for _WIN32 is sufficient, even for x64 compilers
There is no need to check for _WIN32 and _WIN64. x64 compiler also set _WIN32 (compare http://sourceforge.net/apps/mediawiki/predef/index.php?title=Operating_Systems#Windows).

Signed-off-by: Sven Strickroth <email@cs-ware.de>
2012-04-21 18:43:10 +02:00
Russell Belfer
14a513e058 Add support for pathspec to diff and status
This adds preliminary support for pathspecs to diff and status.
The implementation is not very optimized (it still looks at
every single file and evaluated the the pathspec match against
them), but it works.
2012-04-13 15:00:29 -07:00
schu
5e0de32818 Update Copyright header
Signed-off-by: schu <schu-github@schulog.org>
2012-02-13 17:11:09 +01:00
Vicent Marti
a15c550db8 threads: Fix the shared global state with TLS
See `global.c` for a description of what we're doing.

When libgit2 is built with GIT_THREADS support, the threading system
must be explicitly initialized with `git_threads_init()`.
2011-11-16 14:09:44 +01:00
Sven Strickroth
314f54eb06 fix build for x64
Signed-off-by: Sven Strickroth <email@cs-ware.de>
2011-10-09 05:29:57 +02:00
Vicent Marti
c060854ed5 msvc: Properly handle inttypes.h/stdint.h 2011-10-05 16:21:16 -04:00
Vicent Martí
e311519dce Merge pull request #411 from boyski/gcc4
Don't use '__attribute__ visibility' with gcc unless it's at version 4 or better
2011-09-18 19:38:14 -07:00
David Boyce
d2a1861ea1 Don't use '__attribute__ visibility' with gcc unless it's at
version 4 or better.
2011-09-18 21:27:25 -04:00
Vicent Marti
87d9869fc3 Tabify everything
There were quite a few places were spaces were being used instead of
tabs. Try to catch them all. This should hopefully not break anything.
Except for `git blame`. Oh well.
2011-09-19 03:34:49 +03:00
Vicent Marti
bb742ede3d Cleanup legal data
1. The license header is technically not valid if it doesn't have a
copyright signature.

2. The COPYING file has been updated with the different licenses used in
the project.

3. The full GPLv2 header in each file annoys me.
2011-09-19 01:54:32 +03:00
Vicent Marti
536955f9d7 Add method to get the compiled version of the lib 2011-06-16 02:21:33 +02:00
Romain Geissler
0657e46dee Fix: GIT_PATH_PATH_SEPARATOR is now a semi-colon under Windows.
GIT_PATH_LIST_SEPARATOR and GIT_PATH_MAX are made public so
that it's can be used by a client.
2011-06-15 22:11:18 +02:00
Vicent Marti
6810bf28f8 Move all error-related defines to git2/errors.h 2011-05-11 00:40:07 +03: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
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
c6e65acae6 Properly check strtol for errors
We are now using a custom `strtol` implementation to make sure we're not
missing any overflow errors.
2011-04-09 15:22:11 -07:00
Carlos Martín Nieto
c7db45e862 Match the comment with the error string
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-29 19:58:18 +03:00
Carlos Martín Nieto
baad182cbc Add GIT_EEXISTS error code
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-03-29 19:58:18 +03:00
Jakob Pfender
c585f55ff4 common.h: Fix minor typos
Fix a few minor typos in the documentation of the GIT_ERROR codes.
2011-03-23 18:55:41 +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
955f9ae9bd Export git_strarray_free instead of inlining
That way non-C bindings can use it.
2011-03-16 01:06:15 +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
71d33382a7 Move the external includes folder from src to include
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-03-03 20:23:53 +02:00