summaryrefslogtreecommitdiff
path: root/src/repository.c
Commit message (Collapse)AuthorAgeFilesLines
* git_repository_set_head: use remote name in reflogethomson/set_head_to_tagEdward Thomson2017-04-031-2/+4
| | | | | | When `git_repository_set_head` is provided a remote reference, update the reflog with the tag name, like we do with a branch. This helps consumers match the semantics of `git checkout remote`.
* git_repository_set_head: use tag name in reflogEdward Thomson2017-03-211-37/+38
| | | | | | When `git_repository_set_head` is provided a tag reference, update the reflog with the tag name, like we do with a branch. This helps consumers match the semantics of `git checkout tag`.
* strmap: remove GIT__USE_STRMAP macroPatrick Steinhardt2017-02-171-1/+0
|
* worktree: compute workdir for worktrees opened via their gitdirPatrick Steinhardt2017-02-131-4/+32
| | | | | | | | | | | | | | | | | | | | | When opening a worktree via the gitdir of its parent repository we fail to correctly set up the worktree's working directory. The problem here is two-fold: we first fail to see that the gitdir actually is a gitdir of a working tree and then subsequently fail to determine the working tree location from the gitdir. The first problem of not noticing a gitdir belongs to a worktree can be solved by checking for the existence of a `gitdir` file in the gitdir. This file points back to the gitlink file located in the working tree's working directory. As this file only exists for worktrees, it should be sufficient indication of the gitdir belonging to a worktree. The second problem, that is determining the location of the worktree's working directory, can then be solved by reading the `gitdir` file in the working directory's gitdir. When we now resolve relative paths and strip the final `.git` component, we have the actual worktree's working directory location.
* repository: rename `path_repository` and `path_gitlink`Patrick Steinhardt2017-02-131-24/+24
| | | | | | | | | | | | | The `path_repository` variable is actually confusing to think about, as it is not always clear what the repository actually is. It may either be the path to the folder containing worktree and .git directory, the path to .git itself, a worktree or something entirely different. Actually, the intent of the variable is to hold the path to the gitdir, which is either the .git directory or the bare repository. Rename the variable to `gitdir` to avoid confusion. While at it, also rename `path_gitlink` to `gitlink` to improve consistency.
* repository: restrict checking out checked out branchesPatrick Steinhardt2017-02-131-0/+6
| | | | | | If a branch is already checked out in a working tree we are not allowed to check out that branch in another repository. Introduce this restriction when setting a repository's HEAD.
* worktree: implement functions reading HEADPatrick Steinhardt2017-02-131-0/+85
| | | | | | Implement `git_repository_head_for_worktree` and `git_repository_head_detached_for_worktree` for directly accessing a worktree's HEAD without opening it as a `git_repository` first.
* worktree: implement `git_repository_open_from_worktree`Patrick Steinhardt2017-02-131-0/+31
| | | | | Add function `git_repository_open_from_worktree`, which allows to open a `git_worktree` as repository.
* repository: expose `repo_init_create_head`Patrick Steinhardt2017-02-131-2/+2
| | | | | Expose the function `repo_init_create_head` as `git_repository_create_head`.
* config: open configuration in commondirPatrick Steinhardt2017-02-131-2/+1
| | | | | | | A repository's configuartion file can always be found in the GIT_COMMON_DIR, which has been newly introduced. For normal repositories this does change nothing, but for working trees this change allows to access the shared configuration file.
* repository: introduce is_worktree variablePatrick Steinhardt2017-02-131-0/+11
|
* repository: use `git_repository_item_path`Patrick Steinhardt2017-02-131-1/+2
| | | | | | | | | | | | | | The recent introduction of the commondir variable of a repository requires callers to distinguish whether their files are part of the dot-git directory or the common directory shared between multpile worktrees. In order to take the burden from callers and unify knowledge on which files reside where, the `git_repository_item_path` function has been introduced which encapsulate this knowledge. Modify most existing callers of `git_repository_path` to use `git_repository_item_path` instead, thus making them implicitly aware of the common directory.
* repository: add function to retrieve paths for repo itemsPatrick Steinhardt2017-02-131-0/+61
|
* repository: introduce commondir variablePatrick Steinhardt2017-02-131-15/+66
| | | | | | | | | The commondir variable stores the path to the common directory. The common directory is used to store objects and references shared across multiple repositories. A current use case is the newly introduced `git worktree` feature, which sets up a separate working copy, where the backing git object store and references are pointed to by the common directory.
* Allow for caching of submodules.Brock Peabody2017-01-201-0/+33
| | | | | | | | | | | | | | Added `git_repository_submodule_cache_all` to initialze a cache of submodules on the repository so that operations looking up N submodules are O(N) and not O(N^2). Added a `git_repository_submodule_cache_clear` function to remove the cache. Also optimized the function that loads all submodules as it was itself O(N^2) w.r.t the number of submodules, having to loop through the `.gitmodules` file once per submodule. I changed it to process the `.gitmodules` file once, into a map. Signed-off-by: David Turner <dturner@twosigma.com>
* giterr_set: consistent error messagesEdward Thomson2016-12-291-13/+13
| | | | | | | | Error messages should be sentence fragments, and therefore: 1. Should not begin with a capital letter, 2. Should not conclude with punctuation, and 3. Should not end a sentence and begin a new one
* repository: do not interpret all files as gitlinks in discoveryPatrick Steinhardt2016-11-141-1/+1
| | | | | | | | | | | | | | When trying to find a discovery, we walk up the directory structure checking if there is a ".git" file or directory and, if so, check its validity. But in the case that we've got a ".git" file, we do not want to unconditionally assume that the file is in fact a ".git" file and treat it as such, as we would error out if it is not. Fix the issue by only treating a file as a gitlink file if it ends with "/.git". This allows users of the function to discover a repository by handing in any path contained inside of a git repository.
* git_repository_open_ext: fix handling of $GIT_NAMESPACEJosh Triplett2016-11-111-5/+8
| | | | | | | | | | | | The existing code would set a namespace of "" (empty string) with GIT_NAMESPACE unset. In a repository where refs/heads/namespaces/ exists, that can produce incorrect results. Detect that case and avoid setting the namespace at all. Since that makes the last assignment to error conditional, and the previous assignment can potentially get GIT_ENOTFOUND, set error to 0 explicitly to prevent the call from incorrectly failing with GIT_ENOTFOUND.
* repository: don't cast to `int` for no reasonEdward Thomson2016-07-241-4/+4
| | | | | And give it a default so that some compilers don't (unnecessarily) complain.
* find_repo: Clean up and simplify logicJosh Triplett2016-06-241-22/+30
| | | | | | | | | | | | | | | find_repo had a complex loop and heavily nested conditionals, making it difficult to follow. Simplify this as much as possible: - Separate assignments from conditionals. - Check the complex loop condition in the only place it can change. - Break out of the loop on error, rather than going through the rest of the loop body first. - Handle error cases by immediately breaking, rather than nesting conditionals. - Free repo_link unconditionally on the way out of the function, rather than in multiple places. - Add more comments on the remaining complex steps.
* Add GIT_REPOSITORY_OPEN_FROM_ENV flag to respect $GIT_* environment varsJosh Triplett2016-06-241-0/+169
| | | | | | | | | | | | | | | | | | | | | git_repository_open_ext provides parameters for the start path, whether to search across filesystems, and what ceiling directories to stop at. git commands have standard environment variables and defaults for each of those, as well as various other parameters of the repository. To avoid duplicate environment variable handling in users of libgit2, add a GIT_REPOSITORY_OPEN_FROM_ENV flag, which makes git_repository_open_ext automatically handle the appropriate environment variables. Commands that intend to act just like those built into git itself can use this flag to get the expected default behavior. git_repository_open_ext with the GIT_REPOSITORY_OPEN_FROM_ENV flag respects $GIT_DIR, $GIT_DISCOVERY_ACROSS_FILESYSTEM, $GIT_CEILING_DIRECTORIES, $GIT_INDEX_FILE, $GIT_NAMESPACE, $GIT_OBJECT_DIRECTORY, and $GIT_ALTERNATE_OBJECT_DIRECTORIES. In the future, when libgit2 gets worktree support, git_repository_open_env will also respect $GIT_WORK_TREE and $GIT_COMMON_DIR; until then, git_repository_open_ext with this flag will error out if either $GIT_WORK_TREE or $GIT_COMMON_DIR is set.
* Add GIT_REPOSITORY_OPEN_NO_DOTGIT flag to avoid appending /.gitJosh Triplett2016-06-241-7/+10
| | | | | | | | | | GIT_REPOSITORY_OPEN_NO_SEARCH does not search up through parent directories, but still tries the specified path both directly and with /.git appended. GIT_REPOSITORY_OPEN_BARE avoids appending /.git, but opens the repository in bare mode even if it has a working directory. To support the semantics git uses when given $GIT_DIR in the environment, provide a new GIT_REPOSITORY_OPEN_NO_DOTGIT flag to not try appending /.git.
* Fix repository discovery with ceiling_dirs at current directoryJosh Triplett2016-06-241-17/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | git only checks ceiling directories when its search ascends to a parent directory. A ceiling directory matching the starting directory will not prevent git from finding a repository in the starting directory or a parent directory. libgit2 handled the former case correctly, but differed from git in the latter case: given a ceiling directory matching the starting directory, but no repository at the starting directory, libgit2 would stop the search at that point rather than finding a repository in a parent directory. Test case using git command-line tools: /tmp$ git init x Initialized empty Git repository in /tmp/x/.git/ /tmp$ cd x/ /tmp/x$ mkdir subdir /tmp/x$ cd subdir/ /tmp/x/subdir$ GIT_CEILING_DIRECTORIES=/tmp/x git rev-parse --git-dir fatal: Not a git repository (or any of the parent directories): .git /tmp/x/subdir$ GIT_CEILING_DIRECTORIES=/tmp/x/subdir git rev-parse --git-dir /tmp/x/.git Fix the testsuite to test this case (in one case fixing a test that depended on the current behavior), and then fix find_repo to handle this case correctly. In the process, simplify and document the logic in find_repo(): - Separate the concepts of "currently checking a .git directory" and "number of iterations left before going further counts as a search" into two separate variables, in_dot_git and min_iterations. - Move the logic to handle in_dot_git and append /.git to the top of the loop. - Only search ceiling_dirs and find ceiling_offset after running out of min_iterations; since ceiling_offset only tracks the longest matching ceiling directory, if ceiling_dirs contained both the current directory and a parent directory, this change makes find_repo stop the search at the parent directory.
* annotated_commit: provide refs and descriptionethomson/annotated_commit_refsEdward Thomson2016-04-261-1/+1
| | | | | | | | | | | Differentiate between the ref_name used to create an annotated_commit (that can subsequently be used to look up the reference) and the description that we resolved this with (which _cannot_ be looked up). The description is used for things like reflogs (and may be a ref name, and ID something that we revparsed to get here), while the ref name must actually be a reference name, and is used for things like rebase to return to the initial branch.
* git_repository_init: include dotfiles when copying templatesEdward Thomson2015-12-261-1/+3
| | | | | | Include dotfiles when copying template directory, which will handle both a template directory itself that begins with a dotfile, and any dotfiles inside the directory.
* repository: distinguish sequencer cherry-pick and revertcmn/repository-state-sequencerCarlos Martín Nieto2015-11-201-3/+10
| | | | These are not quite like their plain counterparts and require special handling.
* repository: plug memory leakVicent Marti2015-10-281-0/+1
| | | | cc @carlosmn
* config: add a ProgramData levelcmn/programdata-configCarlos Martín Nieto2015-10-211-2/+12
| | | | | This is where portable git stores the global configuration which we can use to adhere to it even though git isn't quite installed on the system.
* Merge pull request #3434 from ethomson/reservednamesCarlos Martín Nieto2015-09-211-4/+20
|\ | | | | Win32 Reserved names: don't reserve names outside the working directory
| * repository: only reserve repo dirs in the workdirEdward Thomson2015-09-181-4/+20
| | | | | | | | | | | | | | | | | | | | Check that the repository directory is beneath the workdir before adding it to the list of reserved paths. If it is not, then there is no possibility of checking out files into it, and it should not be a reserved word. This is a particular problem with submodules where the repo directory may be in the super's .git directory.
* | git_futils_mkdir_*: make a relative-to-base mkdirEdward Thomson2015-09-171-6/+6
|/ | | | | | | | | | | | Untangle git_futils_mkdir from git_futils_mkdir_ext - the latter assumes that we own everything beneath the base, as if it were being called with a base of the repository or working directory, and is tailored towards checkout and ensuring that there is no bogosity beneath the base that must be cleaned up. This is (at best) slow and (at worst) unsafe in the larger context of a filesystem where we do not own things and cannot do things like unlink symlinks that are in our way.
* win32: ensure hidden files can be stagedEdward Thomson2015-08-031-2/+2
|
* Fix 8.3 filename tests failure when 8.3 is disabledLinquize2015-07-011-1/+4
|
* Merge pull request #3097 from libgit2/cmn/submodule-config-stateCarlos Martín Nieto2015-06-241-1/+0
|\ | | | | Remove run-time configuration settings from submodules
| * submodule: remove the per-repo cacheCarlos Martín Nieto2015-06-221-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | Having this cache and giving them out goes against our multithreading guarantees and it makes it impossible to use submodules in a multi-threaded environment, as any thread can ask for a refresh which may reallocate some string in the submodule struct which we've accessed in a different one via a getter. This makes the submodules behave more like remotes, where each object is created upon request and not shared except explicitly by the user. This means that some tests won't pass yet, as they assume they can affect the submodule objects in the cache and that will affect later operations.
* | Fixed invalid error handling in git_repository_open_ext()Pierre-Olivier Latour2015-06-231-1/+1
| |
* | repository: check the format versioncmn/repo-version-checkCarlos Martín Nieto2015-06-231-9/+26
| | | | | | | | | | | | | | | | This is something we do on re-init but not when opening a repository. This hasn't particularly mattered up to now as the version has been 0 ever since the first release of git, but the times, they're a-changing and we will soon see version 1 in the wild. We need to make sure we don't open those.
* | repository: don't error out if there is no versionCarlos Martín Nieto2015-06-231-2/+7
|/ | | | | git will assume the repository format version is 0 if the value is not there. Do the same.
* Merge pull request #3030 from linquize/symlink_supportedEdward Thomson2015-04-101-3/+5
|\ | | | | If work_dir is not specified, use repo_dir to test if symlink is supported
| * For bare repository, use repo_dir to test if symlinks are supportedLinquize2015-04-041-3/+5
| |
* | squash some leaksEdward Thomson2015-03-241-0/+2
|/
* Merge remote-tracking branch 'ethomson/submodule_8dot3'Carlos Martín Nieto2015-03-181-26/+121
|\
| * repository: Introduce "reserved names"Edward Thomson2015-02-271-26/+121
| | | | | | | | | | | | | | A repository can have multiple "reserved names" now, not just a single "short name" for the repository folder itself. Refactor to include a git_repository__reserved_names that returns all the reserved names for a repository.
* | Add annotated commit versions of reflog-modifying functionsCarlos Martín Nieto2015-03-161-6/+24
| | | | | | | | | | | | | | We do not always want to put the id directly into the reflog, but we want to speicfy what a user typed. For this use-case we provide annotated version of a few functions which let the caller specify what user-friendly name was used when asking for the operation.
* | repository: in-memory repos are bare by defaultEdward Thomson2015-03-101-1/+7
| |
* | Plug a few leaksCarlos Martín Nieto2015-03-041-0/+3
| |
* | config: borrow refcounted referencescmn/config-borrow-entryCarlos Martín Nieto2015-03-031-5/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changes the get_entry() method to return a refcounted version of the config entry, which you have to free when you're done. This allows us to avoid freeing the memory in which the entry is stored on a refresh, which may happen at any time for a live config. For this reason, get_string() has been forbidden on live configs and a new function get_string_buf() has been added, which stores the string in a git_buf which the user then owns. The functions which parse the string value takea advantage of the borrowing to parse safely and then release the entry.
* | repository: remove log message override for switching the active branchCarlos Martín Nieto2015-03-031-26/+60
| | | | | | | | | | | | We want to use the "checkout: moving from ..." message in order to let git know when a change of branch has happened. Make the convenience functions for this goal write this message.
* | Remove the signature from ref-modifying functionsCarlos Martín Nieto2015-03-031-8/+38
|/ | | | | | | | | | The signature for the reflog is not something which changes dynamically. Almost all uses will be NULL, since we want for the repository's default identity to be used, making it noise. In order to allow for changing the identity, we instead provide git_repository_set_ident() and git_repository_ident() which allow a user to override the choice of signature.
* git_filter_opt_t -> git_filter_flag_tEdward Thomson2015-02-191-1/+1
| | | | | For consistency with the rest of the library, where an opt is an options *structure*.