Commit Graph

39 Commits

Author SHA1 Message Date
Russell Belfer
ae9e29fde7 Migrating diff to new error handling
Ended up migrating a bunch of upstream functions as well
including vector, attr_file, and odb in order to get this
to work right.
2012-03-06 16:27:13 -08:00
Vicent Martí
1a48112342 error-handling: References
Yes, this is error handling solely for `refs.c`, but some of the
abstractions leak all ofer the code base.
2012-03-06 00:43:10 +01:00
Paul Betts
1db9d2c3bb Ensure that commits don't fail if committing content that already exists
Making a commit that results in a blob that already exists in the ODB (i.e.
committing something, then making a revert commit) will result in us trying
to p_rename -> MoveFileExW a temp file into the existing ODB entry. Despite
the MOVEFILE_REPLACE_EXISTING flag is passed in, Win32 does not care and
fails it with STATUS_ACCESS_DENIED.

To fix this, we p_unlink the ODB entry before attempting to rename it. This
call will typically fail, but we don't care, we'll let the p_rename fail if
the file actually does exist and we couldn't delete it for some reason (ACLs,
etc).
2012-02-23 17:11:20 -08:00
schu
5e0de32818 Update Copyright header
Signed-off-by: schu <schu-github@schulog.org>
2012-02-13 17:11:09 +01:00
Russell Belfer
1744fafec0 Move path related functions from fileops to path
This takes all of the functions that look up simple data about
paths (such as `git_futils_isdir`) and moves them over to path.h
(becoming `git_path_isdir`).  This leaves fileops.h just with
functions that actually manipulate the filesystem or look at
the file contents in some way.

As part of this, the dir.h header which is really just for win32
support was moved into win32 (with some minor changes).
2012-01-17 15:49:47 -08:00
Russell Belfer
97769280ba Use git_buf for path storage instead of stack-based buffers
This converts virtually all of the places that allocate GIT_PATH_MAX
buffers on the stack for manipulating paths to use git_buf objects
instead.  The patch is pretty careful not to touch the public API
for libgit2, so there are a few places that still use GIT_PATH_MAX.

This extends and changes some details of the git_buf implementation
to add a couple of extra functions and to make error handling easier.

This includes serious alterations to all the path.c functions, and
several of the fileops.c ones, too.  Also, there are a number of new
functions that parallel existing ones except that use a git_buf
instead of a stack-based buffer (such as git_config_find_global_r
that exists alongsize git_config_find_global).

This also modifies the win32 version of p_realpath to allocate whatever
buffer size is needed to accommodate the realpath instead of hardcoding
a GIT_PATH_MAX limit, but that change needs to be tested still.
2011-12-07 23:08:15 -08:00
Russell Belfer
b762e576c6 filebuf: add GIT_FILEBUF_INIT and protect multiple opens and cleanups
Update all stack allocations of git_filebuf to use GIT_FILEBUF_INIT
and make git_filebuf_open and git_filebuf_cleanup safe to be called
multiple times on the same buffer.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-11-22 01:53:56 +01:00
Carlos Martín Nieto
0c49ec2d3b Implement p_rename
Move the callers of git_futils_mv_atomic to use p_rename.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
2011-11-07 20:34:27 +01:00
Vicent Martí
89fb8f025a Merge pull request #456 from brodie/perm-fixes
Create objects, indexes, and directories with the right file permissions
2011-10-28 19:04:23 -07: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
Brodie Rao
01ad7b3a9e *: correct and codify various file permissions
The following files now have 0444 permissions:

- loose objects
- pack indexes
- pack files
- packs downloaded by fetch
- packs downloaded by the HTTP transport

And the following files now have 0666 permissions:

- config files
- repository indexes
- reflogs
- refs

This brings libgit2 more in line with Git.

Note that git_filebuf_commit() and git_filebuf_commit_at() have both
gained a new mode parameter.

The latter change fixes an important issue where filebufs created with
GIT_FILEBUF_TEMPORARY received 0600 permissions (due to mkstemp(3)
usage). Now we chmod() the file before renaming it into place.

Tests have been added to confirm that new commit, tag, and tree
objects are created with the right permissions. I don't have access to
Windows, so for now I've guarded the tests with "#ifndef GIT_WIN32".
2011-10-14 16:07:47 -07:00
Brodie Rao
ce8cd006ce fileops/repository: create (most) directories with 0777 permissions
To further match how Git behaves, this change makes most of the
directories libgit2 creates in a git repo have a file mode of
0777. Specifically:

- Intermediate directories created with git_futils_mkpath2file() have
  0777 permissions. This affects odb_loose, reflog, and refs.

- The top level folder for bare repos is created with 0777
  permissions.

- The top level folder for non-bare repos is created with 0755
  permissions.

- /objects/info/, /objects/pack/, /refs/heads/, and /refs/tags/ are
  created with 0777 permissions.

Additionally, the following changes have been made:

- fileops functions that create intermediate directories have grown a
  new dirmode parameter. The only exception to this is filebuf's
  lock_file(), which unconditionally creates intermediate directories
  with 0777 permissions when GIT_FILEBUF_FORCE is set.

- The test runner now sets the umask to 0 before running any
  tests. This ensurses all file mode checks are consistent across
  systems.

- t09-tree.c now does a directory permissions check. I've avoided
  adding this check to other tests that might reuse existing
  directories from the prefabricated test repos. Because they're
  checked into the repo, they have 0755 permissions.

- Other assorted directories created by tests have 0777 permissions.
2011-10-14 16:04:34 -07:00
Vicent Marti
c103d7b4b7 odb: Pass compression settings to filebuf 2011-09-29 15:49:28 +02:00
Vicent Martí
3125929bc4 Merge pull request #393 from schu/unused-but-set-variable
filebuf.c: fix unused-but-set warning
2011-09-18 19:54:18 -07: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
schu
c8f16bfef9 filebuf.c: fix unused-but-set warning
write_deflate() used to ignore errors by zlib's deflate function when
not compiling in DEBUG mode. Always read $result and throw an error
instead.

Signed-off-by: schu <schu-github@schulog.org>
2011-09-09 16:59:28 +02:00
Sebastian Schuberth
1c3fac4d5e Add casts to get rid of some warnings when filling zlib structures 2011-09-08 17:08:57 +02:00
Sebastian Schuberth
353560b440 Get rid of a superfluous pointer cast 2011-09-08 17:08:10 +02:00
Sebastian Schuberth
45e93ef34e Fix minor indentation issues (spaces to tabs) 2011-09-08 17:07:52 +02:00
Kirill A. Shutemov
05a62d1a82 filebuf: update git_filebuf.write signature to take non-const buffer
z_stream.next_in is non-const. Although currently Zlib doesn't modify
buffer content on deflate(), it might be change in the future. gzwrite()
already modify it.

To avoid this let's change signature of git_filebuf.write and rework
git_filebuf_write() accordingly.

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-07-25 21:12:48 +02:00
Vicent Marti
afeecf4f26 odb: Direct writes are back
DIRECT WRITES ARE BACK AND FASTER THAN EVER. The streaming writer to the
ODB was an overkill for the smaller objects like Commit and Tags; most
of the streaming logic was taking too long.

This commit makes Commits, Tags and Trees to be built-up in memory, and
then written to disk in 2 pushes (header + data), instead of streaming
everything.

This is *always* faster, even for big files (since the git_filebuf class
still does streaming writes when the memory cache overflows). This is
also a gazillion lines of code smaller, because we don't have to
precompute the final size of the object before starting the stream (this
was kind of defeating the point of streaming, anyway).

Blobs are still written with full streaming instead of loading them in
memory, since this is still the fastest way.

A new `git_buf` class has been added. It's missing some features, but
it'll get there.
2011-07-09 02:40:16 +02:00
Vicent Marti
2fc78e700c posix: Portable vsnprintf
Our good, lovely folks at Microsoft decided that there was no good
reason to make `vsnprintf` compilant with the C standard, so that
function in Windows returns -1 on overflow, instead of returning the
actual byte count needed to write the full string.

We now handle this situation more gracefully with the POSIX
compatibility layer, by returning the needed byte size using an
auxiliary method instead of blindly resizing the target buffer until it
fits.

This means we can now support `printf`s of any size by allocating a
temporary buffer. That's good.
2011-07-09 02:40:16 +02:00
Vicent Marti
f79026b491 fileops: Cleanup
Cleaned up the structure of the whole OS-abstraction layer.

fileops.c now contains a set of utility methods for file management used
by the library. These are abstractions on top of the original POSIX
calls.

There's a new file called `posix.c` that contains
emulations/reimplementations of all the POSIX calls the library uses.
These are prefixed with `p_`. There's a specific posix file for each
platform (win32 and unix).

All the path-related methods have been moved from `utils.c` to `path.c`
and have their own prefix.
2011-07-05 02:04:03 +02:00
Kirill A. Shutemov
932d1baf29 cleanup: remove trailing spaces
Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-07-01 18:02:56 +02:00
Kirill A. Shutemov
fe5babacd6 filebuf: fix endless loop on writing buf > WRITE_BUFFER_SIZE
Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
2011-06-30 16:19:19 +03:00
Carlos Martín Nieto
bb9272dd7a filebuf cleanup: only unlink lockfile if we've opened it
Add a check for the file descriptor in git_filebuf_cleanup. Without
it, an existing lockfile would be deleted if we tried to acquire it
(but failed, as the lockfile already existed).

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-06-07 17:05:40 +02:00
Vicent Marti
f9213015fd filebuf: Fix printf buffer overflows
The filebuf was not being properly written after a flush. This should
cut it now.

Fixes #228
2011-06-06 01:54:59 +02:00
Romain Geissler
1549cba9a4 Filebuf: Fixed a TODO in filebuf (real lock in lock_file)
Added gitfo_creat_locked and gitfo_creat_locked_force
2011-06-03 23:08:42 +02:00
Vicent Marti
f6328611dc filebuf: Reword errors 2011-05-23 21:00:19 +03:00
Jakob Pfender
374db5f912 filebuf.c: Move to new error handling mechanism 2011-05-23 20:45:19 +03:00
Vicent Marti
a6359408a5 Use Z_BEST_SPEED for filebuf deflating
This is what Git uses by default for all deflating.
2011-04-10 12:23:55 -07:00
Vicent Marti
f6f72d7ef8 Improve the ODB writing backend
Temporary files when doing streaming writes are now stored inside the
Objects folder, to prevent issues when moving files between
disks/partitions.

Add support for block writes to the ODB again (for those backends that
cannot implement streaming).
2011-03-23 18:44:53 +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
55ffebe377 Fix creation of deeply-rooted references
Use a new `gitfo_creat_force` that will create the full path to a file
before creating it.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-03-05 14:34:32 +02:00
Vicent Marti
19a30a3f6e Add new move function, gitfo_mv_force
Forces a move by creating the folder for the destination file, if it
doesn't exist.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-03-03 20:23:51 +02:00
Vicent Marti
86194b2433 Split packed from unpacked references
These two reference types are now stored separately to eventually allow
the removal/renaming of loose references and rewriting of the refs
packfile.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-03-03 20:23:49 +02:00
Vicent Marti
c3be146840 Fix double-freeing file descriptors
Was crashing the Windows build.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-24 19:31:12 +02:00
Vicent Marti
5591ea15a5 Add printf method to the File Buffer
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-22 15:19:23 +02:00
Vicent Marti
817c28201e Rewrite all file IO for more performance
The new `git_filebuf` structure provides atomic high-performance writes
to disk by using a write cache, and optionally a double-buffered scheme
through a worker thread (not enabled yet).

Writes can be done 3-layered, like in git.git (user code -> write cache
-> disk), or 2-layered, by writing directly on the cache. This makes
index writing considerably faster.

The `git_filebuf` structure contains all the old functionality of
`git_filelock` for atomic file writes and reads. The `git_filelock`
structure has been removed.

Additionally, the `git_filebuf` API allows to automatically hash (SHA1)
all the data as it is written to disk (hashing is done smartly on big
chunks to improve performance).

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-21 18:13:43 +02:00