Commit Graph

236 Commits

Author SHA1 Message Date
Russell Belfer
9cfce2735d Cleanups, renames, and leak fixes
This renames git_vector_free_all to the better git_vector_free_deep
and also contains a couple of memory leak fixes based on valgrind
checks.  The fixes are specifically: failure to free global dir
path variables when not compiled with threading on and failure to
free filters from the filter registry that had not be initialized
fully.
2013-12-12 12:11:38 -08:00
Russell Belfer
25e0b1576d Remove converting user error to GIT_EUSER
This changes the behavior of callbacks so that the callback error
code is not converted into GIT_EUSER and instead we propagate the
return value through to the caller.  Instead of using the
giterr_capture and giterr_restore functions, we now rely on all
functions to pass back the return value from a callback.

To avoid having a return value with no error message, the user
can call the public giterr_set_str or some such function to set
an error message.  There is a new helper 'giterr_set_callback'
that functions can invoke after making a callback which ensures
that some error message was set in case the callback did not set
one.

In places where the sign of the callback return value is
meaningful (e.g. positive to skip, negative to abort), only the
negative values are returned back to the caller, obviously, since
the other values allow for continuing the loop.

The hardest parts of this were in the checkout code where positive
return values were overloaded as meaningful values for checkout.
I fixed this by adding an output parameter to many of the internal
checkout functions and removing the overload.  This added some
code, but it is probably a better implementation.

There is some funkiness in the network code where user provided
callbacks could be returning a positive or a negative value and
we want to rely on that to cancel the loop.  There are still a
couple places where an user error might get turned into GIT_EUSER
there, I think, though none exercised by the tests.
2013-12-11 10:57:49 -08:00
Russell Belfer
96869a4edb Improve GIT_EUSER handling
This adds giterr_user_cancel to return GIT_EUSER and clear any
error message that is sitting around.  As a result of using that
in places, we need to be more thorough with capturing errors that
happen inside a callback when used internally.  To help with that,
this also adds giterr_capture and giterr_restore so that when we
internally use a foreach-type function that clears errors and
converts them to GIT_EUSER, it is easier to restore not just the
return value, but the actual error message text.
2013-12-11 10:57:49 -08:00
nulltoken
39b1ad7f15 Plug configuration file search paths leaks 2013-11-05 17:36:12 +01:00
Edward Thomson
1d3a8aeb4b move mode_t to filebuf_open instead of _commit 2013-11-04 22:33:05 -05:00
Edward Thomson
c2408a698a preserve windows error numbers as well 2013-11-01 17:27:07 -04:00
Vicent Martí
2c2b0ebb4a Merge pull request #1562 from libgit2/cmn/refs-namespace-lookup
Provide the user with a more useful error code when a looking up a reference which name points to a namepace
2013-10-11 09:47:05 -07:00
Carlos Martín Nieto
7c9f5bec51 futils: return GIT_ENOTFOUND when trying to read a directory
This lets the reference code return not-found when the user asks to
look up a reference when in fact they pass a namespace.
2013-10-11 16:29:59 +02:00
Russell Belfer
14997dc5f6 More filemode cleanups for FAT on MacOS
This cleans up some additional issues.  The main change is that
on a filesystem that doesn't support mode bits, libgit2 will now
create new blobs with GIT_FILEMODE_BLOB always instead of being
at the mercy to the filesystem driver to report executable or not.
This means that if "core.filemode" lies and claims that filemode
is not supported, then we will ignore the executable bit from the
filesystem.  Previously we would have allowed it.

This adds an option to the new git_repository_reset_filesystem to
recurse through submodules if desired.  There may be other types
of APIs that would like a "recurse submodules" option, but this
one is particularly useful.

This also has a number of cleanups, etc., for related things
including trying to give better error messages when problems come
up from the filesystem.  For example, the FAT filesystem driver on
MacOS appears to return errno EINVAL if you attempt to write a
filename with invalid UTF-8 in it.  We try to capture that with a
better error message now.
2013-10-08 12:45:43 -07:00
Russell Belfer
219d345732 Initial iconv hookup for precomposed unicode
This hooks up git_path_direach and git_path_dirload so that they
will take a flag indicating if directory entry names should be
tested and converted from decomposed unicode to precomposed form.
This code will only come into play on the Apple platform and even
then, only when certain types of filesystems are used.

This involved adding a flag to these functions which involved
changing a lot of places in the code.

This was an opportunity to do a bit of code cleanup here and there,
for example, getting rid of the git_futils_cleanupdir_r function in
favor of a simple flag to git_futils_rmdir_r to not remove the top
level entry.  That ended up adding depth tracking during rmdir_r
which led to a safety check for infinite directory recursion.  Yay.

This hasn't actually been tested on the Mac filesystems where the
issue occurs.  I still need to get test environment for that.
2013-10-03 10:44:13 -07:00
Vicent Martí
3d4f169867 Merge pull request #1858 from linquize/win32-template-dir
Configurable template dir for Win32
2013-09-17 10:21:22 -07:00
Russell Belfer
13f36ffb9e Add clar helpers for testing file equality
These are a couple of new clar helpers for testing that a file
has expected contents that I extracted from the checkout code.

Actually wrote this as part of an abandoned earlier attempt at a
new filters API, but it will be useful now for some of the tests
I'm going to write.
2013-09-17 09:31:46 -07:00
Russell Belfer
a3aa5f4d5d Add simple global shutdown hooks
Increasingly there are a number of components that want to do some
cleanup at global shutdown time (at least if there are not going
to be memory leaks).  This creates a very simple system of shutdown
hooks that will be invoked by git_threads_shutdown.  Right now, the
maximum number of hooks is hardcoded, but since adding a hook is
not a public API, it should be fine and I thought it was better to
start off with really simple code.
2013-09-17 09:31:45 -07:00
Linquize
a025907e0d Can load default template directory 2013-09-18 00:09:09 +08:00
Linquize
7e8934bba2 Can guess win32 git template dir 2013-09-17 23:29:02 +08:00
Linquize
f84bc38853 Refactor git_win32__find_system_dirs() to extract "etc\\" as subpath parameter 2013-09-17 23:28:16 +08:00
nulltoken
d0cd6c427a path: Make direach() return EUSER on callback error 2013-09-10 22:36:10 +02:00
Russell Belfer
f240acce86 Add more file mode permissions macros
This adds some more macros for some standard operations on file
modes, particularly related to permissions, and then updates a
number of places around the code base to use the new macros.
2013-09-05 11:20:12 -07:00
Carlos Martín Nieto
3d27687475 index: report when it's locked
Report the index being locked with its own error code in order to be
able to differentiate, as a locked index is typically the result of a
crashed process or concurrent access, both of which often require user
intervention to fix.
2013-08-19 10:30:44 +02:00
Vicent Martí
89f6d84ccf Merge pull request #1781 from brodie/brodie/stat-before-open
fileops: stat() before open()ing in git_futils_readbuffer_updated()
2013-08-14 06:40:38 -07:00
Brodie Rao
9ccdb21155 fileops: stat() before open()ing in git_futils_readbuffer_updated()
This reverts refactoring done in 13224ea4aa
that introduces a performance regression for NFS when reading files that
don't exist. open() forces a cache invalidation on NFS, while stat()ing a
file just uses the cache and is very quick.

To give a specific example, say you have a repo with a thousand packed
refs. Before this change, looking up every single one ould incur a thousand
slow open() calls. With this change, it's a thousand fast stat() calls.
2013-08-13 10:55:37 -07:00
Russell Belfer
d4cff0cb1c Rename git__win32_path fns to git_win32_path 2013-08-13 09:40:32 -07:00
Vicent Marti
abf3732728 windows: Path conversion with better semantics 2013-08-13 09:15:39 +02:00
Ben Straub
aaefbdeea2 Discriminate path-specific and general UTF-X conversions 2013-08-08 08:48:57 -07:00
Ben Straub
2c0128ee79 Rename git_win_str_utf* to git_win32_path_utf* 2013-08-07 19:29:33 -07:00
Ben Straub
9c38f7a652 Add typedefs for win32 utf-8 and utf-16 buffers
...and normalize the signatures of the two conversion functions.
2013-08-07 13:22:41 -07:00
Ben Straub
d85636190f Split UTF-16 and UTF-8 buffer sizes for win32
Also fixed up call-sites to use the correct buffer sizes, especially
when converting to utf-8.
2013-08-05 11:41:39 -07:00
Sven Strickroth
f5254d7844 Fix possible double close
Signed-off-by: Sven Strickroth <email@cs-ware.de>
2013-07-27 20:15:06 +02:00
Russell Belfer
989710d982 Fix warning message about mismatched types 2013-07-22 11:22:55 -07:00
Edward Thomson
0a1c8f55b3 preload configuration paths 2013-07-11 17:17:53 -05:00
Sven Strickroth
022a45e084 Revert "Work around reparse point stat issues"
This reverts commit 32c12ea6a9.
2013-06-25 16:43:15 +02:00
Vicent Martí
09ee60c6d4 Merge pull request #1670 from arrbee/open-cloexec
Add O_CLOEXEC to open calls
2013-06-24 11:21:09 -07:00
Russell Belfer
32c12ea6a9 Work around reparse point stat issues
In theory, p_stat should never return an S_ISLNK result, but due
to the current implementation on Windows with mount points it is
possible that it will.  For now, work around that by allowing a
link in the path to a directory being created.  If it is really a
problem, then the issue will be caught on the next iteration of
the loop, but typically this will be the right thing to do.
2013-06-24 09:19:24 -07:00
Russell Belfer
3d3ea4dc56 Add O_CLOEXEC to open calls 2013-06-22 20:58:32 -07:00
yorah
2da72fb21c fileops: fix invalid read 2013-06-14 20:01:35 +02:00
Russell Belfer
f7e5615086 Make mkdir early exit cases clearer
There are two places where git_futils_mkdir should exit early or
at least do less.  The first is when using GIT_MKDIR_SKIP_LAST
and having that flag leave no directory left to create; it was
being handled previously, but the behavior was subtle.  Now I put
in a clear explicit check that exits early in that case.

The second is when there is no directory to create, but there is
a valid path that should be verified.  I shifted the logic a bit
so we'll be better about not entering the loop than that happens.
2013-06-05 15:41:42 -07:00
Russell Belfer
999d4405a6 Simplify git_futils_mkdir
This routine was (is) pretty complicated, but given the recent
changes, it seemed like it could be simplified a bit.
2013-06-05 12:02:28 -07:00
Vicent Marti
2e1fa15fcd I'm a dick 2013-06-05 19:00:16 +02:00
Russell Belfer
b832ecf71c Ensure git_futils_mkdir won't mkdir root
This makes sure that git_futils_mkdir always skips over the root
directory at a minimum, even on platforms where the root is not
simply '/'.  Also, this removes the GIT_WIN32 ifdef in favor of
making EACCES as a potentially recoverable error on all platforms.
2013-06-05 09:46:51 -07:00
Jameson Miller
daf98cb2ed Allow creation of directories under the volume root in Win32
We ran into an issue where cloning a repository to a folder
directly underneath the root of a volume (e.g. 'd:\libgit2')
would fail with an access denied error. This was traced down
to a call to make a directory that is the root (e.g. 'd:') could
return an error indicated access denied instead of an error
indicating the path already exists. This change now handles
the access denied error on Win32 and checks for the existence
of the folder.
2013-06-05 12:05:29 -04:00
Russell Belfer
4742148d54 Add more diff rename detection tests
This adds a bunch more rename detection tests including checks
vs the working directory, the new exact match options, some more
whitespace variants, etc.

This also adds a git_futils_writebuffer helper function and uses
it in checkout.  This is mainly added because I wanted an easy
way to write out a git_buf to disk inside my test code.
2013-05-20 13:41:39 -07:00
Vicent Martí
03c28d92d0 Merge pull request #1526 from arrbee/cleanup-error-return-without-msg
Make sure error messages are set for most error returns
2013-05-06 06:45:53 -07:00
Edward Thomson
e09d18eed6 allow checkout to proceed when a dir to be removed is in use (win32) 2013-05-03 18:54:47 -05:00
Russell Belfer
e830c020f3 Report stat error when checking if file modified 2013-05-01 13:50:39 -07:00
Vicent Martí
5b27bf7e5b Merge pull request #1417 from arrbee/opts-for-paths
Implement opts interface for global/system file search paths
2013-03-18 16:17:14 -07:00
Russell Belfer
324602514f Fixes and cleanups
Get rid of some dead code, tighten things up a bit, and fix a bug
with core::env test.
2013-03-18 15:54:35 -07: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
Arkadiy Shapkin
10c06114cb Several warnings detected by static code analyzer fixed
Implicit type conversion argument of function to size_t type
Suspicious sequence of types castings: size_t -> int -> size_t
Consider reviewing the expression of the 'A = B == C' kind. The expression is calculated as following: 'A = (B == C)'
Unsigned type is never < 0
2013-03-18 03:30:26 +04: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 Martí
b72f5d4038 Merge pull request #1369 from arrbee/repo-init-template-hooks
More tests (and fixes) for initializing repo from template
2013-03-05 15:35:28 -08:00