aboutsummaryrefslogtreecommitdiffstats
path: root/core/git-access.c
AgeCommit message (Collapse)Author
2020-09-22cleanup: silence two compiler warnings in git-access.cGravatar Berthold Stoeger
gcc complained about two constructs of the kind remote_id && SSRF_INFO("..."); And while I am not a fan of excessive warnings, I must say it has a point here. That's just code obfuscation. In fact, it appears that the condition was wrong - the SSRF_INFO should probably be invoked if remote_id is NULL. The way it was written it would be invoked if it was *not* NULL. Change both instances to unfancy if statements. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-06-14git-storage: add global flag to indicate successful cloud syncGravatar Dirk Hohndel
This may seem like a bit heavy handed as it adds more global state, but given the number of ways in which attempts to sync with the cloud can fail it seems much more reliable to claim success in the spots where we actually know that we have successfully synced with the remote server. Transporting that information back through the various call chains turned out to be very disruptive and ugly, so I went with global state instead. Whenever we access cloud storage (or any git repo), we always first check if it actually is a git repo by calling is_git_repository() - so this is the perfect spot to initialize the variable to false. And there are only two spots where we either clone the remote repo (create_local_repo()) or update the remote with the (potentially merged) local changes (check_remote_status()). So those are the two places where we set the variable to true. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-06-14git storage: significantly expand logging to stderrGravatar Dirk Hohndel
In many cases we did not log the issues the code ran into to stderr which made remote debugging user problems much harder. This hopefully will help with that. Since I was looking at the code, I also made the existing messages more consistent. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-18core: debug cert callsGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-18core: bring back libgit2 certificate callbackGravatar Dirk Hohndel
Turns out that at least on Android libgit2 sometimes rejects valid certificates. And I cannot quite figure out when and why. But since we actually already checked the validity of the certificate when we called canReachCloudServer() (and the Qt code handles certificates correctly), we'll simply ignore this here and override the check to always return true for our cloud server. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-18debug output: ensure our debug output is captured on AndroidGravatar Dirk Hohndel
I would have bet money that Android used to send stderr to the logcat log, but apparently it doesn't (anymore?). So in order to be able to have a chance to debug weird cloud storage issues on Android, let's do some wholesale replacement of fprintf(stderr,...) with our own version of the INFO macro that we long ago borrowed from libdivecomputer (and rename it to ensure we don't have a conflict there). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-15git-storage: add helper function to delete remote branchGravatar Dirk Hohndel
This will be used by the test to clean up test branches that are created on the server. Since we aren't testing that functionality (it's not something that Subsurface itself ever does) the helper prints out errors it encounters, but doesn't report them back to the caller. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-15git-storage: fix up old broken local caches to use the right branchGravatar Linus Torvalds
If you had one of the unfortunate local git caches with a local HEAD just pointing to 'master', this will make note of that and then fix it up to use the proper branch name in the cache repository. [Dirk Hohndel: demoted from error to fprintf as most users won't care] Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-15git-storage: make creation of empty cache repo set the initial branchGravatar Linus Torvalds
In create_and_push_remote(), we set up the remote tracking etc to use the proper branch name, but never actually set up the initial local branch for the new cache repository at all. So the repository would end up with the default 'master' branch, instead of the branch name it should have. This went unnoticed, because most setups start by initializing the git caches by cloning from the cloud, and that worked fine. Debugged-by: Dirk Hohndel <dirk@hohndel.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-04-10Merge pull request #2736 from Subsurface-divelog/removeCloudOverrideGravatar Dirk Hohndel
core: remove cloud certificate override
2020-04-10cloud-storage: create consistent commit message for mergesGravatar Dirk Hohndel
This never made sense and I think I just forgot to complete this code when I first worked on it. Now we can see which version of Subsurface or Subsurface-mobile created a merge. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-09cleanup: remove support for ancient versions of libgit2Gravatar Dirk Hohndel
We require a minimum of libgit2 0.26. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-09core: remove cloud certificate overrideGravatar Dirk Hohndel
This code stopped being useful a long time ago. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-08-08Cleanup: move file-related function declarations to file.hGravatar Berthold Stoeger
A number of architecture-dependent functions were declared in dive.h. Move them to file.h so that not all file-manipulating translation units have to include dive.h. This is a small step in avoiding mass-recompilation on every change to dive.h Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08Cleanup: move error reporting function declarations to errorhelper.hGravatar Berthold Stoeger
Move the declarations of the "report_error()" and "set_error_cb()" functions and the "verbose" variable to errorhelper.h. Thus, error-reporting translation units don't have to import the big dive.h header file. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-18Cleanup: remove includes from qthelper.hGravatar Berthold Stoeger
To reduce interdependencies, remove the dive.h and divelist.h includes in qthelper.h Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Cleanup: remove "sha1.h" include in "dive.h"Gravatar Berthold Stoeger
No point in pulling that in for all users of "dive.h" Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-03-17Core: fix missing argument to report_errorGravatar Dirk Hohndel
The format requires a string argument. Found via LGTM.com Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-10prefs: git_local_only is not a preferenceGravatar Dirk Hohndel
It's the current state of the app, so it should be a global variable, not a preference. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-24core: replace (void) with UNUSED(x) and include ssrf.hGravatar jan Iversen
Unused parameters in C are "silenced" by adding UNUSED(x) Signed-off-by: Jan Iversen <jani@apache.org>
2018-05-14Core: don't inline rarely used functionGravatar Dirk Hohndel
This is only used by one caller and there doesn't appear to be a reason to inline it in the first place. Suggested-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-14Android: build fixGravatar Dirk Hohndel
On other OSs this compiles fine without adding this header, but Android is special... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-14Core: remove dive.h from files that don't need itGravatar Dirk Hohndel
Of course, quite a few of them indirectly get it through other header files. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-14Core: introduce new subsurface-string headerGravatar Dirk Hohndel
First small step to shrinking dive.h. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-02-26Cleanup: Unify qthelper.h and qthelperfromc.hGravatar Berthold Stoeger
Since all qt-helpers are defined in qthelper.cpp, there seems to be no reason to have two include files. By unifying the two files, duplication and inconsistencies are removed. The C++-only part is simply compiled away with #ifdefs. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-02-17Coding-style: remove superfluous parenthesesGravatar Berthold Stoeger
Mostly replace "return (expression);" by "return expression;" and one case of "function((parameter))" by "function(parameter)". Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-19Unify username handling of remote git repositoriesGravatar Berthold Stoeger
The username was extracted from https:// urls but not from ssh:// urls. Unify this by extracting the username from any remote url. This is done with regard to unifying the file handling in the frontend. For this approach to work, the credential callback of the ssh:// transport had to be adapted. It now also supports username/password in addition to private-key authentication. Currently, the only way the user can use the username/password authentication is by deleting a potential public key. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-19Support non-https:// repositories for savingGravatar Berthold Stoeger
On saving to a remote git repository, the transport was set to https://, which broke saving to ssh:// repositories. Instead determine the transport from the remote url. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-19Create local cache and push to remote for any remote repositoryGravatar Berthold Stoeger
This used to be done only for cloud repositories. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-19Check cloudserver availability only for cloud repositoriesGravatar Berthold Stoeger
The check used to be done for any https:// repository. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-19Factor out counting of authentication attempts into functionGravatar Berthold Stoeger
Moreover, make the maximum number of authentication attempts a const variable. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-17Use format_string() in core/git_access.cGravatar Berthold Stoeger
Since this helper-function exists, we might just use it. A subtle reuse of a buffer (string of second use was known to be shorter than string of first use) was replaced by a separate allocation. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-13Fix leak(s) in core/git-access.cGravatar Berthold Stoeger
The libgit2 functions git_cred_ssh_key_new() and git_cred_userpass_plaintext_new() copy their arguments. Therefore, free the string arguments or don't copy them in the first place. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-08Enter offline mode if sync with cloud failedGravatar Berthold Stoeger
In case syncing with the online repository failed, enter offline mode. This reflects the message sent to the user ("working with local copy"). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-26Cleanup: avoid memory leakGravatar Dirk Hohndel
No point in doing the strdup of the password if we then bail. Coverity CID 208316 Coverity CID 209293 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-05Gracefully handle cloud authentication failure in verbose modeGravatar Berthold Stoeger
If the credential functions return GIT_EUSER, a call to git_remote_fetch fails, but giterr_last() may return NULL. This led to a crash in verbose mode. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-03Free unused git repository in git_create_local_repo()Gravatar Berthold Stoeger
In this function, a repository is created, but the returned object is not used. Might just as well free it. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-02Fix file:// handling for git access.Gravatar Berthold Stoeger
Currently, in is_remote_git_repository(), git URLs of the form "file://..." are recognized as local and the "file://" prefix is removed. The shortened URL is then processed as if it was a remote URL, which of course has to fail. So far so good - this is not a remote repository after all. But the removal of the prefix is not propagated to the calling is_git_repository() function and handling as a local git repository therefore fails likewise. To fix this issue, move removal of the "file://" prefix one level up to the is_git_repository() function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-10-30Add a useful error message if we fail to connect to cloud serverGravatar Dirk Hohndel
Because now we are trying to open a URL as if it was a local file. Again, the goal is to accelerated debugging if things go wrong. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-30Improve parsing of git error messageGravatar Dirk Hohndel
This is rather fragile code, and the capitalization of the error message in libgit2 changed at some point. But commit 794739b4c0 ("strstr is a case sensitive compare") didn't really fix the problem - as it broke that same check for older libgit2 versions. Instead use our new helper function to make it work with libgit2 old and new. Also, add some more error output so the next time we run into this it's more obvious what broke and where. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-29Correctly create cloud account from mobileGravatar Jan Mulder
The creation of a cloud account from mobile was broken. This fixes it. Basically, we need to go online for a moment, and setup a correct local and remote repo for the cloud storage. Tested for the following scenarios: 1) inital account creation including PIN handling from mobile, from a clean install . 2) open an already validated cloud account from a clean install. 3) open no-cloud style local account. 4) Switch between 2 already validated could accounts. 5) Try to create a cloud account without data connection. Notice that scenario 4) does not work perfectly. A restart of the app is needed to see the new logbook. So that is to be fixed. Scenario 5) seems a non realistic corner case. This does not work in a gracefull way. The user needs to remove the app, install it again, and retry with data connection. Further notice this is backgroud/core processing only. So no QML UI changes as proposed (for example) bij Davide. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-07-29strstr is a case sensitive compareGravatar Jan Mulder
strstr is a case sensitive compare and the string reported from libgit2 reads "reference" and not "Reference". Further investigation reveals commit 909d5494368a0080 of libgit2. Here, the change is made from Reference to reference, breaking our rather poor way of detecting something from an error string. So, to be future-proof to more libgit2 oddities, it might be wise to use strcasestr in this situation. But this seems a not fully supported variant of strstr, so leave it at this point. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-07-29Fix small memory leakGravatar Jan Mulder
Add 2 forgotten free() statements for the temporary used string buffers. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-06-18Clean up git storage update messagesGravatar Dirk Hohndel
Translate all of them, but also remove some redundant or possibly misleading messages. These are now seen by users, not just developers trying to debug the code. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-17QML UI: redesign the user notificationGravatar Dirk Hohndel
The old system of cloud access updates with fake percentages just wasn't helpful. Even worse, it hid a lot important information from the user. This should be more useful (but it will require that we localize the messages sent from the git progress notifications and make them more 'user ready'). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-04-29Add SPDX header to core C filesGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-03-28Fix a crash when git init failsGravatar Miika Turkia
This can occur e.g. if directory permissions prevent one from writing to the local cloud storage directory. (Such a crash was discussed on mailing list.) The error message on GUI is misleading, claiming that cloud connection failed... Signed-off-by: Miika Turkia <miika.turkia@gmail.com> --- We probably should check the return value of other git operations as well, but going for bare minimum for now.
2017-03-12Only enable -Wmissing-field-initializers for ClangGravatar Lubomir I. Ivanov
The following pragma is Clang specific: It produces a warning: warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas] Only enable it for Clang by checking the __clang__ macro. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-02-24Fix "Load/Save to cloudstorage" for non-ASCII user namesGravatar Jeremie Guichard
On Windows that would fail because stat() doesn't deal well with our utf8 strings. Added new subsurface_stat() portability function to replace stat(). Added Windows implementation of subsurface_stat() using wstat(), with conversion to ut16 of the inputed path. Other platform implementations (linux, android) make use of the normal stat(). Added non ASCII test case in TestGitStorage::testGitStorageLocal() Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
2016-08-14Fix cloud storage authentication attempt countingGravatar Linus Torvalds
The authentication count was a static counter in the authentication callback, which gets incremented until we consider the authentication to have failed. The problem with that is that it doesn't get incremented for just _one_ authentication operation, it gets incremented each time you try to load or save, so eventually the code considers authentication to have failed even if nothing ever went wrong. This fixes it by making it static to the whole git-access file, and have each operation clear it before starting a new remote access. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>