summaryrefslogtreecommitdiff
path: root/src/fileops.c
Commit message (Collapse)AuthorAgeFilesLines
...
* I broke your bindingsVicent Marti2011-03-201-4/+86
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Fix creation of deeply-rooted referencesVicent Marti2011-03-051-17/+33
| | | | | | | 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>
* Add new move function, `gitfo_mv_force`Vicent Marti2011-03-031-1/+24
| | | | | | | Forces a move by creating the folder for the destination file, if it doesn't exist. Signed-off-by: Vicent Marti <tanoku@gmail.com>
* Move the path comparison method to fileops.cVicent Marti2011-03-031-0/+19
| | | | Signed-off-by: Vicent Marti <tanoku@gmail.com>
* Fix file renaming in MinGWVicent Marti2011-02-241-4/+2
| | | | | | | | | | | 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>
* Fix renaming of files in Win32Vicent Marti2011-02-241-0/+12
| | | | | | | | 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>
* Made path prettifying functions return GIT_EINVALIDPATH instead of GIT_ERROR.nulltoken2011-01-291-4/+4
|
* Fixed naming convention related issue.nulltoken2011-01-291-3/+3
|
* Added git_prettify_file_path().nulltoken2011-01-291-0/+27
|
* Optimized git_prettify_dir_path() parsing.nulltoken2011-01-291-21/+18
|
* Fixed a parsing issue in git_prettify_dir_path().nulltoken2011-01-291-26/+39
|
* Small enhancements to git_prettify_dir_path().nulltoken2011-01-201-2/+6
| | | | | - Secured buffer ahead reading. - Guard against potential multiple dot path traversal (cf http://cwe.mitre.org/data/definitions/33.html)
* Merge branch 'dir-path-prettifying' of https://github.com/nulltoken/libgit2Vicent Marti2011-01-191-0/+76
|\
| * Added git_prettify_dir_path().nulltoken2011-01-111-0/+77
| | | | | | | | | | | | | | | | | | | | 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.
* | Revised platform types to use 'best supported' size.Alex Budovski2011-01-111-3/+3
|/ | | | | This will allow graceful migration to 64 bit file sizes and timestamps should git's binary interface be extended to allow this.
* Merge branch 'repo-init' of https://github.com/nulltoken/libgit2 into ↵Vicent Marti2011-01-031-14/+40
|\ | | | | | | nulltoken-repo-init
| * Fixed placement of pointer argument.nulltoken2010-12-261-1/+1
| |
| * Merge branch 'master' into repo-initnulltoken2010-12-231-10/+10
| |\ | |/ |/|
| * Made is_windows_rooted_path() able to cope with awkward but valid relative ↵nulltoken2010-12-211-1/+1
| | | | | | | | | | | | 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:.
| * Wrapped the detection of a Windows rooted path within a conditional ↵nulltoken2010-12-211-3/+19
| | | | | | | | compilation directive.
| * Made gitfo_mkdir_recurs() skip creation of the root of the path if it looks ↵nulltoken2010-12-201-0/+5
| | | | | | | | like a Windows drive.
| * Made gitfo_mkdir_recurs() gracefully recover when a given directory already ↵nulltoken2010-12-201-1/+6
| | | | | | | | exists.
* | Remove git_errnoVicent Marti2010-12-231-10/+10
|/ | | | | | | | | 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>
* Fix issues in repository initializationVicent Marti2010-12-191-6/+23
| | | | | | | Implemented recursive directory creation Fix style issues Signed-off-by: Vicent Marti <tanoku@gmail.com>
* Added a comment reminding that the gitfo_mkdir_recurs() is far from being ↵nulltoken2010-12-171-0/+1
| | | | fully implemented.
* Made gitfo_mkdir_recurs() more tolerant.nulltoken2010-12-171-1/+8
| | | | Doesn't err any more when the directory already exists.
* Added gitfo_mkdir_recurs() placeholder.nulltoken2010-12-171-0/+5
|
* Fix initialization & freeing of inexistent reposVicent Marti2010-12-131-2/+7
| | | | Signed-off-by: Vicent Marti <tanoku@gmail.com>
* Small source code readability improvements.nulltoken2010-12-051-3/+3
| | | | Replaced magic number "0" with GIT_SUCCESS constant wherever it made sense.
* Fix gitfo_isdir() in Win32 systemsVicent Marti2010-11-241-1/+19
| | | | | | Because adhering to the POSIX standards is overrated. Signed-off-by: Vicent Marti <tanoku@gmail.com>
* Change git_repository initialization to use a pathVicent Marti2010-11-021-0/+7
| | | | | | | | | | | | 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>
* Add some more (macro) file operation wrappersRamsay Jones2010-04-301-1/+1
| | | | Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
* msvc: Fix some -W4 warningsRamsay Jones2010-01-201-1/+0
| | | | Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
* Save the git_file in the gitfo_cache when enabling cachingRamsay Jones2010-01-201-0/+1
| | | | Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
* win32: Use an 64-bit file offset typeRamsay Jones2010-01-201-3/+9
| | | | Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
* Improve the portability of the gitfo_cache code (to 64-bit systems)Ramsay Jones2009-06-051-1/+1
| | | | | | | | | 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>
* Add the git_move_file() functionRamsay Jones2009-06-051-0/+13
| | | | | Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Andreas Ericsson <ae@op5.se>
* gitfo_exists: replace call to stat() with access()Ramsay Jones2009-06-051-2/+1
| | | | | Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Andreas Ericsson <ae@op5.se>
* win32: Add routines to abstract memory-mapped file functionsRamsay Jones2009-03-201-6/+4
| | | | | | | | | | 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>
* win32: Open or create files in binary modeRamsay Jones2009-03-171-2/+2
| | | | | | | | | | | | 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>
* win32: fixup some headers to improve win32 compilationRamsay Jones2009-03-171-1/+0
| | | | | Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* Fix some (digital-mars) compiler warningsRamsay Jones2009-03-171-1/+1
| | | | | | | | | | | 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>
* Avoid using a gcc compiler language extensionRamsay Jones2009-03-171-2/+4
| | | | | | | | | | 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>
* Add a simple mmap wrapper for cross-platform mmap usageShawn O. Pearce2009-01-031-0/+15
| | | | | | | | | | | 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>
* Define gitfo_exists to determine file presenceShawn O. Pearce2008-12-311-0/+6
| | | | | | | 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>
* Rewrite git_foreach_dirent into gitfo_direntShawn O. Pearce2008-12-311-15/+9
| | | | | | | | | | | | | | 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>
* Set GIT_EOSERR when the OS errno should be consultedShawn O. Pearce2008-12-301-8/+20
| | | | | | | | 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>
* Wrap malloc and friends and report out of memory as GIT_ENOMEMShawn O. Pearce2008-12-301-6/+7
| | | | | | | | | | | | | | | | 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>
* Change usages of static inline to GIT_INLINEJulio Espinoza-Sokal2008-12-301-1/+1
| | | | | Signed-off-by: Julio Espinoza-Sokal <julioes@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* Fix a bug in gitfo_read_file()Ramsay Jones2008-12-301-2/+3
| | | | | | | | | | | | | | | | | | | 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>