src/refdb_fs.c


Log

Author Commit Date CI Message
Carlos Martín Nieto 21e0fc32 2016-11-14T17:55:49 Plug a leak in the refs compressor
Carlos Martín Nieto ce5553d4 2016-03-10T22:01:09 refdb: bubble up locked files on the read side On Windows we can find locked files even when reading a reference or the packed-refs file. Bubble up the error in this case as well to allow callers on Windows to retry more intelligently.
Carlos Martín Nieto 33248b9e 2016-03-10T12:22:34 refdb: remove a check-delete race when removing a loose ref It does not help us to check whether the file exists before trying to unlink it since it might be gone by the time unlink is called. Instead try to remove it and handle the resulting error if it did not exist.
Carlos Martín Nieto 2e09106e 2015-12-24T17:49:49 refdb: bubble up the error code when compressing the db This allows the caller to know the errors was e.g. due to the packed-refs file being already locked and they can try again later.
Carlos Martín Nieto dd1ca6f1 2015-12-24T17:38:41 refdb: refactor the lockfile cleanup We can reduce the duplication by cleaning up at the beginning of the loop, since it's something we want to do every time we continue.
Carlos Martín Nieto 7ea4710a 2015-12-24T17:30:24 refdb: don't report failure for expected errors There might be a few threads or processes working with references concurrently, so fortify the code to ignore errors which come from concurrent access which do not stop us from continuing the work. This includes ignoring an unlinking error. Either someone else removed it or we leave the file around. In the former case the job is done, and in the latter case, the ref is still in a valid state.
Carlos Martín Nieto 2d9aec99 2015-12-24T14:01:38 refdb: make ref deletion after pack safer In order not to undo concurrent modifications to references, we must make sure that we only delete a loose reference if it still has the same value as when we packed it. This means we need to lock it and then compare the value with the one we put in the packed file.
Carlos Martín Nieto 9914efec 2015-12-24T14:00:48 refdb: bubble up errors We can get useful information like GIT_ELOCKED out of this instead of just -1.
Patrick Steinhardt b27ccad2 2016-03-10T16:11:51 refdb_fs: fail if refcache returns NULL pointer We usually check entries returned by `git_sortedcache_entry` for NULL pointers. As we have a write lock in `packed_write`, though, it really should not happen that the function returns NULL. Assert that ref is not NULL to silence a Coverity warning.
Patrick Steinhardt 793e0855 2016-02-22T14:06:48 refdb_fs: remove unnecessary check for NULL The fail-label of `reflog_parse` explicitly checks the entry poitner for NULL before freeing it. When we jump to the label the variable has to be set to a non-NULL and valid pointer though: if the allocation fails we immediately return with an error code and if the loop was not entered we return with a success code, withouth executing the label's code. Remove the useless NULL-check to silence Coverity.
Edward Thomson 318b825e 2016-02-16T17:11:46 index: allow read of index w/ illegal entries 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`).
Edward Thomson 0a700ee3 2015-11-03T17:34:54 reflog: error when a directory is at reflog path When a non-empty directory exists and prevents the creation of a reflog, provide a more informative error message.
Edward Thomson b46c7ee5 2015-11-03T17:18:00 refs: complain when a directory exists at ref When a (non-empty) directory exists at the reference target location, complain with a more actionable error message.
Carlos Martín Nieto fd74bd08 2015-10-29T20:37:48 Merge pull request #3486 from srajko/reflog-segfault-fix Fix segfault when reading reflog with extra newlines
Stjepan Rajko 335c9e2f 2015-10-26T15:33:00 Prevent segfault when parsing a reflog with oid parse error Using calloc instead of malloc because the parse error will lead to an immediate free of committer (and its properties, which can segfault on free if undefined - test_refs_reflog_reflog__reading_a_reflog_with_invalid_format_returns_error segfaulted before the fix). #3458
Vicent Marti 1e5e02b4 2015-10-27T17:26:04 pool: Simplify implementation
Edward Thomson ac2fba0e 2015-09-16T15:07:27 git_futils_mkdir_*: make a relative-to-base mkdir 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.
Edward Thomson ed1c6446 2015-07-28T11:41:27 iterator: use an options struct instead of args
Carlos Martín Nieto 01d0c02d 2015-07-12T19:08:06 refdb: delete a ref's reflog upon deletion Removing a reflog upon ref deletion is something which only some backends might wish to do. Backends which are database-backed may wish to archive a reflog, log-based ones may not need to do anything.
Carlos Martín Nieto d578b45f 2015-03-08T16:46:33 refdb: use the same id for old and new when renaming a reference When we rename a reference, we want the old and new ids to be the same one (as we did not change it). The normal code path looks up the old id from the current value of the brtanch, but by the time we look it up, it does not exist anymore and thus we write a zero id. Pass the old id explicitly instead.
Stefan Widgren c8e02b87 2015-02-15T21:07:05 Remove extra semicolon outside of a function Without this change, compiling with gcc and pedantic generates warning: ISO C does not allow extra ‘;’ outside of a function.
Jeff Hostetler 1589a93a 2015-02-02T16:50:10 Fix branch creation when branch name matches namespace of previously deleted branch
Edward Thomson ee5da720 2014-12-02T22:20:42 reference_create: validate loose names Validate loose reference names on Win32.
Edward Thomson a64119e3 2014-11-25T18:13:00 checkout: disallow bad paths on win32 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.
Carlos Martín Nieto ab8d9242 2014-06-28T06:39:38 Introduce reference transactions A transaction allows you to lock multiple references and set up changes for them before applying the changes all at once (or as close as the backend supports). This can be used for replication purposes, or for making sure some operations run when the reference is locked and thus cannot be changed.
Carlos Martín Nieto 2d945f82 2014-06-02T17:44:51 refs: copy the packed refs on iteration This lets us work without worrying about what's happening but work on a snapshot.
Russell Belfer 2b52a0bf 2014-05-13T16:32:27 Increase use of config snapshots And decrease extra reload checks of config data.
Carlos Martín Nieto 4f9d5414 2014-04-26T14:29:18 refdb: fix typo and wording
Russell Belfer 18234b14 2014-02-21T09:14:16 Add efficient git_buf join3 API There are a few places where we need to join three strings to assemble a path. This adds a simple join3 function to avoid the comparatively expensive join_n (which calls strlen on each string twice).
Carlos Martín Nieto 1c351659 2014-03-20T09:55:47 reflog: remove some dead code
Carlos Martín Nieto 83504371 2014-03-19T22:27:23 reflog: follow core.logallrefupdates On bare by default, or when core.logallrefupdates is false, we must not write the reflog.
Carlos Martín Nieto 99797c96 2014-03-19T18:14:35 reflog: handle symref chains Given HEAD -> master -> foo, when updating foo's reflog we should also update HEAD's, as it's considered the current branch.
Carlos Martín Nieto 6aaae94a 2014-03-19T16:30:37 reflog: handle the birth of a branch The reflog append function was overzealous in its checking. When passed an old and new ids, it should not do any checking, but just serialize the data to a reflog entry.
Carlos Martín Nieto afc57eb4 2014-03-19T06:59:09 reflog: simplify the append logic Remove some duplicated logic.
Carlos Martín Nieto 1afe1400 2014-03-18T22:16:58 refdb: don't update when there's no need If the caller wants to update a ref to point to the same target as it currently has, we should return early and avoid writing to the reflog.
Carlos Martín Nieto bac95e6e 2014-03-18T19:41:03 reflog: more comprehensive HEAD tests The existing ones lack checking zeroed ids when switching back from an unborn branch as well as what happens when detaching. The reflog appending function mistakenly wrote zeros when dealing with a detached HEAD. This explicitly checks for those situations and fixes them.
Carlos Martín Nieto 4b7e1b9e 2014-01-15T13:19:48 refs: append to the HEAD reflog when updating the current branch When we update the current branch, we must also append to HEAD's reflog to keep them in sync. This is a bit of a hack, but as git.git says, it covers 100% of default cases.
Carlos Martín Nieto ae32c54e 2014-03-05T20:28:49 Plug a few leaks in the tests
Carlos Martín Nieto a213a7bf 2014-03-05T20:32:53 refdb: catch a directory disappearing If a directory disappears between the time we look up the entries of its parent and the time when we go to look at it, we should ignore the error and move forward. This fixes #2046.
Carlos Martín Nieto 77ad6754 2014-02-10T14:38:01 refs: conditional wording fixups This addresses arrbee's concerns about wording in the conditional reference udpate functions.
Carlos Martín Nieto b7ae71ec 2014-02-05T11:47:33 refs: catch cases where the ref type has changed If the type of the on-disk reference has changed, the old value comparison should fail.
Carlos Martín Nieto 7ee8c7e6 2014-02-05T11:07:34 refs: placeholder conditional delete We don't actually pass the old value yet.
Carlos Martín Nieto f8621dde 2014-02-05T10:42:42 refs: factor out old value comparison We will reuse this later for deletion.
Carlos Martín Nieto 91123661 2014-02-04T22:04:00 refdb: add conditional symbolic updates Add a parameter to the backend to allow checking for the old symbolic target.
Carlos Martín Nieto 1202c7ea 2014-02-04T21:35:44 refs: fix leak on successful update Free the old ref even on success.
Carlos Martín Nieto fc4728e3 2014-01-29T14:07:18 refs: return GIT_EMODIFIED if the ref target moved In case we loose the race to update the reference, return GIT_EMODIFIED to let the user distinguish it from other types of errors.
Carlos Martín Nieto 9b148098 2013-12-18T19:58:16 refs: conditional ref updates Allow updating references if the old value matches the given one.
Ben Straub 7f058b86 2014-02-01T19:29:48 Check for errors when dereferencing symbolic refs
Ben Straub ee8e6afd 2014-02-01T11:46:44 Reflog: correct "new" id for reattaching HEAD
Ben Straub 6357388e 2014-01-27T13:24:10 Enhance clarity
Ben Straub a2311f92 2014-01-27T13:12:31 Ensure updating HEAD updates reflog
Vicent Marti 4e1f517c 2013-12-18T09:33:45 Merge pull request #1920 from libgit2/cmn/ref-with-log Reference operations with log
Russell Belfer 25e0b157 2013-12-06T15:07:57 Remove converting user error to GIT_EUSER 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.
Russell Belfer 96869a4e 2013-12-03T16:45:39 Improve GIT_EUSER handling This adds giterr_user_cancel to return GIT_EUSER and clear any error message that is sitting around. As a result of using that in places, we need to be more thorough with capturing errors that happen inside a callback when used internally. To help with that, this also adds giterr_capture and giterr_restore so that when we internally use a foreach-type function that clears errors and converts them to GIT_EUSER, it is easier to restore not just the return value, but the actual error message text.
Carlos Martín Nieto f2105129 2013-11-23T14:39:53 refs: expose has_log() on the backend The frontend used to look at the file directly, but that's obviously not the right thing to do. Expose it on the backend and use that function instead.
Carlos Martín Nieto 8d5ec910 2013-11-23T14:13:01 refs: expose a way to ensure a ref has a log 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.
Carlos Martín Nieto 6f13a305 2013-11-17T23:26:49 reflog: write to the reflog following git's rules git-core only writes to the reflogs of HEAD, refs/heads/ and, refs/notes/ or if there is already a reflog in place. Adjust our code to follow these semantics.
Carlos Martín Nieto a57dd3b7 2013-11-13T18:15:20 reflog: integrate into the ref writing Whenever a reference is created or updated, we need to write to the reflog regardless of whether the user gave us a message, so we shouldn't leave that to the ref frontend, but integrate it into the backend. This also eliminates the race between ref update and writing to the reflog, as we protect the reflog with the ref lock. As an additional benefit, this reflog append on the backend happens by appending to the file instead of parsing and rewriting it.
Carlos Martín Nieto 110df893 2013-11-13T13:36:37 refdb: add a `message` parameter for appending to the log This is as yet unused.
Edward Thomson 1d3a8aeb 2013-11-04T18:28:57 move mode_t to filebuf_open instead of _commit
Ben Straub 8f4a8b09 2013-10-28T06:20:28 Merge pull request #1802 from libgit2/cmn/reflog-backend Make reflog part of refdb
Russell Belfer 219d3457 2013-10-01T16:12:15 Initial iconv hookup for precomposed unicode 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.
Russell Belfer 2fe54afa 2013-09-30T16:58:33 Put hooks in place for precompose in dirload fn 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.
Carlos Martín Nieto 0174794a 2013-08-21T05:12:49 reflog: bring _append and _drop back to the frontend These functions act purely on the reflog data structure.
Carlos Martín Nieto b976f3c2 2013-08-19T13:01:49 reflog: move the reflog implementation into refdb_fs References and their logs are logically coupled, let's make it so in the code by moving the fs-based reflog implementation to live next to the fs-based refs one. As part of the change, make the function take names rather than references, as only the names are relevant when looking up and handling reflogs.
Edward Thomson e3f3868a 2013-09-24T11:04:14 'del' instead of 'delete' for the poor C++ users
nulltoken d0cd6c42 2013-09-08T18:22:28 path: Make direach() return EUSER on callback error
Russell Belfer 8d9a85d4 2013-08-22T11:40:53 Convert sortedcache to use rwlock This is the first use we have of pthread_rwlock_t in libgit2. Hopefully it won't cause any serious portability problems.
Russell Belfer fe372740 2013-08-21T16:26:32 Rewrite refdb_fs using git_sortedcache object This adds thread safety to the refdb_fs by using the new git_sortedcache object and also by relaxing the handling of some filesystem errors where the fs may be changed out from under us. This also adds some new threading tests that hammer on the refdb.
Russell Belfer 0f0f5655 2013-08-19T10:42:48 Don't try to pack symbolic refs If there were symbolic refs among the loose refs then the code to create packed-refs would fail trying to parse the OID out of them (where Git just skips trying to pack them). This fixes it.
Russell Belfer c77342ef 2013-07-22T11:20:34 Use pool for loose refdb string allocations Instead of using lots of strdup calls, this adds a memory pool to the loose refs iteration code and uses it for keeping track of the loose refs array. Memory usage could probably be reduced even further by eliminating the vector and just scanning by adding the strlen of each ref, but that would be a more intrusive changes. This also updates the error handling to be more thorough about checking for failed allocations, etc.
Russell Belfer b7107131 2013-07-22T11:01:19 git_reference_next_name must match git_reference_next The git_reference_next API silently skips invalid references when scanning the loose refs. The git_reference_next_name API should skip the same ones even though it isn't creating the reference object. This adds a test with a an invalid loose reference and makes sure that both APIs skip the same entries and generate the same results.
Russell Belfer 114f5a6c 2013-06-10T10:10:39 Reorganize diff and add basic diff driver This is a significant reorganization of the diff code to break it into a set of more clearly distinct files and to document the new organization. Hopefully this will make the diff code easier to understand and to extend. This adds a new `git_diff_driver` object that looks of diff driver information from the attributes and the config so that things like function content in diff headers can be provided. The full driver spec is not implemented in the commit - this is focused on the reorganization of the code and putting the driver hooks in place. This also removes a few #includes from src/repository.h that were overbroad, but as a result required extra #includes in a variety of places since including src/repository.h no longer results in pulling in the whole world.
Russell Belfer cee695ae 2013-05-31T12:18:43 Make iterators use GIT_ITEROVER & smart advance 1. internal iterators now return GIT_ITEROVER when you go past the last item in the iteration. 2. git_iterator_advance will "advance" to the first item in the iteration if it is called immediately after creating the iterator, which allows a simpler idiom for basic iteration. 3. if git_iterator_advance encounters an error reading data (e.g. a missing tree or an unreadable file), it returns the error but also attempts to advance past the invalid data to prevent an infinite loop. Updated all tests and internal usage of iterators to account for these new behaviors.
Vicent Marti 1ed356dc 2013-05-30T21:04:28 Frees
Vicent Marti 4e6e2ff2 2013-05-30T03:47:10 ...Aaaand this works
Vicent Marti ec24e542 2013-05-29T22:47:37 What are the chances, really
Vicent Marti 56960b83 2013-05-28T20:47:55 Liike this
Vicent Marti 2638a03a 2013-05-28T17:50:47 This refs iterator pleases the gods.
Eitan Adler 038c1654 2013-05-19T01:41:00 Initialize loose_deleted before it is used for a check later on.
nulltoken 1fed6b07 2013-05-13T21:57:37 Fix trailing whitespaces
Linquize 0cb16fe9 2013-05-15T20:26:55 Unify whitespaces to tabs
Russell Belfer 99d32707 2013-05-11T06:42:25 Fix refdb iteration early termination bug There was a problem found in the Rugged test suite where the refdb_fs_backend__next function could exit too early in some very specific hashing patterns for packed refs. This ports the Rugged test to libgit2 and then fixes the bug.
Edward Thomson b6cc559a 2013-05-11T02:42:49 Merge pull request #1385 from carlosmn/refs-iter Introduce a refs iterator
Carlos Martín Nieto 2b562c3a 2013-05-04T16:32:58 refs: remove the OID/SYMBOLIC filtering Nobody should ever be using anything other than ALL at this level, so remove the option altogether. As part of this, git_reference_foreach_glob is now implemented in the frontend using an iterator. Backends will later regain the ability of doing the glob filtering in the backend.
Carlos Martín Nieto 69a3c766 2013-05-04T15:03:32 refdb_fs: don't crash when the repo doesn't have a path
Carlos Martín Nieto 4def7035 2013-03-02T19:31:03 refs: introduce an iterator This allows us to get a list of reference names in a loop instead of callbacks.
Edward Thomson 617bb175 2013-05-09T17:44:44 calloc refs instead of malloc'ing them
Jeff King a591ed3e 2013-05-02T12:06:46 refdb_fs: respect PEELING_STANDARD We only set our negative flag for PEELING_FULL; we can fall back to the lesser PEELING_STANDARD if our ref is in the refs/tags/ hierarchy.
Vicent Marti 822645f6 2013-05-02T17:48:49 refdb_fs: Only strstr the traits line
Vicent Marti 1022db2b 2013-05-02T17:42:09 refdb_fs: Traits are always surrounded by spaces This makes parsing easier! :p
Vicent Marti f69db390 2013-05-02T17:29:58 refdb_fs: store "cannot be peeled" flag for packed refs Fixes #1532
Vicent Marti 3bb00f33 2013-05-02T17:17:46 refdb_fs: implement the fully-peeled trait
Jeff King 7edb9071 2013-05-02T11:07:20 refdb_fs: do not require peeled packed refs to be tags Older versions of git would only write peeled entries for items under refs/tags/. Newer versions will write them for all refs, and we should be prepared to handle that.
Vicent Marti 8cddf9b8 2013-05-01T18:21:10 refdb: Properly load namespaces
Vicent Marti 2ba55c1f 2013-05-01T15:20:08 refdb: Proper namespace root
Vicent Marti bade5194 2013-04-30T21:02:13 lol namespaces
Vicent Marti a5de9044 2013-04-23T02:24:44 refs: Better error name
Russell Belfer 53607868 2013-04-15T00:09:03 Further threading fixes This builds on the earlier thread safety work to make it so that setting the odb, index, refdb, or config for a repository is done in a threadsafe manner with minimized locking time. This is done by adding a lock to the repository object and using it to guard the assignment of the above listed pointers. The lock is only held to assign the pointer value. This also contains some minor fixes to the other work with pack files to reduce the time that locks are being held to and fix an apparently memory leak.
Russell Belfer 21ca0451 2013-04-21T12:52:17 Move git_reference__alloc to include/git2/sys Create a new include/git2/sys/refs.h and move the reference alloc functions there. Also fix some documentation issues and some minor code cleanups.