Commit Graph

107 Commits

Author SHA1 Message Date
Carlos Martín Nieto
6ab65b80b4 refdb: bubble up recursive rm when locking a ref
Failure to bubble up this error means some locking errors do not get reported as
such on Windows.
2016-12-16 11:33:54 +00:00
Carlos Martín Nieto
21e0fc32ab Plug a leak in the refs compressor 2016-11-14 17:55:49 +01:00
Carlos Martín Nieto
ce5553d48b 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.
2016-11-14 11:35:38 +01:00
Carlos Martín Nieto
33248b9edb 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.
2016-11-14 11:35:38 +01:00
Carlos Martín Nieto
2e09106e7a 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.
2016-11-14 11:35:37 +01:00
Carlos Martín Nieto
dd1ca6f15a 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.
2016-11-14 11:35:35 +01:00
Carlos Martín Nieto
7ea4710ae3 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.
2016-11-14 11:34:14 +01:00
Carlos Martín Nieto
2d9aec99fb 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.
2016-11-14 11:34:08 +01:00
Carlos Martín Nieto
9914efec2a refdb: bubble up errors
We can get useful information like GIT_ELOCKED out of this instead of
just -1.
2016-11-14 11:25:58 +01:00
Patrick Steinhardt
b27ccad274 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.
2016-03-11 14:20:15 +01:00
Patrick Steinhardt
793e085536 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.
2016-02-23 11:50:23 +01:00
Edward Thomson
318b825e76 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`).
2016-02-17 13:10:33 +00:00
Edward Thomson
0a700ee368 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.
2015-11-12 09:39:29 -05:00
Edward Thomson
b46c7ee5e2 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.
2015-11-12 09:35:51 -05:00
Carlos Martín Nieto
fd74bd0842 Merge pull request #3486 from srajko/reflog-segfault-fix
Fix segfault when reading reflog with extra newlines
2015-10-29 20:37:48 +01:00
Stjepan Rajko
335c9e2f45 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
2015-10-29 11:15:37 -07:00
Vicent Marti
1e5e02b4f4 pool: Simplify implementation 2015-10-28 10:13:13 +01:00
Edward Thomson
ac2fba0ecd 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.
2015-09-17 10:00:35 -04:00
Edward Thomson
ed1c64464a iterator: use an options struct instead of args 2015-08-28 18:39:47 -04:00
Carlos Martín Nieto
01d0c02dba 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.
2015-07-12 19:08:06 +02:00
Carlos Martín Nieto
d578b45f3f 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.
2015-03-08 16:50:27 +01:00
Stefan Widgren
c8e02b8776 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.
2015-02-15 21:07:05 +01:00
Jeff Hostetler
1589a93aa6 Fix branch creation when branch name matches namespace of previously deleted branch 2015-02-03 10:33:04 -05:00
Edward Thomson
ee5da720e5 reference_create: validate loose names
Validate loose reference names on Win32.
2014-12-16 10:08:56 -06:00
Edward Thomson
a64119e396 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.
2014-12-16 10:08:53 -06:00
Carlos Martín Nieto
ab8d9242f5 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.
2014-09-30 15:44:32 +02:00
Carlos Martín Nieto
2d945f82f6 refs: copy the packed refs on iteration
This lets us work without worrying about what's happening but work on a
snapshot.
2014-06-02 17:50:30 +02:00
Russell Belfer
2b52a0bfae Increase use of config snapshots
And decrease extra reload checks of config data.
2014-05-13 16:32:27 -07:00
Carlos Martín Nieto
4f9d54146d refdb: fix typo and wording 2014-04-26 14:29:18 +02:00
Russell Belfer
18234b14ad 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).
2014-04-01 09:45:20 -07:00
Carlos Martín Nieto
1c35165993 reflog: remove some dead code 2014-03-20 19:18:50 +01:00
Carlos Martín Nieto
8350437112 reflog: follow core.logallrefupdates
On bare by default, or when core.logallrefupdates is false, we must not
write the reflog.
2014-03-20 19:18:49 +01:00
Carlos Martín Nieto
99797c96cd 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.
2014-03-19 18:14:35 +01:00
Carlos Martín Nieto
6aaae94a70 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.
2014-03-19 16:52:20 +01:00
Carlos Martín Nieto
afc57eb48f reflog: simplify the append logic
Remove some duplicated logic.
2014-03-19 15:54:33 +01:00
Carlos Martín Nieto
1afe140043 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.
2014-03-19 15:54:33 +01:00
Carlos Martín Nieto
bac95e6e1e 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.
2014-03-18 19:58:52 +01:00
Carlos Martín Nieto
4b7e1b9e92 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.
2014-03-17 17:47:47 +01:00
Carlos Martín Nieto
ae32c54e58 Plug a few leaks in the tests 2014-03-07 16:03:15 +01:00
Carlos Martín Nieto
a213a7bfa8 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.
2014-03-05 21:00:15 +01:00
Carlos Martín Nieto
77ad675464 refs: conditional wording fixups
This addresses arrbee's concerns about wording in the conditional
reference udpate functions.
2014-02-10 14:38:01 +01:00
Carlos Martín Nieto
b7ae71ecf2 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.
2014-02-05 12:07:57 +01:00
Carlos Martín Nieto
7ee8c7e677 refs: placeholder conditional delete
We don't actually pass the old value yet.
2014-02-05 12:07:57 +01:00
Carlos Martín Nieto
f8621dde40 refs: factor out old value comparison
We will reuse this later for deletion.
2014-02-05 12:07:57 +01:00
Carlos Martín Nieto
911236619b refdb: add conditional symbolic updates
Add a parameter to the backend to allow checking for the old symbolic
target.
2014-02-05 12:07:56 +01:00
Carlos Martín Nieto
1202c7eaa6 refs: fix leak on successful update
Free the old ref even on success.
2014-02-05 12:07:56 +01:00
Carlos Martín Nieto
fc4728e3e2 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.
2014-02-05 12:07:56 +01:00
Carlos Martín Nieto
9b148098e6 refs: conditional ref updates
Allow updating references if the old value matches the given one.
2014-02-05 12:07:56 +01:00
Ben Straub
7f058b8668 Check for errors when dereferencing symbolic refs 2014-02-01 19:31:26 -08:00
Ben Straub
ee8e6afda9 Reflog: correct "new" id for reattaching HEAD 2014-02-01 11:46:44 -08:00