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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
It's missing on Windows... we had this helper in liquivision.c but since I
used the function in git-access.c I figured I should just turn it into a
little helper.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
So far there is no mechanism to actually create a repository on the
server, so this only works with the two test repositories.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Cloud storage makes more sense that remote storage - at least I assume
that more people are used to thinking about "storing things in the cloud".
Don't use PIN or passphrase, call it a password everywhere.
Don't use copy_string() to copy the password - the git credentials routine
asserts that password is not NULL, so make sure we at least have a pointer
to an empty string here.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
I was afraid that this would only work with a farily current git master of
libgit2 and it turns out I was right. The API was available, but the
correct type wasn't.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
The key location is hard coded as this is only intended for our own
infrastructure, so we don't need multiple keys.
If the private key is protected by a passphrase, this needs to be manually
added to the preferences. As RemoteStorage->passphrase.
This has only be tested with a current version of libgit2 master, but
should compile with any previous version (the API doesn't exist in v0.19
and earlier - that's handled with appropriate #if clauses).
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Just as we would expect, the libgit2 developers of course once again broke
their API. In order to compile against current master we need to remap
those APIs once again.
Simply call cmake with -DUSE_LIBGIT23_API
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Ubuntu has git minor version 20 which has less parameters in
git-remote-fetch.
From ac9516984e4fbc787635b0dfd76649c8e43fab83 Mon Sep 17 00:00:00 2001
From: Patrick Valsecchi <patrick@thus.ch>
Date: Tue, 24 Feb 2015 08:45:21 +0100
Subject: [PATCH 2/2] Fix Ubuntu compilation error.
Ubuntu has git minor version 20 which has less parameters in
git-remote-fetch.
Signed-off-by: Patrick Valsecchi <patrick@thus.ch>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This fixes the problem with Windows being the usual non-POSIX PoS that it is..
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This doesn't really usefully work, but I'm committing it to have git
diff and history. It also insanely hardcodes the git-repo cache
directory, because right now it's purely useful for development.
The big missing pieces are:
- progress information
- credential callbacks not implemented
where the first one makes the user interface horrible (long delays with
nothing visibly going on), and the second one makes ssh logins etc not
work.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
It may be a bit less efficient to use a printf-style interface rather
than the explicit malloc and memcpy, but the code ends up simpler and
more readable.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This doesn't actually change any code, but it moves the 'is_git_repo()'
function that is used by both loading and saving into a new git-access.c
file.
This is where I'll start doing remote repo syncing too. Knock wood.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>