summaryrefslogtreecommitdiff
path: root/src/stash.c
Commit message (Collapse)AuthorAgeFilesLines
* str: introduce `git_str` for internal, `git_buf` is externalethomson/gitstrEdward Thomson2021-10-171-37/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Fix coding style for pointerpunkymaniac2021-09-091-1/+1
| | | | Make some syntax change to follow coding style.
* stash: use GIT_ASSERTEdward Thomson2020-11-271-1/+3
|
* 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.
* Fix uninitialized stack memory and NULL ptr dereference in stash_to_indexPhilip Kelley2020-05-101-2/+2
| | | | Caught by static analysis.
* stash: refactor code that prepares commit messagesPatrick Steinhardt2019-10-181-18/+15
|
* stash: modernize code style of `git_stash_save`Patrick Steinhardt2019-10-181-32/+15
| | | | | The code style of `git_stash_save` doesn't really match our current coding style. Update it to match our current policies more closely.
* stash: avoid recomputing tree when committing worktreePatrick Steinhardt2019-07-201-14/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When creating a new stash, we need to create there separate commits storing differences stored in the index, untracked changes as well as differences in the working directory. The first two will only be done conditionally if the equivalent options "git stash --keep-index --include-untracked" are being passed to `git_stash_save`, but even when only creating a stash of worktree changes we're much slower than git.git. Using our new stash example: $ time git stash Saved working directory and index state WIP on (no branch): 2f7d9d47575e Linux 5.1.7 real 0m0.528s user 0m0.309s sys 0m0.381s $ time lg2 stash real 0m27.165s user 0m13.645s sys 0m6.403s As can be seen, libgit2 is more than 50x slower than git.git! When creating the stash commit that includes all worktree changes, we create a completely new index to prepare for the new commit and populate it with the entries contained in the index' tree. Here comes the catch: by populating the index with a tree's contents, we do not have any stat caches in the index. This means that we have to re-validate every single file from the worktree and see whether it has changed. The issue can be fixed by populating the new index with the repo's existing index instead of with the tree. This retains all stat cache information, and thus we really only need to check files that have changed stat information. This is semantically equivalent to what we previously did: previously, we used the tree of the commit computed from the index. Now we're just using the index directly. And, in fact, the cache is doing wonders: time lg2 stash real 0m1.836s user 0m1.166s sys 0m0.663s We're now performing 15x faster than before and are only 3x slower than git.git now.
* configuration: cvar -> configmapPatrick Steinhardt2019-07-181-1/+1
| | | | | `cvar` is an unhelpful name. Refactor its usage to `configmap` for more clarity.
* Rename opt init functions to `options_init`Edward Thomson2019-06-141-1/+6
| | | | | | | | | | | | | In libgit2 nomenclature, when we need to verb a direct object, we name a function `git_directobject_verb`. Thus, if we need to init an options structure named `git_foo_options`, then the name of the function that does that should be `git_foo_options_init`. The previous names of `git_foo_init_options` is close - it _sounds_ as if it's initializing the options of a `foo`, but in fact `git_foo_options` is its own noun that should be respected. Deprecate the old names; they'll now call directly to the new ones.
* git_error: use new names in internal APIs and usageEdward Thomson2019-01-221-11/+11
| | | | | Move to the `git_error` name in the internal API for error-related functions.
* stash: use _an_ index not _the_ indexEdward Thomson2018-06-291-28/+77
| | | | | | | | | Don't manipulate the repository's index during stash; instead, manipulate a temporary index and check it out. This allows us to use the checkout mechanism to update the workdir and the repository's index, and allows checkout to use its common mechanisms to write data and handle errors.
* Convert usage of `git_buf_free` to new `git_buf_dispose`Patrick Steinhardt2018-06-101-4/+4
|
* checkout: change default strategy to SAFEEtienne Samson2018-03-261-3/+0
| | | As per #4200, our default is quite surprising to users that expect checkout to just "do the thing".
* 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.
* giterr_set: consistent error messagesEdward Thomson2016-12-291-6/+6
| | | | | | | | 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
* git_diff_generated: abstract generated diffsEdward Thomson2016-05-261-0/+1
|
* Horrible fix for #3173.Arthur Schreiber2016-02-111-4/+4
|
* iterator: use an options struct instead of argsEdward Thomson2015-08-281-12/+17
|
* Fix #3094 - improve use of portable size_t/ssize_t format specifiers.Matthew Plough2015-07-121-1/+1
| | | | The header src/cc-compat.h defines portable format specifiers PRIuZ, PRIdZ, and PRIxZ. The original report highlighted the need to use these specifiers in examples/network/fetch.c. For this commit, I checked all C source and header files not in deps/ and transitioned to the appropriate format specifier where appropriate.
* stash: drop unused variableEdward Thomson2015-06-291-2/+1
|
* stash: stage new files when unstashing themEdward Thomson2015-06-251-0/+78
| | | | | Files that were new (staged additions) in the stash tree should be staged when unstashing, even when not applying the index.
* stash: don't allow apply with staged changesEdward Thomson2015-06-251-0/+26
|
* stash: save the workdir file when deleted in indexEdward Thomson2015-06-231-3/+26
| | | | | | | | | | | | | | When stashing the workdir tree, examine the index as well. Using a mechanism similar to `git_diff_tree_to_workdir_with_index` allows us to determine that a file was added in the index and subsequently modified in the working directory. Without examining the index, we would erroneously believe that this file was untracked and fail to include it in the working directory tree. Use a slightly modified `git_diff_tree_to_workdir_with_index` in order to avoid some of the behavior custom to `git diff`. In particular, be sure to include the working directory side of a file when it was deleted in the index.
* Write modified index in git_stash_apply()Pierre-Olivier Latour2015-06-211-0/+2
| | | | | Same as with git_stash_save(), there's no reason not to write the index to disk since it has been modified.
* Rename GIT_EMERGECONFLICT to GIT_ECONFLICTEdward Thomson2015-05-291-1/+1
| | | | | | | | | | We do not error on "merge conflicts"; on the contrary, merge conflicts are a normal part of merging. We only error on "checkout conflicts", where a change exists in the index or the working directory that would otherwise be overwritten by performing the checkout. This *may* happen during merge (after the production of the new index that we're going to checkout) but it could happen during any checkout.
* Fix a few leaksCarlos Martín Nieto2015-05-131-4/+8
| | | | | The interesting one is the notification macro, which was returning directly on a soft-abort instead of going through the cleanup.
* stash: propagate the error when writing a treeEdward Thomson2015-05-111-1/+1
|
* stash_apply: provide progress callbacksEdward Thomson2015-05-111-3/+23
|
* stash_apply: provide its own options structureEdward Thomson2015-05-111-28/+35
|
* stash apply: default to at least GIT_CHECKOUT_SAFEEdward Thomson2015-05-111-2/+3
|
* stash: return GIT_EMERGECONFLICT on merge conflictEdward Thomson2015-05-111-3/+1
|
* stash: refactor to use merge_iteratorsEdward Thomson2015-05-111-172/+93
|
* stash: ensure a reflog has entriesEdward Thomson2015-05-111-2/+2
|
* stash apply: check out a tree, not piecewiseEdward Thomson2015-05-111-32/+11
|
* stash: use git_commit_summary for a summaryEdward Thomson2015-05-111-12/+4
|
* Added git_stash_apply() and git_stash_pop() APIsPierre-Olivier Latour2015-05-111-0/+371
|
* Merge pull request #2913 from ethomson/stash_fixupEdward Thomson2015-03-031-2/+1
|\ | | | | stash: correctly stash wd modified/index deleted
| * stash: correctly stash wd modified/index deletedEdward Thomson2015-02-181-2/+1
| |
* | Remove the signature from ref-modifying functionsCarlos Martín Nieto2015-03-031-3/+2
|/ | | | | | | | | | 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.
* transaction: rename lock() to lock_ref()cmn/reference-transactionCarlos Martín Nieto2014-10-091-1/+1
| | | | | This leaves space for future expansion to locking other resources without having to change the API for references.
* stash: use a transaction to modify the reflogCarlos Martín Nieto2014-09-301-13/+17
| | | | | | | | | The stash is implemented as the refs/stash reference and its reflog. In order to modify the reflog, we need avoid races by making sure we're the only ones allowed to modify the reflog. We achieve this via the transactions API. Locking the reference gives us exclusive write access, letting us modify and write it without races.
* Recurse ignored directories when stashingJacques Germishuys2014-09-261-3/+5
|
* Several CppCat warnings fixedArkady Shapkin2014-09-031-1/+2
|
* Make stash and checkout ignore contained reposRussell Belfer2014-04-221-1/+2
| | | | | | | | | | | To emulate git, stash should not remove untracked git repositories inside the parent repo, and checkout's REMOVE_UNTRACKED should also skip over these items. `git stash` actually prints a warning message for these items. That should be possible with a checkout notify callback if you wanted to, although it would require a bit of extra logic as things are at the moment.
* git_checkout_opts -> git_checkout_optionsBen Straub2014-03-061-1/+1
|
* Remove ignored files from the working directory if they were stashedJacques Germishuys2014-03-041-2/+7
|
* refs: remove the _with_log differentiationCarlos Martín Nieto2014-01-151-2/+2
| | | | | | Any well-behaved program should write a descriptive message to the reflog whenever it updates a reference. Let's make this more prominent by removing the version without the reflog parameters.
* Merge pull request #1920 from libgit2/cmn/ref-with-logVicent Marti2013-12-181-15/+9
|\ | | | | Reference operations with log
| * refs: expose a way to ensure a ref has a logCarlos Martín Nieto2013-12-091-0/+3
| | | | | | | | | | | | Sometimes (e.g. stash) we want to make sure that a log will be written, even if it's not in one of the standard locations. Let's make that easier.