Commit Graph

61 Commits

Author SHA1 Message Date
Carlos Martín Nieto
969d4b703c object: correct the expected ID size in prefix lookup
We take in a possibly partial ID by taking a length and working off of
that to figure out whether to just look up the object or ask the
backends for a prefix lookup.

Unfortunately we've been checking the size against `GIT_OID_HEXSZ` which
is the size of a *string* containing a full ID, whereas we need to check
against the size we can have when it's a 20-byte array.

Change the checks and comment to use `GIT_OID_RAWSZ` which is the
correct size of a git_oid to have when full.
2015-06-10 10:59:56 +02:00
Carlos Martín Nieto
753e17b0f5 peel: reject bad queries with EINVALIDSPEC
There are some combination of objects and target types which we know
cannot be fulfilled. Return EINVALIDSPEC for those to signify that there
is a mismatch in the user-provided data and what the object model is
capable of satisfying.

If we start at a tag and in the course of peeling find out that we
cannot reach a particular type, we return EPEEL.
2014-11-22 18:55:22 +01:00
Carlos Martín Nieto
6e9afb97d1 object: fix a brace
The brace in the check for peel's return was surrounding the wrong
thing, which made 'error' be set to 1 when there was an error instead of
the error code.
2014-05-06 21:29:55 +02:00
Russell Belfer
13f7ecd7b9 Add git_object_short_id API to get short id string
This finds a short id string that will unambiguously select the
given object, starting with the core.abbrev length (usually 7)
and growing until it is no longer ambiguous.
2014-03-04 16:23:28 -08:00
Edward Thomson
4f46a98b6e Remove now-duplicated stdarg.h include 2014-02-24 23:32:25 -08:00
Ben Straub
ba02079f2d Avoid temporary object in lookup routine 2013-10-28 05:01:33 -07:00
Ben Straub
ceab4e2606 Port blame from git.git 2013-09-16 16:23:50 -07:00
Linquize
e583334c00 Fix broken build when MSVC SDL checks is enabled 2013-05-11 20:13:26 +08:00
Russell Belfer
0cce210a54 Use assert for peel target type check 2013-05-02 10:36:58 -07:00
Russell Belfer
8915a140cb Report a couple object error conditions 2013-05-01 14:23:01 -07:00
Russell Belfer
3f27127d15 Simplify object table parse functions
This unifies the object parse functions into one signature that
takes an odb_object.
2013-04-22 16:52:06 +02:00
Russell Belfer
786062639f Add callback to git_objects_table
This adds create and free callback to the git_objects_table so
that more of the creation and destruction of objects can be table
driven instead of using switch statements.  This also makes the
semantics of certain object creation functions consistent so that
we can make better use of function pointers.  This also fixes a
theoretical error case where an object allocation fails and we
end up storing NULL into the cache.
2013-04-22 16:51:40 +02:00
Vicent Marti
cf7850a4f7 Duplicated type object 2013-04-22 16:50:50 +02:00
Vicent Marti
8842c75f17 What has science done. 2013-04-22 16:50:50 +02:00
Vicent Marti
c4e91d4500 Random eviction 2013-04-22 16:50:50 +02:00
Vicent Marti
5df184241a lol this worked first try wtf 2013-04-22 16:50:50 +02:00
Vicent Marti
575a54db85 object: Export git_object_dup 2013-04-10 16:56:32 +02:00
Edward Thomson
359fc2d241 update copyrights 2013-01-08 17:31:27 -06:00
nulltoken
bc05f30c47 object: refine git_object_peel() error report 2012-12-01 08:34:29 +01:00
Philip Kelley
ac22d08f2f Remove git_object_oid2type 2012-11-29 08:22:15 -05:00
Philip Kelley
613d5eb939 Push! By schu, phkelley, and congyiwu, et al 2012-11-28 11:42:37 -05:00
Vicent Marti
ae20189170 object: Raise proper code on invalid object type 2012-11-28 11:47:38 +01:00
Vicent Marti
cfbe4be3fb More external API cleanup
Conflicts:
	src/branch.c
	tests-clar/refs/branches/create.c
2012-11-27 13:18:27 -08:00
nulltoken
5cec896a3b repo: Make git_repository_head_tree() return error codes 2012-11-22 18:51:06 +01:00
Russell Belfer
c6ac28fdc5 Reorg internal odb read header and object lookup
Often `git_odb_read_header` will "fail" and have to read the
entire object into memory instead of just the header.  When this
happens, the object is loaded and then disposed of immediately,
which makes it difficult to efficiently use the header information
to decide if the object should be loaded (since attempting to do
so will often result in loading the object twice).

This commit takes the existing code and reorganizes it to have
two new functions:

- `git_odb__read_header_or_object` which acts just like the old
  read header function except that it returns the object, too, if
  it was forced to load the whole thing.  It then becomes the
  callers responsibility to free the `git_odb_object`.
- `git_object__from_odb_object` which was extracted from the old
  `git_object_lookup` and creates a subclass of `git_object` from
  an existing `git_odb_object` (separating the ODB lookup from the
  `git_object` creation).  This allows you to use the first header
  reading function efficiently without instantiating the
  `git_odb_object` twice.

There is no net change to the behavior of any of the existing
functions, but this allows internal code to tap into the ODB
lookup and object creation to be more efficient.
2012-09-10 12:24:05 -07:00
Russell Belfer
d8057a5b0e Make git_object_peel a bit smarter
This expands the types of peeling that `git_object_peel` knows
how to do to include TAG -> BLOB peeling, and makes the errors
slightly more consistent depending on the situation.  It also
adds a new special behavior where peeling to ANY will peel until
the object type changes (e.g. chases TAGs to a non-TAG).

Using this expanded peeling, this replaces peeling code that was
embedded in `git_tag_peel` and `git_reset`.
2012-08-27 11:53:59 -07:00
nulltoken
b8457baae2 portability: Improve x86/amd64 compatibility 2012-07-24 16:10:12 +02:00
nulltoken
db9be9457d object: introduce git_object_peel()
Partially fix #530
2012-07-17 20:32:40 +02:00
Michael Schubert
f95121cb4f object: add missing git_odb_object_free 2012-06-21 10:33:24 +02:00
Vicent Martí
904b67e69f errors: Rename error codes 2012-05-18 01:48:50 +02:00
Vicent Martí
e172cf082e errors: Rename the generic return codes 2012-05-18 01:26:26 +02:00
nulltoken
e28c37761b object: make git_object_lookup() return GIT_ENOTFOUND when searching for an existing object by specifying an incorrect type
This fix complements cb0ce16bbe and cover the following additional use cases

 - retrieving an object which has been previously searched, found and cached
 - retrieving an object through an non ambiguous abbreviated id
2012-05-11 23:56:23 +02:00
nulltoken
cb0ce16bbe object: make git_object_lookup() return GIT_ENOTFOUND when searching for an existing object by specifying an incorrect type 2012-05-08 10:05:14 +02:00
Russell Belfer
282283acc6 Fix valgrind issues
There are three changes here:
- correctly propogate error code from failed object lookups
- make zlib inflate use our allocators
- add OID to notfound error in ODB lookups
2012-05-04 16:46:46 -07:00
Russell Belfer
f917481ee8 Support reading attributes from index
Depending on the operation, we need to consider gitattributes
in both the work dir and the index.  This adds a parameter to
all of the gitattributes related functions that allows user
control of attribute reading behavior (i.e. prefer workdir,
prefer index, only use index).

This fix also covers allowing us to check attributes (and
hence do diff and status) on bare repositories.

This was a somewhat larger change that I hoped because it had
to change the cache key used for gitattributes files.
2012-05-03 16:37:25 -07:00
Vicent Martí
3fbcac89c4 Remove old and unused error codes 2012-05-02 19:56:38 -07:00
Carlos Martín Nieto
3aa351ea0f error handling: move the missing parts over to the new error handling 2012-04-26 15:38:42 +02:00
Russell Belfer
e1de726c15 Migrate ODB files to new error handling
This migrates odb.c, odb_loose.c, odb_pack.c and pack.c to
the new style of error handling.  Also got the unix and win32
versions of map.c.  There are some minor changes to other
files but no others were completely converted.

This also contains an update to filebuf so that a zeroed out
filebuf will not think that the fd (== 0) is actually open
(and inadvertently call close() on fd 0 if cleaned up).

Lastly, this was built and tested on win32 and contains a
bunch of fixes for the win32 build which was pretty broken.
2012-03-12 22:55:40 -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
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
Vicent Marti
9462c47143 repository: Change ownership semantics
The ownership semantics have been changed all over the library to be
consistent. There are no more "borrowed" or duplicated references.

Main changes:

	- `git_repository_open2` and `3` have been dropped.

	- Added setters and getters to hotswap all the repository owned
	objects:

		`git_repository_index`
		`git_repository_set_index`
		`git_repository_odb`
		`git_repository_set_odb`
		`git_repository_config`
		`git_repository_set_config`
		`git_repository_workdir`
		`git_repository_set_workdir`

	Now working directories/index files/ODBs and so on can be
	hot-swapped after creating a repository and between operations.

	- All these objects now have proper ownership semantics with
	refcounting: they all require freeing after they are no longer
	needed (the repository always keeps its internal reference).

	- Repository open and initialization has been updated to keep in
	mind the configuration files. Bare repositories are now always
	detected, and a default config file is created on init.

	- All the tests affected by these changes have been dropped from the
	old test suite and ported to the new one.
2011-11-26 08:37:08 +01: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
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
Lambert CLARA
7d3ec3caac Fix memory leak when wrong object type is looked up from cache
Update unit test accordingly : no need to close
2011-08-02 19:23:00 +02:00
Vicent Marti
d0323a5f63 short-oid: Cleanup 2011-06-01 23:40:42 +02:00
Marc Pegon
ac2b94ad76 Added a GIT_OID_MINPREFIXLEN constant to define the minimum length allowed for oid prefixes (set to 4, like in git). Consequently updated some object lookup methods and their documentation. 2011-06-01 23:40:41 +02:00
Marc Pegon
dd453c4dbf Added git.git sha1 lookup method to replace simple binary search in pack backend.
Implemented find_unique_short_oid for pack backend, based on git sha1 lookup method;
finding an object given its full oid is just a particular case of searching
the unique object matching an oid prefix (short oid).

Added git_odb_read_unique_short_oid, which iterates over all the backends to
find and read the unique object matching the given oid prefix.

Added a git_object_lookup_short_oid method to find the unique object in
the repository matching a given oid prefix : it generalizes git_object_lookup
which now does nothing but calls git_object_lookup_short_oid.
2011-06-01 23:40:41 +02:00
Vicent Marti
6623f5c91b object: Reword errors 2011-05-23 21:05:43 +03:00
Jakob Pfender
75eb97fed0 object.c: Move to new error handling mechanism 2011-05-23 21:04:19 +03:00