summaryrefslogtreecommitdiff
path: root/src/path.h
Commit message (Collapse)AuthorAgeFilesLines
* path: export the dotgit-checking functionscmn/expose-gitfile-checkCarlos Martín Nieto2018-10-151-38/+2
| | | | | | | | These checks are preformed by libgit2 on checkout, but they're also useful for performing checks in applications which do not involve checkout. Expose them under `sys/` as it's still fairly in the weeds even for this library.
* path: unify `git_path_is_*` APIsPatrick Steinhardt2018-06-011-71/+37
| | | | | | | | | | | | | | | | Right now, there's quite a lot of different function calls to determine whether a path component matches a specific name after normalization from the filesystem. We have a function for each of {gitattributes, gitmodules, gitignore} multiplicated with {generic, NTFS, HFS} checks. In the long time, this is unmaintainable in case there are e.g. new filesystems with specific semantics, blowing up the number of functions we need to implement. Replace all functions with a simple `git_path_is_gitfile` function, which accepts an enum pointing out the filename that is to be checked against as well as the filesystem normalizations to check for. This greatly simplifies implementation at the expense of the caller having to invoke a somewhat longer function call.
* path: reject .gitmodules as a symlinkCarlos Martín Nieto2018-05-231-0/+1
| | | | | | | | Any part of the library which asks the question can pass in the mode to have it checked against `.gitmodules` being a symlink. This is particularly relevant for adding entries to the index from the worktree and for checking out files.
* path: accept the name length as a parameterCarlos Martín Nieto2018-05-221-9/+18
| | | | | We may take in names from the middle of a string so we want the caller to let us know how long the path component is that we should be checking.
* path: expose dotgit detection functions per filesystemCarlos Martín Nieto2018-05-221-0/+42
| | | | | These will be used by the checkout code to detect them for the particular filesystem they're on.
* path: hide the dotgit file functionsCarlos Martín Nieto2018-05-181-0/+21
| | | | | These can't go into the public API yet as we don't want to introduce API or ABI changes in a security release.
* path: expose `git_path_is_dirsep`Patrick Steinhardt2017-10-091-0/+6
| | | | | | | This function has previously been implemented in Windows-specific path handling code as `path__is_dirsep`. As we will need this functionality in other parts, extract the logic into "path.h" alongside with a non-Windows implementation.
* path: expose `git_path_is_absolute`Patrick Steinhardt2017-10-091-0/+7
| | | | | | | This function has previously been implemented in Windows-specific path handling code as `path__is_absolute`. As we will need this functionality in other parts, extract the logic into "path.h" alongside with a non-Windows implementation.
* Make sure to always include "common.h" firstPatrick Steinhardt2017-07-031-0/+1
| | | | | | | | | | | | | | | | | | | | | | Next to including several files, our "common.h" header also declares various macros which are then used throughout the project. As such, we have to make sure to always include this file first in all implementation files. Otherwise, we might encounter problems or even silent behavioural differences due to macros or defines not being defined as they should be. So in fact, our header and implementation files should make sure to always include "common.h" first. This commit does so by establishing a common include pattern. Header files inside of "src" will now always include "common.h" as its first other file, separated by a newline from all the other includes to make it stand out as special. There are two cases for the implementation files. If they do have a matching header file, they will always include this one first, leading to "common.h" being transitively included as first file. If they do not have a matching header file, they instead include "common.h" as first file themselves. This fixes the outlined problems and will become our standard practice for header and source files inside of the "src/" from now on.
* Patch parsing from patch filesEdward Thomson2016-05-261-0/+6
|
* Introduce `git_path_common_dirlen`Edward Thomson2016-03-241-0/+12
|
* index: allow read of index w/ illegal entriesEdward Thomson2016-02-171-4/+14
| | | | | | | | | Allow `git_index_read` to handle reading existing indexes with illegal entries. Allow the low-level `git_index_add` to add properly formed `git_index_entry`s even if they contain paths that would be illegal for the current filesystem (eg, `AUX`). Continue to disallow `git_index_add_bypath` from adding entries that are illegal universally illegal (eg, `.git`, `foo/../bar`).
* `mkdir`: cope with root path on win32Edward Thomson2015-09-171-1/+1
|
* core::mkdir tests: ensure we don't stomp symlinks in mkdirEdward Thomson2015-09-171-0/+6
| | | | | In `mkdir` and `mkdir_r`, ensure that we don't try to remove symlinks that are in our way.
* Merge pull request #3332 from phatblat/ben/doc-warningsCarlos Martín Nieto2015-08-011-1/+1
|\ | | | | Resolve documentation warnings
| * Fix remaining documentation warningsBen Chatelain2015-07-271-1/+1
| |
* | submodule, path: extract slash conversioncmn/submodule-backslashCarlos Martín Nieto2015-07-131-0/+5
|/ | | | Extract the backslash-to-slash conversion into a helper function.
* path: remove unnecessary readdir_r usagecmn/readdirCarlos Martín Nieto2015-06-151-1/+1
| | | | | | Arguably all uses of readdir_r are unnecessary, but in this case especially so, as the directory handle only exists within this function, so we don't race with anybody.
* diriter: actually use iconv on macEdward Thomson2015-05-011-84/+91
|
* git_path_diriter: use FindFirstFile in win32Edward Thomson2015-05-011-0/+26
| | | | | | | Using FindFirstFile and FindNextFile in win32 allows us to use the directory information that is returned, instead of us having to get the file attributes all over again, which is a distinct cost savings on win32.
* git_path_diriter: next shouldn't take path ptrEdward Thomson2015-05-011-1/+48
| | | | | | | | The _next method shouldn't take a path pointer (and a path_len pointer) as 100% of current users use the full path and ignore the filename. Plus let's add some docs and a unit test.
* git_path_dirload_with_stat: moved to fs_iteratorEdward Thomson2015-05-011-36/+0
|
* git_path_dirload: use git_path_diriterEdward Thomson2015-05-011-7/+3
|
* git_path: introduce 'git_path_diriter'Edward Thomson2015-05-011-0/+32
| | | | | Introduce a new `git_path_diriter` that can iterate directories efficiently for each platform.
* git_path_join_unrooted: return base lenEdward Thomson2015-01-201-3/+17
| | | | | | | The documentation for `git_path_join_unrooted` states that the base length will be returned, so that consumers like checkout know where to start creating directories instead of always creating directories at the directory root.
* Introduce core.protectHFS and core.protectNTFSEdward Thomson2014-12-171-10/+10
| | | | | | Validate HFS ignored char ".git" paths when `core.protectHFS` is specified. Validate NTFS invalid ".git" paths when `core.protectNTFS` is specified.
* checkout: disallow bad paths on HFSEdward Thomson2014-12-161-0/+5
| | | | | | | | HFS filesystems ignore some characters like U+200C. When these characters are included in a path, they will be ignored for the purposes of comparison with other paths. Thus, if you have a ".git" folder, a folder of ".git<U+200C>" will also match. Protect our ".git" folder by ensuring that ".git<U+200C>" and friends do not match it.
* checkout: disallow bad paths on win32Edward Thomson2014-12-161-0/+38
| | | | | | | | | | | | | | | Disallow: 1. paths with trailing dot 2. paths with trailing space 3. paths with trailing colon 4. paths that are 8.3 short names of .git folders ("GIT~1") 5. paths that are reserved path names (COM1, LPT1, etc). 6. paths with reserved DOS characters (colons, asterisks, etc) These paths would (without \\?\ syntax) be elided to other paths - for example, ".git." would be written as ".git". As a result, writing these paths literally (using \\?\ syntax) makes them hard to operate with from the shell, Windows Explorer or other tools. Disallow these.
* Spelling fixesWill Stamper2014-12-041-1/+1
|
* path: Fix `git_path_walk_up` to work with non-rooted pathsThe rugged tests are fragile2014-09-171-1/+1
|
* Introduce git_path_make_relativeEdward Thomson2014-09-021-0/+11
|
* Fix rejection of parent dir of negated ignoresRussell Belfer2014-08-081-0/+8
| | | | | | | While scanning through a directory hierarchy, this prevents a positive ignore match on a parent directory from blocking the scan of a directory when a negative match rule exists for files inside the directory.
* Merge pull request #2471 from jacquesg/compatibility-cleanupVicent Marti2014-08-071-0/+1
|\ | | | | Compatibility/Portability cleanup
| * Cleanup portability/compatibility layerJacques Germishuys2014-08-051-0/+1
| | | | | | | | | | | | | | * Removes mingw-compat.h * Cleans up separation of compiler/platform idiosyncrasies * Unifies mingw/msvc stat structures and functions * (Tries to) hide more compiler specific implementation details (even in our internal API)
* | Handle local file:/// paths on WindowsEdward Thomson2014-07-111-0/+1
|/ | | | | Windows can't handle a path like `/c:/foo`; when turning file:/// URIs into local paths, we must strip the leading slash.
* clone: re-use the local transport's path resolutioncmn/path-to-pathCarlos Martín Nieto2014-06-031-0/+3
| | | | | | Whe already worked out the kinks with the function used in the local transport. Expose it and make use of it in the local clone method instead of trying to work it out again.
* Pass unconverted data when iconv doesn't like itRussell Belfer2014-05-081-0/+2
| | | | | | | | | | | | | | When using Iconv to convert unicode data and iconv doesn't like the source data (because it thinks that it's not actual UTF-8), instead of stopping the operation, just use the unconverted data. This will generally do the right thing on the filesystem, since that is the source of the non-UTF-8 path data anyhow. This adds some tests for creating and looking up branches with messy Unicode names. Also, this takes the helper function that was previously internal to `git_repository_init` and makes it into `git_path_does_fs_decompose_unicode` which is a useful in tests to understand what the expected results should be.
* Submodule sync refactoringRussell Belfer2014-04-011-0/+8
| | | | | | Turns out there was already a helper to do what I wanted to do, so I just made it so that I could use it for sync and switched to that instead.
* Remove converting user error to GIT_EUSERRussell Belfer2013-12-111-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* iconv: Do not fake an API when iconv is not availableVicent Marti2013-11-011-10/+0
|
* Move path prefixed help to path.hEdward Thomson2013-10-161-0/+28
|
* Make reference lookups apply precomposeunicodeRussell Belfer2013-10-081-5/+0
| | | | | | | | | | | | | | | | | | | | | Before these changes, looking up a reference would return the same precomposed or decomposed form of the reference name that was used to look it up, so on MacOS which ignores the difference between the two, a single reference could be looked up either way and git_reference_name would return the form of the name that was used to look it up! This change makes lookup always return the precomposed name if core.precomposeunicode is set regardless of which version was used to look it up. The reference iterator was already returning the precomposed form from earlier work. This also updates the CMakeLists.txt rules for enabling iconv usage because the clar tests for this code were actually not being activated properly with the old version. Finally, this moves git_repository_reset_filesystem from include/ git2/repository.h to include/git2/sys/repository.h since it is not really a function that normal library users should have to think about very often.
* More filemode cleanups for FAT on MacOSRussell Belfer2013-10-081-0/+4
| | | | | | | | | | | | | | | | | | | | | | 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.
* Wrap iconv stuff and write testsRussell Belfer2013-10-031-0/+52
| | | | | | | | This adds a simple wrapper around the iconv APIs and uses it instead of the old code that was inlining the iconv stuff. This makes it possible for me to test the iconv logic in isolation. A "no iconv" version of the API was defined with macros so that I could have fewer ifdefs in the code itself.
* Initial iconv hookup for precomposed unicodeRussell Belfer2013-10-031-23/+26
| | | | | | | | | | | | | | | | | | | | 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.
* Put hooks in place for precompose in dirload fnRussell Belfer2013-10-031-2/+8
| | | | | | This doesn't actual do string precompose but it puts the hooks in place into the iterators and the git_path_dirload function so that the actual precompose work is ready to go.
* Clean up some documentationCarlos Martín Nieto2013-07-231-2/+0
| | | | clang's docparser highlighted these.
* Improved tree iterator internalsRussell Belfer2013-03-141-6/+2
| | | | | | | | | | | | | | | | | | | | | | | | This updates the tree iterator internals to be more efficient. The tree_iterator_entry objects are now kept as pointers that are allocated from a git_pool, so that we may use git__tsort_r for sorting (which is better than qsort, given that the tree is likely mostly ordered already). Those tree_iterator_entry objects now keep direct pointers to the data they refer to instead of keeping indirect index values. This simplifies a lot of the data structure traversal code. This also adds bsearch to find the start item position for range- limited tree iterators, and is more explicit about using git_path_cmp instead of reimplementing it. The git_path_cmp changed a bit to make it easier for tree_iterators to use it (but it was barely being used previously, so not a big deal). This adds a git_pool_free_array function that efficiently frees a list of pool allocated pointers (which the tree_iterator keeps). Also, added new tests for the git_pool free list functionality that was not previously being tested (or used).
* Add git_path_icmp to case-insensitive path cmpRussell Belfer2013-01-151-1/+6
| | | | This adds git_path_icmp to complement git_path_cmp.
* update copyrightsEdward Thomson2013-01-081-1/+1
|