Commit Graph

123 Commits

Author SHA1 Message Date
Carlos Martín Nieto
c2418f4613 Rename FALLBACK to UNSPECIFIED
Fallback describes the mechanism, while unspecified explains what the
user is thinking.
2015-06-25 12:48:44 +02:00
Carlos Martín Nieto
c4e3a3dbfa submodule: handle writing out all enum values for settings
We currently do not handle those enum values which require us to set
"true" or unset variables in all cases. Use a common function which does
understand this by looking at our mapping directly.
2015-06-22 17:02:56 +02:00
Carlos Martín Nieto
961861fafa submodule: get rid of _save()
We no longer have any setters which affect an instance, so
`git_submodule_save()` is no longer relevant.
2015-06-22 17:02:55 +02:00
Carlos Martín Nieto
d6073b30f3 submodule: make _set_url() affect the configuration
With this one, we can get rid of the edit_and_save test.
2015-06-22 17:02:55 +02:00
Carlos Martín Nieto
486ba4cdd3 submodule: make _set_branch() affect the configuration 2015-06-22 17:02:55 +02:00
Carlos Martín Nieto
4e63642321 submodule: make _set_update_fetch_recurse_submodules() affect the config
Similarly to the other ones. In this test we copy over testing
`RECURSE_YES` which shows an error in our handling of the `YES` variant
which we may have to port to the rest.
2015-06-22 17:02:55 +02:00
Carlos Martín Nieto
e8a39f8ed1 submodule: make _set_update() affect the configuration
Moving on with the removal of runtime-changing variables, the update
setting for a remote is whatever it was when it was looked up.
2015-06-22 17:02:55 +02:00
Carlos Martín Nieto
2278637c4a submodule: correct detection of existing submodules
During the cache deletion, the check for whether we consider a submodule
to exist got changed regarding submodules which are in the worktree but
not configured.

Instead of checking for the url field to be populated, check the
location where we've found it.
2015-06-22 17:02:55 +02:00
Carlos Martín Nieto
d769a3fdda submodule: bring back finding by path
During the removal of the cache, we also removed the ability to use
`_lookup()` to search by path rather than name. Bring this logic back.
2015-06-22 17:02:55 +02:00
Carlos Martín Nieto
c6f489c964 submodule: add an ignore option to status
This lets us specify in the status call which ignore rules we want to
use (optionally falling back to whatever the submodule has in its
configuration).

This removes one of the reasons for having `_set_ignore()` set the value
in-memory. We re-use the `IGNORE_RESET` value for this as it is no
longer relevant but has a similar purpose to `IGNORE_FALLBACK`.

Similarly, we remove `IGNORE_DEFAULT` which does not have use outside of
initializers and move that to fall back to the configuration as well.
2015-06-22 17:02:55 +02:00
Carlos Martín Nieto
64bbd47a32 submodule: don't let status change an existing instance
As submodules are becomes more like values, we should not let a status
check to update its properties. Instead of taking a submodule, have
status take a repo and submodule name.
2015-06-22 17:02:55 +02:00
Carlos Martín Nieto
5a9fc6c83c submodule: make set_ignore() affect the configuration
Instead of affecting a particular instance, make it change the
configuration.
2015-06-22 17:02:55 +02:00
Carlos Martín Nieto
dfda2f68ea submodule: remove the per-repo cache
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.
2015-06-22 17:02:54 +02:00
Carlos Martín Nieto
624c949f01 index: make relative comparison use the checksum as well
This is used by the submodule in order to figure out if the index has
changed since it last read it. Using a timestamp is racy, so let's make
it use the checksum, just like we now do for reloading the index itself.
2015-06-20 16:17:28 +02:00
Carlos Martín Nieto
8f0104ecc5 Remove the callbacks struct from the remote
Having the setting be different from calling its actions was not a great
idea and made for the sake of the wrong convenience.

Instead of that, accept either fetch options, push options or the
callbacks when dealing with the remote. The fetch options are currently
only the callbacks, but more options will be moved from setters and
getters on the remote to the options.

This does mean passing the same struct along the different functions but
the typical use-case will only call git_remote_fetch() or
git_remote_push() and so won't notice much difference.
2015-05-13 09:46:35 +02:00
Patrick Steinhardt
129788a623 Implement git_submodule_set_branch. 2015-04-12 10:51:08 +02:00
Patrick Steinhardt
e6903ea278 Fix git_submodule_sync writing URL to wrong key.
Currently git_submodule_sync writes the submodule's URL to the
key 'branch.<REMOTE_NAME>.remote' while the reference
implementation of `git submodule sync` writes to
'remote.<REMOTE_NAME>.url', which is the intended behavior
according to git-submodule(1).
2015-03-12 16:05:07 +01:00
Carlos Martín Nieto
4e498646b6 repository: remove log message override for switching the active branch
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.
2015-03-03 14:40:50 +01:00
Carlos Martín Nieto
659cf2029f Remove the signature from ref-modifying functions
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.
2015-03-03 14:40:50 +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
David Calavera
c868981f0e Add extern function to initialize submodule update options. 2015-01-07 09:04:49 -06:00
Edward Thomson
5018e2c639 submodule: declare vars at top of func block 2015-01-06 17:08:38 -06:00
Jameson Miller
9d1f97df10 Introduce a convenience function for submodule update
This introduces the functionality of submodule update in
'git_submodule_do_update'. The existing 'git_submodule_update' function is
renamed to 'git_submodule_update_strategy'. The 'git_submodule_update'
function now refers to functionality similar to `git submodule update`,
while `git_submodule_update_strategy` is used to get the configured value
of submodule.<name>.update.
2014-12-22 16:37:35 -05:00
Jameson Miller
b2ab887e11 submodule init should resolve relative url paths
Submodule init should handle relative paths in .gitmodules files
and resolve these urls when updating the git config file.
2014-12-22 16:35:45 -05:00
Carlos Martín Nieto
209425ce26 remote: rename _load() to _lookup()
This brings it in line with the rest of the lookup functions.
2014-11-08 13:28:27 +01:00
Jameson Miller
bc737620dd Introduce option to use relative paths for repository work directory
Teach git_repository_init_ext to use relative paths for the gitlink
to the work directory. This is used when creating a sub repository
where the sub repository resides in the parent repository's
.git directory.
2014-09-02 21:07:26 -04:00
Russell Belfer
1e4976cb01 Be more careful with user-supplied buffers
This adds in missing calls to `git_buf_sanitize` and fixes a
number of places where `git_buf` APIs could inadvertently write
NUL terminator bytes into invalid buffers.  This also changes the
behavior of `git_buf_sanitize` to NUL terminate a buffer if it can
and of `git_buf_shorten` to do nothing if it can.

Adds tests of filtering code with zeroed (i.e. unsanitized) buffer
which was previously triggering a segfault.
2014-05-08 10:17:14 -07:00
Russell Belfer
7d4908724f Attribute file cache refactor
This is a big refactoring of the attribute file cache to be a bit
simpler which in turn makes it easier to enforce a lock around any
updates to the cache so that it can be used in a threaded env.
Tons of changes to the attributes and ignores code.
2014-04-17 14:56:41 -07:00
Russell Belfer
40ed499039 Add diff threading tests and attr file cache locks
This adds a basic test of doing simultaneous diffs on multiple
threads and adds basic locking for the attr file cache because
that was the immediate problem that arose from these tests.
2014-04-17 14:43:45 -07:00
Russell Belfer
eedeeb9e8f Test (and fix) the git_submodule_sync changes
I wrote this stuff a while ago and forgot to write tests.  Wanted
to do so now to wrap up the PR and immediately found problems.
2014-04-03 11:58:51 -07:00
Russell Belfer
18cc7d28c4 Minor code cleanup 2014-04-03 11:29:08 -07:00
Jan Melcher
f2fb4bac68 git_submodule_resolve_url supports relative urls
The base for the relative urls is determined as follows, with descending
priority:

- remote url of HEAD's remote tracking branch
- remote "origin"
- workdir

This follows git.git behaviour
2014-04-03 10:44:08 -07:00
Russell Belfer
4ece3e225b Fix submodule accounting for name and path changes
Wrote tests that try adding, removing, and updating the name of
submodules which showed a number of problems with how we account
for changes when incrementally updating the submodule info.  Most
of these issues didn't exist before because reloading would always
blow away the old submodule data.
2014-04-01 12:19:11 -07:00
Russell Belfer
aa78c9ba77 Minor submodule cache locking improvements
This improvement the management of the lock around submodule cache
updates slightly, using the lock to make sure that foreach can
safely make a snapshot of all existing submodules and making sure
that git_submodule_add_setup also grabs a lock before inserting
the new submodule.  Cache initialization / refresh should already
have been holding the lock correctly as it adds submodules.
2014-04-01 10:22:51 -07:00
Russell Belfer
eeeb9654f0 Reinstate efficient submodule reloading
This makes it so that git_submodule_reload_all will actually only
reload changed items unless the `force` flag is used.
2014-04-01 09:49:58 -07:00
Russell Belfer
a4ccd2b001 Use enums instead of bools for submodule options
When forcing cache flushes or reload, etc., it is easier to keep
track of intent using enums instead of plain bools.  Also, this
fixes a bug where the cache was not being properly refreshes by
a git_submodule_reload_all.
2014-04-01 09:49:58 -07:00
Russell Belfer
db0e7878d3 Make submodule refresh a bit smarter
This makes submodule cache refresh actually look at the timestamps
from the data sources for submodules and reload as needed if they
have changed since the last refresh.
2014-04-01 09:48:37 -07:00
Russell Belfer
69b6ffc4c5 Make a real submodule cache object
This takes the old submodule cache which was just a git_strmap
and makes a real git_submodule_cache object that can contain other
things like a lock and timestamp-ish data to control refreshing of
submodule info.
2014-04-01 09:48:37 -07:00
Russell Belfer
e402d2f134 Submodule sync refactoring
Turns out there was already a helper to do what I wanted to do,
so I just made it so that I could use it for sync and switched to
that instead.
2014-04-01 09:45:20 -07:00
Russell Belfer
8286300a1e Fix git_submodule_sync and add new config helper
This fixes `git_submodule_sync` to correctly update the remote URL
of the default branch of the submodule along with the URL in the
parent repository config (i.e. match core Git's behavior).

Also move some useful helper logic from the submodule code into
a shared config API `git_config__update_entry` that can either set
or delete an entry with constraints like not overwriting or not
creating a new entry.  I used that helper to update a couple other
places in the code.
2014-04-01 09:45:20 -07: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
Russell Belfer
945c92a5cf Add faster git_submodule__is_submodule check 2014-03-31 12:40:58 -07:00
Russell Belfer
acdc7cff2e Fix memory leak of submodule branch name 2014-03-27 15:29:17 -07:00
Russell Belfer
add8db06f9 Fix use-after-free in submodule reload
If the first call to release a no-longer-existent submodule freed
the object, the check if a second is needed would dereference the
data that was just freed.
2014-03-27 15:28:29 -07:00
Russell Belfer
380f864a10 Fix error when submodule path and name differ
When a submodule was inserted with a different path and name, the
return value from khash greater than zero was allowed to propagate
back out to the caller when it should really be zeroed.  This led
to a possible crash when reloading submodules if that was the
first time that submodule data was loaded.
2014-03-26 16:06:21 -07:00
Russell Belfer
22df47cbc5 Fix segfault if gitmodules is invalid
The reload_all call could end up dereferencing a NULL pointer if
there was an error while attempting to load the submodules config
data (i.e. invalid content in the gitmodules file).  This fixes it.
2014-03-26 14:38:26 -07:00
Russell Belfer
591e82952a Fix submodule leaks and invalid references
This cleans up some places I missed that could hold onto submodule
references and cleans up the way in which the repository cache is
both reloaded and released so that existing submodule references
aren't destroyed inappropriately.
2014-03-25 16:52:01 -07:00
Russell Belfer
a15c7802c8 Make submodules externally refcounted
`git_submodule` objects were already refcounted internally in case
the submodule name was different from the path at which it was
stored.  This makes that refcounting externally used as well, so
`git_submodule_lookup` and `git_submodule_add_setup` return an
object that requires a `git_submodule_free` when done.
2014-03-25 09:14:48 -07:00
Carlos Martín Nieto
9af14886a9 MSVC is silly 2014-03-10 18:20:47 +01:00
Jan Melcher
52fba18f4e Add git_submodule_resolve_url() 2014-03-10 18:16:10 +01:00