summaryrefslogtreecommitdiff
path: root/src/repository.c
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #6106 from ammgws/fixtemplateerrEdward Thomson2021-11-221-1/+6
|\ | | | | Fix repo init when template dir is non-existent
| * repo: minor formatting fixEdward Thomson2021-11-221-2/+1
| |
| * repository: do not copy templates if dir nonexistentJason Nader2021-11-121-1/+7
| | | | | | | | | | This mimics the behaviour of git which just prints a warning and continues with the repo initialisation.
* | fs_path: add length with suffix validationEdward Thomson2021-11-091-2/+2
| |
* | path: use new length validation functionsEdward Thomson2021-11-091-3/+3
| |
* | path: separate git-specific path functions from utilEdward Thomson2021-11-091-59/+59
|/ | | | | | Introduce `git_fs_path`, which operates on generic filesystem paths. `git_path` will be kept for only git-specific path functionality (for example, checking for `.git` in a path).
* str: introduce `git_str` for internal, `git_buf` is externalethomson/gitstrEdward Thomson2021-10-171-257/+267
| | | | | | | | | | | | | | | | | | | | | | | | | | | libgit2 has two distinct requirements that were previously solved by `git_buf`. We require: 1. A general purpose string class that provides a number of utility APIs for manipulating data (eg, concatenating, truncating, etc). 2. A structure that we can use to return strings to callers that they can take ownership of. By using a single class (`git_buf`) for both of these purposes, we have confused the API to the point that refactorings are difficult and reasoning about correctness is also difficult. Move the utility class `git_buf` to be called `git_str`: this represents its general purpose, as an internal string buffer class. The name also is an homage to Junio Hamano ("gitstr"). The public API remains `git_buf`, and has a much smaller footprint. It is generally only used as an "out" param with strict requirements that follow the documentation. (Exceptions exist for some legacy APIs to avoid breaking callers unnecessarily.) Utility functions exist to convert a user-specified `git_buf` to a `git_str` so that we can call internal functions, then converting it back again.
* repository: improve `hashfile` for absolute pathsEdward Thomson2021-09-251-11/+13
| | | | | | | | | | | | | When `git_repository_hashfile` is handed an absolute path, it determines whether the path is within the repository's working directory or not. This is necessary when there is no `as_path` specified. If the path is within the working directory, then the given path should be used for attribute lookups (it is the effective `as_path`). If it is not within the working directory, then it is _not_ eligible. Importantly, now we will _never_ pass an absolute path down to attribute lookup functions.
* Merge pull request #6031 from libgit2/ethomson/extensionsEdward Thomson2021-09-141-3/+112
|\ | | | | Support custom git extensions
| * common: support custom repository extensionsethomson/extensionsEdward Thomson2021-09-041-3/+112
| | | | | | | | | | | | | | | | | | | | Allow users to specify additional repository extensions that they want to support. For example, callers can specify that they support `preciousObjects` and then may open repositories that support `extensions.preciousObjects`. Similarly, callers may opt out of supporting extensions that the library itself supports.
* | Fix coding style for pointerpunkymaniac2021-09-091-5/+5
|/ | | | Make some syntax change to follow coding style.
* Merge pull request #5943 from kcsaul/fix/5851Edward Thomson2021-08-301-0/+6
|\ | | | | Fix worktree iteration when repository has no common directory
| * repo: fix worktree iteration when repo has no common directoryKevin Saul2021-07-111-0/+6
| | | | | | | | | | | | | | | | | | | | When applying an operation to a repository created without a common directory, which is known to occur in scenarios where custom odb/refdb backends are used, git_repository_foreach_worktree currently asserts while attempting to open the repository located in the common directory. Fix this issue by applying operation to repository supplied when there are no linked worktrees to iterate (implied by common directory being empty).
* | Homogenize semantics for atomic-related functionslhchavez2021-08-261-8/+4
|/ | | | | | | | | | | | | | | | | | There were some subtle semantic differences between the various implementations of atomic functions. Now they behave the same, have tests and are better documented to avoid this from happening again in the future. Of note: * The semantics chosen for `git_atomic_compare_and_swap` match `InterlockedCompareExchangePointer`/`__sync_cal_compare_and_swap` now. * The semantics chosen for `git_atomic_add` match `InterlockedAdd`/`__atomic_add_fetch`. * `git_atomic_swap` and `git_atomic_load` still have a bit of semantic difference with the gcc builtins / msvc interlocked operations, since they require an l-value (not a pointer). If desired, this can be homogenized.
* Merge pull request #5823 from libgit2/ethomson/path_validationEdward Thomson2021-05-021-31/+86
|\ | | | | Working directory path validation
| * repo: validate repository pathsEdward Thomson2021-04-281-7/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Ensure that a repository's path (at initialization or open time) is valid. On Windows systems, this means that the longest known path beneath the repository will fit within MAX_PATH: this is a lock file for a loose object within the repository itself. Other paths, like a very long loose reference, may fail to be opened after the repository is opened. These variable length paths will be checked when they are accessed themselves. This new functionality is done at open to prevent needlessly checking every file in the gitdir (eg, `MERGE_HEAD`) for its length when we could instead check once at repository open time.
| * repo: factor the commondir detectionEdward Thomson2021-04-281-28/+41
| |
| * repository: validate workdir path lengthsEdward Thomson2021-04-281-3/+3
| |
| * repo: introduce git_repository_workdir_pathEdward Thomson2021-04-281-0/+16
| | | | | | | | | | | | | | Add a simple accessor for workdir paths to get an absolute on-disk path given a repository and a relative path within it. This is useful to avoid copy-pasta `git_buf_joinpath` and to ensure that we validate working directory paths while honoring `core.longpaths` settings.
* | Merge pull request #5834 from libgit2/cmn/repo-no-passthroughEdward Thomson2021-04-131-11/+9
|\ \ | | | | | | repo: remove an inappropriate use of PASSTHROUGH
| * | repo: remove an inappropriate use of PASSTHROUGHcmn/repo-no-passthroughCarlos Martín Nieto2021-04-111-11/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This error code is for callbacks where we should act as though the callback was not set. This is not something that makes sense for a `_foreach` and checking for that error message to bubble up mostly is happenstance precisely because this is not an error code we expect in the callback. As part of removing this, let's also remove a use of foreach as we can open-code this check.
* | | repo: specify init.defaultbranch is meant to be a branch namecmn/branch-or-refCarlos Martín Nieto2021-04-111-1/+1
|/ / | | | | | | | | | | | | We don't want the default branch's refname here but its name as branch. Returning an error saying it's not a valid reference here suggests we want the value of `init.defaultbranch` to be something like `refs/heads/default` which is not the case.
* | Default to GIT_BRANCH_DEFAULT if init.defaultBranch is empty stringIan Hattendorf2021-04-011-2/+3
|/ | | | We already do this in repo_init_head
* repo: ignore empty init.defaultbranchethomson/empty_default_branchEdward Thomson2021-01-071-1/+2
| | | | | | The init.defaultbranch option may be set, but empty. In this case, we should ignore it instead of trying to set our default branch to `refs/heads/`.
* Fix an oopslhchavez2020-12-111-1/+1
|
* Small refactor to make thing tidierlhchavez2020-12-111-18/+4
| | | | Also repurposed an unused function and deleted another one.
* threads: give atomic functions the git_atomic prefixEdward Thomson2020-12-061-12/+12
|
* Make the odb race-freelhchavez2020-11-281-2/+3
| | | | | | | This change adds all the necessary locking to the odb to avoid races in the backends. Part of: #5592
* repository: use GIT_ASSERTEdward Thomson2020-11-271-33/+58
|
* buffer: git_buf_sanitize should return a valueEdward Thomson2020-11-251-2/+5
| | | | | | `git_buf_sanitize` is called with user-input, and wants to sanity-check that input. Allow it to return a value if the input was malformed in a way that we cannot cope.
* refs: use git_reference_name_is_validEdward Thomson2020-10-251-3/+4
|
* Fix error return for invalid extensions.Eric Huss2020-10-071-2/+2
|
* repo: teach isempty about default branch configEdward Thomson2020-08-031-9/+11
| | | | | | The git_repository_isempty function now respects the init.defaultbranch setting (instead of hardcoding "master") to understand if a repository is empty or not.
* repo: add git_repository_initialbranchEdward Thomson2020-08-031-0/+34
| | | | | | Provide a helper function to get the initial branch for a repository, respecting the `init.defaultBranch` configuration option, if set, and returning the "default default" (currently `master`) otherwise.
* repo: honor the init.defaultBranch settingEdward Thomson2020-08-031-16/+40
| | | | | | | | | | | | | | As part of a push towards more inclusive language, git is reconsidering using "master" as the default branch name. As a first step, this setting will be configurable with the `init.defaultBranch` configuration option. Honor this during repository initialization. During initialization, we will create an initial branch: 1. Using the `initial_head` setting, if specified; 2. Using the `HEAD` configured in a template, if it exists; 3. Using the `init.defaultBranch` configuration option, if it is set; or 4. Using `master` in the absence of additional configuration.
* repository: retrieve worktree HEAD via refdbPatrick Steinhardt2020-07-121-21/+13
| | | | | | | | | | The function `git_repository_head_for_worktree` currently uses `git_reference__read_head` to directly read a given worktree's HEAD from the filesystem. This is broken in case the repository uses a different refdb implementation than the filesystem-based one, so let's instead open the worktree as a real repository and use `git_reference_lookup`. This also fixes the case where the worktree's HEAD is not a symref, but a detached HEAD, which would have resulted in an error previously.
* repository: remove function to iterate over HEADsPatrick Steinhardt2020-07-121-39/+0
| | | | | | | | The function `git_repository_foreach_head` is broken, as it directly interacts with the on-disk representation of the reference database, thus assuming that no other refdb is used for the given repository. As this is an internal function only and all users have been replaced, let's remove this function.
* repository: introduce new function to iterate over all worktreesPatrick Steinhardt2020-07-121-0/+45
| | | | | | | Given a Git repository, it's non-trivial to iterate over all worktrees that are associated with it, including the "main" repository. This commit adds a new internal function `git_repository_foreach_worktree` that does this for us.
* tree-wide: do not compile deprecated functions with hard deprecationPatrick Steinhardt2020-06-091-0/+2
| | | | | | | | | | | | | | | | | | | | | | When compiling libgit2 with -DDEPRECATE_HARD, we add a preprocessor definition `GIT_DEPRECATE_HARD` which causes the "git2/deprecated.h" header to be empty. As a result, no function declarations are made available to callers, but the implementations are still available to link against. This has the problem that function declarations also aren't visible to the implementations, meaning that the symbol's visibility will not be set up correctly. As a result, the resulting library may not expose those deprecated symbols at all on some platforms and thus cause linking errors. Fix the issue by conditionally compiling deprecated functions, only. While it becomes impossible to link against such a library in case one uses deprecated functions, distributors of libgit2 aren't expected to pass -DDEPRECATE_HARD anyway. Instead, users of libgit2 should manually define GIT_DEPRECATE_HARD to hide deprecated functions. Using "real" hard deprecation still makes sense in the context of CI to test we don't use deprecated symbols ourselves and in case a dependant uses libgit2 in a vendored way and knows it won't ever use any of the deprecated symbols anyway.
* strarray: we should `dispose` instead of `free`Edward Thomson2020-06-011-1/+1
| | | | | | We _dispose_ the contents of objects; we _free_ objects (and their contents). Update `git_strarray_free` to be `git_strarray_dispose`. `git_strarray_free` remains as a deprecated proxy function.
* Merge pull request #5388 from bk2204/repo-format-v1Patrick Steinhardt2020-04-021-9/+38
|\ | | | | Handle repository format v1
| * repository: handle format v1brian m. carlson2020-02-111-9/+38
| | | | | | | | | | | | | | | | | | | | | | Git has supported repository format version 1 for some time. This format is just like version 0, but it supports extensions. Implementations must reject extensions that they don't support. Add support for this format version and reject any extensions but extensions.noop, which is the only extension we currently support. While we're at it, also clean up an error message.
* | repository: check error codes when reading common linkPatrick Steinhardt2020-02-071-50/+63
|/ | | | | | | | | | | | | When checking whether a path is a valid repository path, we try to read the "commondir" link file. In the process, we neither confirm that constructing the file's path succeeded nor do we verify that reading the file succeeded, which might cause us to verify repositories on an empty or bogus path later on. Fix this by checking return values. As the function to verify repos doesn't currently support returning errors, this commit also refactors the function to return an error code, passing validity of the repo via an out parameter instead, and adjusts all existing callers.
* repository functions: return an intEdward Thomson2020-01-241-5/+11
| | | | | Stop returning a void for functions, future-proofing them to allow them to fail.
* Do not return free'd git_repository object on errorSven Strickroth2020-01-161-2/+1
| | | | | | | | Regression introduced in commit dde6d9c706bf1ecab545da55ab874a016587af1f. This issue causes lots of crashes in TortoiseGit. Signed-off-by: Sven Strickroth <email@cs-ware.de>
* futils_filesize: use `uint64_t` for object sizeEdward Thomson2019-11-221-5/+2
| | | | | Instead of using a signed type (`off_t`) use `uint64_t` for the maximum size of files.
* refs: fix locks getting forcibly removedSebastian Henke2019-10-101-1/+1
| | | | | | | | | | | | | | | | | The flag GIT_FILEBUF_FORCE currently does two things: 1. It will cause the filebuf to create non-existing leading directories for the file that is about to be written. 2. It will forcibly remove any pre-existing locks. While most call sites actually do want (1), they do not want to remove pre-existing locks, as that renders the locking mechanisms effectively useless. Introduce a new flag `GIT_FILEBUF_CREATE_LEADING_DIRS` to separate both behaviours cleanly from each other and convert callers to use it instead of `GIT_FILEBUF_FORCE` to have them honor locked files correctly. As this conversion removes all current users of `GIT_FILEBUF_FORCE`, this commit removes the flag altogether.
* open:move all cleanup code to cleanup label in git_repository_open_extLaurence McGlashan2019-09-101-9/+7
|
* open:fix memory leak when passing NULL to git_repository_open_extLaurence McGlashan2019-09-101-1/+6
|
* path: extract function to check whether a path supports symlinksPatrick Steinhardt2019-07-201-13/+1
| | | | | | | | | | | | When initializing a repository, we need to check whether its working directory supports symlinks to correctly set the initial value of the "core.symlinks" config variable. The code to check the filesystem is reusable in other parts of our codebase, like for example in our tests to determine whether certain tests can be expected to succeed or not. Extract the code into a new function `git_path_supports_symlinks` to avoid duplicate implementations. Remove a duplicate implementation in the repo test helper code.