Commit Graph

220 Commits

Author SHA1 Message Date
Russell Belfer
74fa4bfae3 Update diff to use iterators
This is a major reorganization of the diff code.  This changes
the diff functions to use the iterators for traversing the
content.  This allowed a lot of code to be simplified.  Also,
this moved the functions relating to outputting a diff into a
new file (diff_output.c).

This includes a number of other changes - adding utility
functions, extending iterators, etc. plus more tests for the
diff code.  This also takes the example diff.c program much
further in terms of emulating git-diff command line options.
2012-03-02 15:49:29 -08:00
Vicent Martí
13224ea4aa buffer: Unify git_fbuffer and git_buf
This makes so much sense that I can't believe it hasn't been done
before. Kill the old `git_fbuffer` and read files straight into
`git_buf` objects.

Also: In order to fully support 4GB files in 32-bit systems, the
`git_buf` implementation has been changed from using `ssize_t` for
storage and storing negative values on allocation failure, to using
`size_t` and changing the buffer pointer to a magical pointer on
allocation failure.

Hopefully this won't break anything.
2012-02-27 05:30:07 +01:00
Russell Belfer
b6c93aef42 Uniform iterators for trees, index, and workdir
This create a new git_iterator type of object that provides a
uniform interface for iterating over the index, an arbitrary
tree, or the working directory of a repository.

As part of this, git ignore support was extended to support
push and pop of directory-based ignore files as the working
directory is being traversed (so the array of ignores does
not have to be recreated at each directory during traveral).

There are a number of other small utility functions in buffer,
path, vector, and fileops that are included in this patch
that made the iterator implementation cleaner.
2012-02-21 14:46:24 -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
15debaf5da Fix bug in dir_for_path
The last checkin accidentally broke dir_for_path by propogating
the dirname return code even when there was no error.
2012-01-11 17:28:25 -08:00
Russell Belfer
6a67a812c2 Allow ignores (and attribs) for nonexistent files
This fixes issue 532 that attributes (and gitignores) could not
be checked for files that don't exist.  It should be possible to
query such things regardless of the existence of the file.
2012-01-11 16:01:48 -08:00
Russell Belfer
df743c7d3a Initial implementation of gitignore support
Adds support for .gitignore files to git_status_foreach() and
git_status_file().  This includes refactoring the gitattributes
code to share logic where possible.  The GIT_STATUS_IGNORED flag
will now be passed in for files that are ignored (provided they
are not already in the index or the head of repo).
2012-01-11 14:39:51 -08:00
nulltoken
f46e622636 Fix Windows specific off-by-one error
The value returned by MultiByteToWideChar includes the NULL termination character.
2012-01-04 21:15:12 +01:00
Russell Belfer
73b51450a3 Add support for macros and cache flush API.
Add support for git attribute macro definitions.  Also, add
support for cache flush API to clear the attribute file content
cache when needed.

Additionally, improved the handling of global and system files,
making common utility functions in fileops and converting config
and attr to both use the common functions.

Adds a bunch more tests and fixed some memory leaks.  Note that
adding macros required me to use refcounted attribute assignment
definitions, which complicated, but probably improved memory usage.
2011-12-29 00:01:10 -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
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
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
Brodie Rao
33127043b3 fileops/posix: replace usage of "int mode" with "mode_t mode"
Note: Functions exported from fileops take const mode_t, while the
underlying POSIX wrappers take mode_t.
2011-10-14 15:57:15 -07:00
Carlos Martín Nieto
dd44887ac6 Implment p_access and use it in git_fileutils_exists
Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
2011-09-23 00:00:05 +02: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
f978b748bb compat: Move mkstemp to the POSIX compat layer 2011-08-30 13:34:14 +02:00
Carlos Martín Nieto
c3da9f062d Add git_futils_readbuffer_updated
This extends the git_fuitls_readbuffer function to only read in if the
file's modification date is later than the given one. Some code paths
want to check a file's modification date in order to decide whether
they should read it or not. If they do want to read it, another stat
call is done by futils. This function combines these two operations so
we avoid one stat call each time we read a new or updated file.

The git_futils_readbuffer functions is now a wrapper around the new
function.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
2011-07-23 14:30:40 +02:00
Vicent Marti
858dba58bf refs: Cleanup reference renaming
`git_futils_rmdir_r`: rename, clean up.

`git_reference_rename`: cleanup. Do not use 3x4096 buffers on the stack
or things will get ugly very fast. We can reuse the same buffer.
2011-07-06 18:08:13 +02:00
nulltoken
1b938a5826 Remove duplicated recursive directory removal related code 2011-07-06 12:25:27 +02:00
nulltoken
1ee5fd903d Fix windows specific issues
- msvc compilation warnings
 - not released file handle that prevents file removal
2011-07-06 12:25:27 +02:00
schu
42b3a46097 fileops: add git_futils_rmdir_recurs()
git_futils_rmdir_recurs() shall remove the given directory and all
subdirectories. This happens only if the directories are empty.

Signed-off-by: schu <schu-github@schulog.org>
2011-07-06 12:25:27 +02:00
schu
e190da78f3 fileops: add convenience function is_dot_or_dotdot()
Signed-off-by: schu <schu-github@schulog.org>
2011-07-06 12:25:27 +02:00
Vicent Marti
eec3fe394a fileutils: Finish dropping the old prettify_path 2011-07-05 02:09:05 +02:00
Vicent Marti
19ac1ed702 fileops: Fix stat() on directories for W32
The `stat` methods were having issues when called with a trailing slash
in Windows platforms.

We now use GetFileAttributes() where possible, which doesn't have this
restriction.
2011-07-05 02:08:09 +02:00
Vicent Marti
5ad739e832 fileops: Drop git_fileops_prettify_path
The old `git_fileops_prettify_path` has been replaced with
`git_path_prettify`. This is a much simpler method that uses the OS's
`realpath` call to obtain the full path for directories and resolve
symlinks.

The `realpath` syscall is the original POSIX call in Unix system and
an emulated version under Windows using the Windows API.
2011-07-05 02:06:26 +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
nulltoken
6ac91dfe52 Hide ".git" directory on Windows upon creation of a non bare repository
Directory which name starts with a dot are hidden on Linux platforms. This patch makes libgit2 behaves similarly on Windows.
2011-06-29 19:22:24 +02:00
Vicent Marti
ab7941b5d9 test: Properly show error messages 2011-06-28 21:10:51 +02:00
schu
28f7869dee gitfo_read: fix read-loop
Signed-off-by: schu <schu-github@schulog.org>
2011-06-20 17:28:59 +02:00
Vicent Marti
e35e9fb4c3 mingw: Fix compilation 2011-06-18 13:23:19 +02:00
Vicent Marti
02285482f1 fileops: Cast the GetProcAddress value 2011-06-17 19:19:30 +02:00
Vicent Marti
9c11bd0a06 fileops: Fix 'GetFinalPathNameByHandleA' in old platforms 2011-06-17 19:09:18 +02:00
Vicent Martí
f2bb894e64 Merge pull request #251 from nulltoken/fix/msvc-warnings
Fix compilation warnings in MSVC
2011-06-15 12:15:11 -07:00
nulltoken
a64bf21bbb blob: Fix git_blob_create_fromfile() 2011-06-15 21:10:10 +02:00
nulltoken
63fadf99dc Add mode_t definition in MSVC compat layer 2011-06-15 19:45:33 +02:00
nulltoken
9e3aa94764 Fix compilation warnings in MSVC 2011-06-12 07:37:50 +02:00
Sebastian Schuberth
3f66c20202 Use "__inline" instead of "inline" with MSVC
MSVC supports "inline" only in C++ code, not in C code.
2011-06-10 13:57:01 +02:00
Sebastian Schuberth
535ff384e2 Prefer to use S_IFLNK instead of _S_IFLNK for consistency 2011-06-10 13:54:47 +02:00
Vicent Marti
ae496955d2 windows: Fix Symlink issues
Handle Symlinks if they can be handled in Win32. This is not even
compiled. Needs review.

The lstat implementation is modified from core Git.
The readlink implementation is modified from PHP.
2011-06-08 17:03:41 +02:00
Vicent Martí
3a12891f53 Merge pull request #243 from jpfender/symlinks2
Symlinks NEW
2011-06-07 07:07:45 -07:00
Vicent Martí
275c6a0b37 Merge pull request #242 from schu/fix-unused-2
fileops.c: fix unused warning v2
2011-06-07 07:03:14 -07:00
Jakob Pfender
fdd1e04ce7 fileops: Allow differentiation between deep and shallow exists()
When calling gitfo_exists() on a symbolic link, sometimes we need to
simply check whether the link exists and sometimes we need to check
whether the file pointed to by the symlink exists.

Introduce a new function gitfo_shallow_exists that only checks if the
link exists and revert gitfo_exists to the original functionality of
checking whether the file pointed to by the link exists.
2011-06-07 14:10:06 +02:00
Jakob Pfender
1869b31e0c index/fileops: Correctly process symbolic links
gitfo_exists() used to error out if the given file was a symbolic link,
due to access() returning an error code. This is not expected behaviour,
as gitfo_exists() should only check whether the file itself exists, not
its link target if it is a symbolic link.

Fix this by calling gitfo_lstat() instead, which is just a wrapper for
lstat().

Also fix the same error in index_init_entry().
2011-06-07 12:54:37 +02:00
schu
05b49b02ef fileops.c: fix unused warning
Signed-off-by: schu <schu-github@schulog.org>
2011-06-06 12:17:58 +02:00
Romain Geissler
a993e4fe06 Fileops: Fixed gitfo_mkdir_recurs so that it proprely works with a path without trailing slash.
It used to discard the last directory if the path didn't have a trailing slash.
2011-06-05 00:20:35 +02:00
Romain Geissler
f2e6b8776e Repository: Added some util functions that we'll need to discover repository path.
retrieve_device returns the file device for a given path (so that we can detect device change while walking through parent directories).
abspath returns a canonicalized path, symbolic link free.
retrieive_ceiling_directories_offset returns the biggest path offset that path match in the ceiling directory list (so that we can stop at ceiling directories).
2011-06-04 00:00:28 +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
Romain Geissler
bc6484912e Fileops: Added gitfo_isfile.
Conflicts:

	src/fileops.c
2011-06-03 21:20:20 +02:00
unknown
26a98ec8a2 Fileops: Added a fourth argument to the path prettifying functions to use an alternate basepath.
Fixed a Windows TO-DO in the prettifying functions.
2011-06-03 21:04:02 +02:00
Romain Geissler
04fdc10d35 Fileops:retrieve_path_root_offset is now named gitfo_retrieve_path_root_offset (like other public functions). Added platform specific directory separator definition. 2011-06-03 19:26:45 +02:00
schu
f5a86fefa9 gitfo_isdir: fix error message
Signed-off-by: schu <schu-github@schulog.org>
2011-05-29 17:44:14 +02:00
Vicent Marti
d3ca89fe60 fileops: Cleanup 2011-05-23 21:03:01 +03:00
Jakob Pfender
cc2ac058b3 fileops.c: Move to new error handling mechanism 2011-05-23 21:00:40 +03:00
nulltoken
77c3999ca9 Move fileops.c to the new error handling 2011-05-14 14:46:22 +02: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
7c80c19e1d Fix compilation in MinGW 2011-03-23 01:58:18 +02:00
nulltoken
3644e98fd9 Fix detection of attempt to escape the root directory on Windows 2011-03-23 00:17:25 +02:00
nulltoken
c90292ce4f Change gitfo_prettify_dir_path() and gitfo_prettify_file_path() behavior
Those functions now return prettified rooted path.
2011-03-23 00:17:24 +02:00
nulltoken
677a3c07f4 Add failing test for issue 84
see https://github.com/libgit2/libgit2/issues#issue/84
2011-03-23 00:17:24 +02:00
nulltoken
ae6ba7f713 Fix gitfo_mv() behavior when running on Windows
When the system temporary folder is located on a different volume than the working directory into which libgit2 is executing, MoveFileEx() requires an additional flag.
2011-03-23 00:08:16 +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
ccef1c9dc2 Move the path comparison method to fileops.c
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-03-03 20:23:50 +02:00
Vicent Marti
7360122ba9 Fix file renaming in MinGW
We now use MoveFileEx, which is not assured to be atomic but works for
always (both if the destination exists, or if it doesn't) and is
available in MinGW.

Since this is a Win32 API call, complaint about lost or overwritten files
should be forwarded at Steve Ballmer.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-24 23:53:40 +02:00
Vicent Marti
3eb47c9f67 Fix renaming of files in Win32
The `rename` call doesn't quite work on Win32: expects the destination
file to not exist. We're using a native Win32 call in those cases --
that should do the trick.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2011-02-24 21:43:08 +02:00
nulltoken
f2c2471389 Made path prettifying functions return GIT_EINVALIDPATH instead of GIT_ERROR. 2011-01-29 03:29:41 +02:00
nulltoken
2e6fd09c5d Fixed naming convention related issue. 2011-01-29 03:29:33 +02:00
nulltoken
618818dcb7 Added git_prettify_file_path(). 2011-01-29 03:29:32 +02:00
nulltoken
4581c22abc Optimized git_prettify_dir_path() parsing. 2011-01-29 03:29:32 +02:00
nulltoken
ae7ffea961 Fixed a parsing issue in git_prettify_dir_path(). 2011-01-29 03:29:32 +02:00
nulltoken
e16c2f6a4c Small enhancements to git_prettify_dir_path().
- Secured buffer ahead reading.
 - Guard against potential multiple dot path traversal (cf http://cwe.mitre.org/data/definitions/33.html)
2011-01-20 13:03:49 -08:00
Vicent Marti
b5e567b9fc Merge branch 'dir-path-prettifying' of https://github.com/nulltoken/libgit2 2011-01-19 17:18:01 -08:00
nulltoken
170d3f2fbb Added git_prettify_dir_path().
Clean up a provided absolute or relative directory path.

This prettification relies on basic operations such as coalescing multiple forward slashes into a single slash, removing '.' and './' current directory segments, and removing parent directory whenever '..' is encountered. If not empty, the returned path ends with a forward slash.

For instance, this will turn "d1/s1///s2/..//../s3" into "d1/s3/".

This only performs a string based analysis of the path. No checks are done to make sure the path actually makes sense from the file system perspective.
2011-01-11 20:12:53 +01:00
Alex Budovski
f0bde7fac0 Revised platform types to use 'best supported' size.
This will allow graceful migration to 64 bit file sizes and timestamps should
git's binary interface be extended to allow this.
2011-01-11 18:31:55 +11:00
Vicent Marti
d5f2520413 Merge branch 'repo-init' of https://github.com/nulltoken/libgit2 into nulltoken-repo-init 2011-01-03 21:41:19 +02:00
nulltoken
951d06e4e9 Fixed placement of pointer argument. 2010-12-26 17:00:35 +01:00
nulltoken
98e3b29895 Merge branch 'master' into repo-init 2010-12-23 09:22:15 +01:00
Vicent Marti
9f54fe482d Remove git_errno
It was not being used by any methods (only by malloc and calloc), and
since it needs to be TLS, it cannot be exported on DLLs on Windows.

Burn it with fire. The API always returns error codes!

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-12-23 00:15:09 +02:00
nulltoken
2c08c3f074 Made is_windows_rooted_path() able to cope with awkward but valid relative paths such as "C:..\File.txt".
Path "C:..\File.txt" refers to a file called File.txt located in the parent directory of the current directory on drive C:.
2010-12-21 06:52:07 +01:00
nulltoken
23a1edbd04 Wrapped the detection of a Windows rooted path within a conditional compilation directive. 2010-12-21 05:43:47 +01:00
nulltoken
2e29957a79 Made gitfo_mkdir_recurs() skip creation of the root of the path if it looks like a Windows drive. 2010-12-20 10:56:32 +01:00
nulltoken
412de9a637 Made gitfo_mkdir_recurs() gracefully recover when a given directory already exists. 2010-12-20 10:43:23 +01:00
Vicent Marti
40c44d2fb6 Fix issues in repository initialization
Implemented recursive directory creation
Fix style issues

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-12-19 22:50:20 +02:00
nulltoken
d13e7e02a8 Added a comment reminding that the gitfo_mkdir_recurs() is far from being fully implemented. 2010-12-17 15:58:30 +01:00
nulltoken
f0b2bfe527 Made gitfo_mkdir_recurs() more tolerant.
Doesn't err any more when the directory already exists.
2010-12-17 14:24:47 +01:00
nulltoken
1a5204a788 Added gitfo_mkdir_recurs() placeholder. 2010-12-17 10:08:01 +01:00
Vicent Marti
1f080e2da4 Fix initialization & freeing of inexistent repos
Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-12-13 03:43:56 +02:00
nulltoken
6f02c3bad8 Small source code readability improvements.
Replaced magic number "0" with GIT_SUCCESS constant wherever it made sense.
2010-12-05 20:18:56 +01:00
Vicent Marti
43e380a88c Fix gitfo_isdir() in Win32 systems
Because adhering to the POSIX standards is overrated.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-11-24 00:23:15 +02:00
Vicent Marti
6fd195d76c Change git_repository initialization to use a path
The constructor to git_repository is now called

	'git_repository_open(path)'

and takes a path to a git repository instead of an existing ODB object.
Unit tests have been updated accordingly and the two test repositories
have been merged into one.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
2010-11-02 18:42:42 +02:00
Ramsay Jones
3cc606359d Add some more (macro) file operation wrappers
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-04-30 09:47:58 +02:00
Ramsay Jones
e8a952561c msvc: Fix some -W4 warnings
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-01-20 20:20:47 +00:00
Ramsay Jones
803a6b4d41 Save the git_file in the gitfo_cache when enabling caching
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-01-20 20:17:56 +00:00
Ramsay Jones
90d4d2f0fc win32: Use an 64-bit file offset type
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
2010-01-20 20:15:57 +00:00
Ramsay Jones
4c9a397329 Improve the portability of the gitfo_cache code (to 64-bit systems)
This supresses some "conversion from 'size_t' to 'unsigned int',
possible loss of data" warning messages from the MS Visual C/C++
compiler with -Wp64.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2009-06-05 12:14:07 +02:00
Ramsay Jones
ca481fc4f1 Add the git_move_file() function
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2009-06-05 10:21:52 +02:00
Ramsay Jones
4d503f884a gitfo_exists: replace call to stat() with access()
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
2009-06-05 10:21:25 +02:00
Ramsay Jones
79ca2edcd4 win32: Add routines to abstract memory-mapped file functions
In particular, the git__mmap() and git__munmap() routines provide
the interface to platform specific memory-mapped file facilities.
We provide implementations for unix and win32, which can be found
in their own sub-directories.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-03-20 14:39:02 -07:00
Ramsay Jones
7a6cf81537 win32: Open or create files in binary mode
On windows, unless we use the O_BINARY flag in the open()
call, the file I/O routines will perform line ending
conversion (\r\n => \n on input, \n => \r\n on output).
In addition to the performance penalty, most files in the
object database are binary and will, therefore, become
corrupted by this conversion.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-03-17 19:10:51 -07:00
Ramsay Jones
840fb8b7cb win32: fixup some headers to improve win32 compilation
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-03-17 19:00:08 -07:00
Ramsay Jones
a9984a4e60 Fix some (digital-mars) compiler warnings
In particular, conditional expressions which contain an
assignment statement, where the expression type is not
explicitly made to be boolean, elicits the following
message:
    warning 2: possible unintended assignment

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-03-17 18:59:26 -07:00
Ramsay Jones
fc3c3a2083 Avoid using a gcc compiler language extension
In particular, using pointer arithmetic on void pointers,
despite being quite useful, is not legal in standard C.
Avoiding non-standard C constructs will help in porting
the library to other compilers/platforms.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-03-17 18:58:30 -07:00
Shawn O. Pearce
20e7f426c3 Add a simple mmap wrapper for cross-platform mmap usage
Win32 has a variant of mmap that is harder to use than POSIX, but
to run natively and efficiently on Win32 we need some form of it.

gitfo_map_ro() provides a basic mmap function for use in locations
where we need read-only random data access to large ranges of a file,
such as a pack-*.idx.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2009-01-03 01:16:02 -08:00
Shawn O. Pearce
7350e6337a Define gitfo_exists to determine file presence
When scanning the pack directory we need to see if the path
name is present for ".idx" when we discover a ".pack" file.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-12-31 16:07:38 -08:00
Shawn O. Pearce
5690f02e87 Rewrite git_foreach_dirent into gitfo_dirent
Our fileops API is currently private.  We aren't planning on supplying
a cross-platform file API to applications that link to us.  If we did,
we'd probably whole-sale publish fileops, not just the dirent code.

By moving it to be private we can also change the call signature to
permit the buffer to be passed down through the call chain.  This is
very helpful when we are doing a recursive scan as we can reuse just
one buffer in all stack frames, reducing the impact the recursion has
on the stack frames in the data cache.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-12-31 15:35:36 -08:00
Shawn O. Pearce
7dd8a9f710 Set GIT_EOSERR when the OS errno should be consulted
This error code indicates the OS error code has a better value
describing the last error, as it is likely a network or local
file IO problem identified by a C library function call.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-12-30 23:29:23 -08:00
Shawn O. Pearce
64a47c0142 Wrap malloc and friends and report out of memory as GIT_ENOMEM
We now forbid direct use of malloc, strdup or calloc within the
library and instead use wrapper functions git__malloc, etc. to
invoke the underlying library malloc and set git_errno to a no
memory error code if the allocation fails.

In the future once we have pack objects in memory we are likely
to enhance these routines with garbage collection logic to purge
cached pack data when allocations fail.  Because the size of the
function will grow somewhat large, we don't want to mark them for
inline as gcc tends to aggressively inline, creating larger than
expected executables.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-12-30 23:28:30 -08:00
Julio Espinoza-Sokal
213e720ca8 Change usages of static inline to GIT_INLINE
Signed-off-by: Julio Espinoza-Sokal <julioes@gmail.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-12-30 21:52:07 -08:00
Ramsay Jones
42fd40db68 Fix a bug in gitfo_read_file()
In particular, when asked to read an empty file, this function
calls malloc() with a zero size allocation request. Standard C
says that the behaviour of malloc() in this case is implementation
defined.

[C99, 7.20.3 says "... If the size of the space requested is zero,
the behavior is implementation-defined: either a null pointer is
returned, or the behavior is as if the size were some nonzero
value, except that the returned pointer shall not be used to
access an object."]

Finesse the issue by over-allocating by one byte. Setting the extra
byte to '\0' may also provide a useful sentinel for text files.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-12-30 07:32:16 -08:00
Ramsay Jones
75d5843055 Add a file reading routine along with an io buffer type
In particular, the gitfo_read_file() routine can be used to slurp
the complete file contents into an gitfo_buf structure. The buffer
content will be allocated by malloc() and may be released by the
gitfo_free_buf() routine. The io buffer type can be initialised
on the stack with the GITFO_BUF_INIT macro.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-12-19 07:21:20 -08:00
Ramsay Jones
5ee2fe777c Add a GIT_PATH_MAX constant
The PATH_MAX symbol is often, but not always, defined
in the <limits.h> header.  In particular, on cygwin you
need to include this header to avoid a compilation error.

However, some systems define PATH_MAX to be something as
small as 256, which POSIX is happy to allow, while others
allow much larger values.  In general it can vary from
one filesystem to another.

In order to avoid the vagaries of different systems, define
our own symbol.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-12-09 08:37:52 -08:00
Andreas Ericsson
ea790f337b Add a dirent walker to the fileops API
Since at least MS have something like GetFirstDirEnt() and
GetNextDirEnt() (presumably with superior performance), we
can let MS hackers add support for a dirent walker using
that API instead, while we stick with the posix-style
readdir() calls.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-12-02 09:18:19 -08:00
Andreas Ericsson
4188d28f1c Add an io caching layer to the gitfo api
The idea is taken from Junio's work in read-cache.c, where
it's used for writing out the index without tap-dancing on
the poor harddrive. Since it's almost certainly useful for
cached writing of packfiles too, we turn it into a generic
API, making it perfectly simple to reuse it later.

gitfo_write_cached() has the same contract as gitfo_write(), it
returns GIT_SUCCESS if all bytes are successfully written (or were
at least buffered for later writing), and <0 if an error occurs
during buffer writing.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-12-02 09:17:42 -08:00
Andreas Ericsson
ec250c6e18 Remove config.h and make fileops an internal API
Since it doesn't make sense to make the disk access stuff
portable *AND* public (that's a job for each application
imo), we can take a shortcut and just support unixy stuff
for now and get away with coding most of it as macros.

Since we go with an internal API for starters and only
provide higher-level API's to the libgit users, we'll be
ok with this approach.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-12-02 09:17:23 -08:00