Commit Graph

220 Commits

Author SHA1 Message Date
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
Jameson Miller
926acbcf8e Clone should not delete directories it did not create 2013-03-01 14:56:09 -05:00
Russell Belfer
18f0826408 Make mode handling during init more like git
When creating files, instead of actually using GIT_FILEMODE_BLOB
and the other various constants that happen to correspond to
mode values, apparently I should be just using 0666 and 0777, and
relying on the umask to clear bits and make the value sane.

This fixes the rules for copying a template directory and fixes
the checks to match that new behavior.  (Further changes to the
checkout logic to follow separately.)
2013-02-27 13:44:15 -08:00
Russell Belfer
3c42e4ef74 Fix initialization of repo directories
When PR #1359 removed the hooks from the test resources/template
directory, it made me realize that the tests for
git_repository_init_ext using templates must be pretty shabby
because we could not have been testing if the hooks were getting
created correctly.

So, this started with me recreating a couple of hooks, including
a sample and symlink, and adding tests that they got created
correctly in the various circumstances, including with the SHARED
modes, etc.  Unfortunately this uncovered some issues with how
directories and symlinks were copied and chmod'ed.  Also, there
was a FIXME in the code related to the chmod behavior as well.

Going back over the directory creation logic for setting up a
repository, I found it was a little difficult to read and could
result in creating and/or chmod'ing directories that the user
almost certainly didn't intend.

So that let to this work which makes repo initialization much
more careful (and hopefully easier to follow).  It required a
couple of extensions / changes to core fileops utilities, but I
also think those are for the better, at least for git_futils_cp_r
in terms of being careful about what actions it takes.
2013-02-26 11:43:14 -08:00
Philip Kelley
6c72035fbc Portability fixes for Solaris 2013-02-22 12:23:14 -05:00
Jameson Miller
91f13a18d5 Try harder to find global config file 2013-02-01 14:23:26 -05:00
Russell Belfer
de59055017 Resolve crash with diff against empty file
It is not legal inside our `p_mmap` function to mmap a zero length
file.  This adds a test that exercises that case inside diff and
fixes the code path where we would try to do that.

The fix turns out not to be a lot of code since our default file
content is already initialized to "" which works in this case.

Fixes #1210
2013-01-08 17:11:11 -08:00
Edward Thomson
359fc2d241 update copyrights 2013-01-08 17:31:27 -06:00
Russell Belfer
7e5c8a5b41 More checkout improvements
This flips checkout back to be driven off the changes between
the baseline and the target trees.  This reinstates the complex
code for tracking the contents of the working directory, but
overall, I think the resulting logic is easier to follow.
2013-01-04 15:47:42 -08:00
Russell Belfer
cccacac555 Add POSIX compat lstat() variant for win32
The existing p_lstat implementation on win32 is not quite POSIX
compliant when setting errno to ENOTDIR.  This adds an option to
make is be compliant so that code (such as checkout) that cares
to have separate behavior for ENOTDIR can use it portably.

This also contains a couple of other minor cleanups in the
posix_w32.c implementations to avoid unnecessary work.
2012-11-14 22:41:51 -08:00
Russell Belfer
ad9a921b92 Rework checkout with new strategy options
This is a major reworking of checkout strategy options.  The
checkout code is now sensitive to the contents of the HEAD tree
and the new options allow you to update the working tree so that
it will match the index content only when it previously matched
the contents of the HEAD.  This allows you to, for example, to
distinguish between removing files that are in the HEAD but not
in the index, vs just removing all untracked files.

Because of various corner cases that arise, etc., this required
some additional capabilities in rmdir and other utility functions.

This includes the beginnings of an implementation of code to read
a partial tree into the index based on a pathspec, but that is
not enabled because of the possibility of creating conflicting
index entries.
2012-11-09 13:52:07 -08:00
Russell Belfer
331e7de900 Extensions to rmdir and mkdir utilities
* Rework GIT_DIRREMOVAL values to GIT_RMDIR flags, allowing
  combinations of flags
* Add GIT_RMDIR_EMPTY_PARENTS flag to remove parent dirs that
  are left empty after removal
* Add GIT_MKDIR_VERIFY_DIR to give an error if item is a file,
  not a dir (previously an EEXISTS error was ignored, even for
  files) and enable this flag for git_futils_mkpath2file call
* Improve accuracy of error messages from git_futils_mkdir
2012-11-09 13:52:06 -08:00
Vicent Marti
c1f61af66b I LIKE THESE NAMES 2012-10-31 20:52:01 +01:00
Russell Belfer
c8b511f3cd Better naming for file timestamp/size checker 2012-10-31 11:26:12 -07:00
Russell Belfer
744cc03e2b Add git_config_refresh() API to reload config
This adds a new API that allows users to reload the config if the
file has changed on disk.  A new config callback function to
refresh the config was added.

The modified time and file size are used to test if the file needs
to be reloaded (and are now stored in the disk backend object).

In writing tests, just using mtime was a problem / race, so I
wanted to check file size as well.  To support that, I extended
`git_futils_readbuffer_updated` to optionally check file size in
addition to mtime, and I added a new function `git_filebuf_stats`
to fetch the mtime and size for an open filebuf (so that the
config could be easily refreshed after a write).

Lastly, I moved some similar file checking code for attributes
into filebuf.  It is still only being used for attrs, but it
seems potentially reusable, so I thought I'd move it over.
2012-10-30 12:11:23 -07:00
Russell Belfer
0d422ec9c2 Fix env variable tests with new Win32 path rules
The new Win32 global path search was not working with the
environment variable tests.  But when I fixed the test, the new
codes use of getenv() was causing more failures (presumably because
of caching on Windows ???).  This fixes the global file lookup to
always go directly to the Win32 API in a predictable way.
2012-10-19 15:40:43 -07:00
Russell Belfer
4c47a8bcfe Merge pull request #968 from arrbee/diff-support-typechange
Support TYPECHANGE records in status and adjust checkout accordingly
2012-10-17 14:14:51 -07:00