Commit graph

64 commits

Author SHA1 Message Date
Dirk Hohndel
c4eb9571be Cloud storage: inform the user if remote sync failed
Being silent in this particular case was the wrong decision as it hides
problems.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-25 10:45:39 -07:00
Dirk Hohndel
f622516dd0 Cloud storage: more user friendly handling of local cache corruption
When dealing with cloud storage most of the time the user will not be
familiar with git. So if the local cache is corrupted don't leave them to
clean up the mess. Instead just move things out of the way (just in case
they know how to extract data from the damaged local repository) and ask
them to restart the operation which should give them a fresh copy of their
data from the remote server (minus any local changes that hadn't been
synced to the server before things went bad).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-23 05:14:46 -07:00
Dirk Hohndel
d0fba482b7 Cloud storage: in verbose mode give lots of progress information
If a user gets stuck accessing cloud storage it's often hard to figure out
which step is hanging which makes it much harder to narrow down the
problem. With this patch calling Subsurface with '-v' will give somewhat
finely grained progress information on stderr.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-20 10:15:34 -07:00
Dirk Hohndel
54ec332c2f Cloud storage: verbose output to console
If Subsurface is started with the verbose flag, also give progress
information on the consol (just in case there are issues with the progress
dialog).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-20 10:15:34 -07:00
Dirk Hohndel
5ba74130c0 Cloud storage: make user visible messages more consistent
I hate this patch. But it makes no sense to expose users to git level
error messages. So this is trying to make things much easier (and,
frankly, less informative) if we are accessing the Subsurface cloud.

The way this is implemented is really ugly; it tries to avoid frequent
repetition of the same strings by using different exit points for the
functions in question. I'm not convinced this was the best way to do it
but it's what I have.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-18 11:51:50 -07:00
Anton Lundin
906cc8804d Be compatible with libgit2 0.22 again
The callback function was introduced in 0.23, so put it behind that
ifdef.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-10 15:30:12 -07:00
Dirk Hohndel
ae1c4ef21e Cloud storage: add another progress callback
This one sadly only appears to be called with 0% and 100% in my examples.
Not sure what to do about that.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-10 09:41:12 -07:00
Dirk Hohndel
2025bc1b2b Replace the spinner with a progress dialog for cloud storage access
Since the spinner caused all kinds of problems inside VMs, wasn't shown at
all for some people on Win10 and appeared to get stuck a lot and still
left people with the perception that Subsurface was hung, this patch takes
a more traditional approach and gives the user a progress dialog.

An additional benefit of this is that the user now can cancel a hung
transfer.

The slightly weird passing in of the callback allows for the separation of
UI and core logic code...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-09 13:02:39 -07:00
Anton Lundin
70d9297e3a Be compatible with libgit2 0.22 again
In libgit2 0.22 tree_flags was called flags.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-31 15:12:37 -07:00
Dirk Hohndel
a2c638f63f Cloud storage: attempt to deal with conflicts about deleted files
This doesn't seem right, but it works. Definitely needs more analysis.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-25 10:44:21 -07:00
Dirk Hohndel
449ba2876f Cloud storage: test offline operation
All this really does is make sure that the fast forward works if the local
cache has received updates that haven't made it to the server, yet.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-25 10:44:10 -07:00
Dirk Hohndel
39863089ed Cloud storage: adjust debugging messages
We shouldn't always tell the user about the perceived validity of the
cloud certificate - we force it anyway.

But it's nice to be easily able to see if we tried to update the remote,
so add another debug output when run with -v

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-25 10:44:02 -07:00
Dirk Hohndel
eb205c1b09 Cloud storage: be more verbose if asked to be verbose
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-25 10:43:36 -07:00
Dirk Hohndel
f177b2ec53 Cloud storage: try to brute force your way around merge issues
This seems to do the right thing in several cases that I tested, but I'm
worried if it might end up causing us data loss in other cases. This needs
a TON of testing.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-25 10:43:32 -07:00
Dirk Hohndel
70c38de3a1 Cloud storage: be very strict about renames
Because of the structure of some of our files git too easily assumed that
they were renames and that confused the merge algorithm.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-25 10:43:27 -07:00
Dirk Hohndel
a45c5f1acf When building against libgit2 v0.23 or newer we can assume API23
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-25 10:43:22 -07:00
Dirk Hohndel
471af6c2fd Cloud storage: clean up after the merge
Make sure the branch is pointing at the merge commit, etc.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-25 10:43:16 -07:00
Dirk Hohndel
f5eb0e2bbb Cloud storage: move git merge into its own function
Just to keep things more readable.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-25 10:43:11 -07:00
Dirk Hohndel
4c31c01139 Cloud storage: better error message for dirty state
Tell us WHAT is wrong with the state.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-25 10:43:01 -07:00
Dirk Hohndel
b8575221b1 Cloud storage: use merge options to avoid conflicts
In many cases Subsurface will do something "reasonable" if we have
conflicting edits and then try to merge. GIT_MERGE_FILE_FAVOR_UNION means
that both edits will be added to the final file and then Subsurface should
quietly take one or the other - this will need quite a bit of testing.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-22 17:52:31 -07:00
Dirk Hohndel
fe0864be60 Cloud storage: merge local and remote changes if there is no conflict
We still punt if there are any conflicts (which are likely to occur if we
have touched dive sites in both changes). But in my testing at least for
fairly simple, non-conflicting changes this works and creates a correctly
merged tree.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-22 17:52:31 -07:00
Robert C. Helling
56c90efba8 Explicit cast to stop compiler warning
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-17 21:09:22 -07:00
Dirk Hohndel
b554ed5ed6 Cloud storage: recognize our server certificate and accept it
On some platforms like Android the installed root certificates are rather
inconsistent. Same goes for older Windows machines. Instead of trying to
figure out how to get the user to install the right root certificates
(just kidding) we explicitly recognize our own server certificate and
allow that to override the validity assessment by the OS.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-13 11:20:18 -07:00
Dirk Hohndel
9e5e12b5e4 Cloud storage: provide more information in debug builds
It makes sense to hide git URLs from the end user in release builds, but
while developing and testing it's better to get more detailed information.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-13 07:11:55 -07:00
Dirk Hohndel
6811f77cdd Fix incorrect buffer length calculation
Oops, this is bad as it will lead to a certain buffer overrun.

The other change is more cosmetic - nested open comment '/*'.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-21 20:02:01 -07:00
Dirk Hohndel
ab90375c19 Use remote transport parameter instead of comparing strings
We pass it in, we might as well use it.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-19 07:31:15 -07:00
Linus Torvalds
eff3fd3261 git save: fix crash with no remote
Commit e21cae2d46 ("Cloud storage: sync the remote after save") broke
regular git saving without any remotes: it would never initialize the
"remote" pointer, and then use that uninitialized remote pointer to see
if it was a cloud storage remote that it should try to sync.

Fix it.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-16 21:40:31 -07:00
Dirk Hohndel
bd11988f74 Cloud storage: warn the user if we are not online
This isn't perfect, but at least tells the user if we weren't able to
connect and are working just off the local cache.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-16 14:09:37 -07:00
Dirk Hohndel
c593dea119 Cloud storage: use preference member instead of hard coded strings
This creates the basis to allow other backends to be used with the cloud
storage infrastructure.

So far this should all just transparently continue to work. A user would
have to manually add the cloud_base_url entry to the CloudStorage section
in their config file in order to use a different backend server.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-15 10:22:00 -07:00
Gaetan Bisson
77dae89b90 Fix compiling against libgit2-0.22.1
I have no idea whether the semantics is right, this patch was only
written so Subsurface compiles against the current stable release of
libgit2.

[Dirk Hohndel: added an extra conditional so this also compiles with the
	       curl-stream branch needed for https proxy support in
	       libgit2]

Signed-off-by: Gaetan Bisson <bisson@archlinux.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-14 20:49:37 -07:00
Dirk Hohndel
9ec155fad0 Cloud storage: clean up error propagation
We were falling of the end of a number of functions that were supposed to
return 0 on success or an error.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-13 20:03:20 -07:00
Dirk Hohndel
0c5ea57f1c Cloud storage: initialize local cache and remote on first use
There's no point in telling the user that the remote is empty. We need to
instead fix that and create the local cache and set things up for the
remote.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-13 18:36:08 -07:00
Dirk Hohndel
e6dce94088 Cloud storage: if there is no remote tracking branch, create it
When we first store things to the remote there won't be a matching branch
for it. And even if for some silly reason the remote branch got lost -
what's the point of telling the user that there is no remote branch? What
are they supposed to do about it. Let's just fix the problem and move on.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-13 18:36:08 -07:00
Dirk Hohndel
b413fabce7 Cloud storage: don't print confusing warning
This is no longer correct and is actively misleading. We now correctly
sync with the remote.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-13 18:24:27 -07:00
Dirk Hohndel
7b7568b1ba Cloud storage: setup proxy before cloning new repository
If we don't have a repository yet, we can't setup the proxy option before
calling into libgit2. Instead we use a callback.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-13 09:14:48 -07:00
Dirk Hohndel
abde615c1c Cloud storage: give user friendly error messages
Instead of showing the git URL and talking about failures to clone
repositories, simply tell the user what's happening with the cloud
storage.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-13 09:14:48 -07:00
Dirk Hohndel
3ad517d87a Cloud storage: check connectivity before trying to connect
With a new repository we take a different path.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-13 09:14:48 -07:00
Dirk Hohndel
9a22efb97b Move git related declarations into their own header file
Also change the name of the enum and make sure all the inner functions get
passed the remote transport information.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-13 09:14:48 -07:00
Dirk Hohndel
e21cae2d46 Cloud storage: sync the remote after save
This change once again tests if the remote can be reached. Even with a
fairly big data file and a medium speed internet connection the remote
sync is fast enough to call it nearly instantaneous. Maybe a couple of
seconds.

We may need more checks / different heuristics / warnings if the sync
didn't happen, etc. But for now this should allow more reasonable testing.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-12 13:56:23 -07:00
Dirk Hohndel
57f2c81125 Add header for Qt helpers used from C functions
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-12 10:20:57 -07:00
Dirk Hohndel
4d06e8f7b5 Cloud storage: check connection before connecting
libgit2 takes forever (a minute or so) to figure out that it can't connect
to a remote server.
So if we are using https as connection protocol, quickly check utilizing
RFCs 2324/7168 to make sure we can reach the cloud server (and not some
captive portal or something).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-12 09:22:36 -07:00
Dirk Hohndel
5e0c546beb Cloud storage: Unset the proxy if none is configured
The settings are stored in the local cache repository - so without
resetting it a proxy would stay configured even if it was disabled in the
Subsurface preferences.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-12 09:22:35 -07:00
Dirk Hohndel
490d21806e Cloud storage: Setup http proxy for git connection
At the time of this commit support for this feature has not landed in
upstream libgit2, yet (but there is a pull request). Yet supporting this
here doesn't appear to cause any issue with older versions of libgit2,
either, so the http proxy support will simply not work when enabled and a
version of libgit2 that's too old is used.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-12 09:22:27 -07:00
Dirk Hohndel
8ad000846d Cloud storage: use our credentials when updating the remote
If we are pushing to an ssh or https based remote we need to use our
credentials.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-10 21:55:19 -07:00
Dirk Hohndel
26cbc32495 Cloud storage
Use the credential helpers earlier in the source. This way we can use them
for the push as well.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-10 21:54:42 -07:00
Dirk Hohndel
e81a67f9d3 Cloud storage: track the repository type and pass the information around
This is easier than having various parts of the code to the string
comparison on the URL.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-10 21:54:25 -07:00
Linus Torvalds
39a0ac965b git storage: actually update the remote repository if the local cache is more recent
Again, note that this currently only happens when you initially open the repository.

So if you do

    subsurface https://.../repo[myubranch]

it will start up by fetching the remote information, and updating the
local cache.  If you then download new dives, and do a save-and-exit, it
will save to the local cache, but it doesn't do the fetch at this point,
so the remote is now begind.

The *next* time you start subsurface, and load that git branch again, it
will fetch the remote, and now notice that the local cache is ahead of
it (because you downloaded new dives and saved them locally), and *then*
it will try to update the remote with the new information.

This is obviously bogus, but we will need to decide exactly how we want
to sync with the remote repository.  But now the core functionality is
there, it's just that we need some interface to say "sync now".
Especially in the face of spotty (or non-working) internet, you want a
GUI etc for this whole remote sync, rather than doing it unconditionally
and silently whenever you load the local cache initially.

With that caveat:

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-10 20:57:57 -07:00
Linus Torvalds
971f1c6674 git storage: re-organize code to make 'origin' remote more widely available
I'm going to try to update the remote if the local cache is more recent
when we fetch the data, which requires access to the remote over a wider
range of code.  This re-organizes the code so that we can free the
remote later without having to have nasty error handling.

We avoid the whole "if an error happened, free the remote and return" by
creating helper functions and freeing the remote in the caller, so that
all paths end up freeing it naturally.

NOTE! We want to try to update the remote when we save the local cache
too, so this whole "update remote when opening it" is incomplete. But
 (a) we do want to do it here as well
and
 (b) this is the easiest place to create the initial "push to remote"
     code without any new "sync with cloud" interfaces.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-10 20:57:13 -07:00
Linus Torvalds
1379f34792 git storage: actually update cached copy from remote
We used to fetch the remote information but not actually do anything
about it, except report when it wasn't up-to-date.

Now we actually update the local cached copy if the remote has changed.

The code does not try to actually merge things, so only fast-forward
updates are done, but that should be the normal case.  We might
eventually do some simple merging on our own, but I suspect manual
merging may be the safer option.

We don't currently ever update the remote repository, and only inform
users that our local repository is ahead of the remote.  Fixing that is
the next step.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-10 18:13:25 -07:00
Dirk Hohndel
2a110811cf Cloud storage: be more careful when trying to determine a user name
Since we use the email address (including the '@' sign) as the repository
name we have to be more careful when trying to pick an account name from a
git URL.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-09 20:54:01 -07:00