aboutsummaryrefslogtreecommitdiffstats
path: root/save-git.c
AgeCommit message (Collapse)Author
2015-06-25Use our membuffer infrastructure to assemble stringGravatar Dirk Hohndel
We should use this consistently throughout the code instead of manually assembling strings and messing with memory all over the place. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-21Add helper function to return local filename of picture as C stringGravatar Dirk Hohndel
This way we can actually find the picture that we are showing. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-21Git storage: store pictures in the repositoryGravatar Dirk Hohndel
In order to be able to see pictures when using cloud storage from different machines, we really need to store the pictures with the dive data. This could be made optional with a preference, but for now I'll just enable it by default. Loading the pictures from git still needs to be implemented. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-21Git storage: replaces colons with equal in picture offsetGravatar Dirk Hohndel
I found another place where we had colons in file names... This fixes a small cut and paste error in an error message as well. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-20Track minimum datafile versionGravatar Dirk Hohndel
Add infrastructure and helper functions to track minimum datafile version. To make this information useful we need to keep the XML and git data format versions in track moving forward. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-19Git storage: change time encoding in directory namesGravatar Dirk Hohndel
We used to use [[yyyy-]mm-]nn-ddd-hh:mm:ss[~hex] in our git storage format for directory that contained dives. Problem with the is that on Windows the colon ':' is an illegal character in a filename. So libgit2 refuses to clone such a repository on Windows. So instead we now always write dive directories in git repositories as [[yyyy-]mm-]nn-ddd-hh=mm=ss[~hex] which replaces the ':' with an '='. Of course we load / parse both formats so that older formats still work. The next time they are written all the names change which causes rather huge commits, but that's the only way I see for cloud storage to work on Windows. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-18Git storage: don't abort if there is no default user/email setGravatar Dirk Hohndel
I never ran into this because all of my computers have a global default set for my name and email address. But if the user never uses git and has no global settings there will be no such info. Instead of failing we need to just set up a default ID and then try to get a best guess from the OS (just as we used to do before libgit2 supported getting the git settings for authorship). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-18Fix potential crash if the existing filename is NULLGravatar Dirk Hohndel
Should have used same_string() anyway... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-17Store the user's unit preferences in git storageGravatar Dirk Hohndel
Save and load a usually unused copy of the preferences with the units that were active the last time the dive list was saved to git storage (this isn't used in XML files); storing the unit preferences in the data file is usually pointless (that's a setting of the software, not a property of the data), but it's a great hint of what the user might expect to see when creating a backend service that visualizes the dive list without Subsurface running - so this is basically a functionality for the core library that Subsurface itself doesn't use but that another consumer of the library (like an HTML exporter) will need. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-17Git storage: only check git_id if saving to the same remoteGravatar Dirk Hohndel
If we switch to a different remote (let's say we opened a local git repo and want to save its content to the cloud storage) then don't check to make sure that the branch stayed unchanged (because, duh, it's a different remote, it will have changed). This fixes the problem where you could open an XML file and store it to cloud storage just fine, but opening a local git repository and then storing that to cloud storage failed. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-16git save: fix crash with no remoteGravatar Linus Torvalds
Commit e21cae2d46db ("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-15Cloud storage: use preference member instead of hard coded stringsGravatar Dirk Hohndel
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-13Cloud storage: clean up error propagationGravatar Dirk Hohndel
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-13Cloud storage: make do_git_save available to other modulesGravatar Dirk Hohndel
And add a parameter that tells it whether to try to save any Subsurface data or whether to just create a branch and push it out. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-13Move git related declarations into their own header fileGravatar Dirk Hohndel
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-12Cloud storage: sync the remote after saveGravatar Dirk Hohndel
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-10When saving only selected dives, only include referenced dive computersGravatar Dirk Hohndel
Since we should have far fewer dive computers than dives this straight forward algorithm shouldn't cause any performance issues. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-05-28Add USE_LIBGIT23_API as cmake optionGravatar Dirk Hohndel
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>
2015-02-27Add hashes to imagesGravatar Robert C. Helling
Upon successfull reading an image file, this computes a SHA1 hash of the image and saves it with the picture tag in the log file. When a file is not successfully loaded (for example because the log was created on a different computer) we look up the hash in a dictionary that maps hashes to local file names. That dictionary (actually two for both directions), is loaded on startup and saved upon destruction of the main window. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-15add and use a version.c / version.h pairGravatar Lubomir I. Ivanov
version.c is now object code which is recompiled each time ssrf-version.h changes, while the interface file version.h remains that same at all times and files which include it will not need to be recompiled. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-15Start splitting out git repo helper routinesGravatar Linus Torvalds
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>
2015-02-13Don't store empty dive sitesGravatar Dirk Hohndel
And remove references to them from the dives. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-13Always print dive site uuids as 8 digits / leading 0s in git formatGravatar Dirk Hohndel
Otherwise there are ugly spaces in the file names. This didn't break anything, per se, it's mostly cosmetic. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-12Get location from dive site for git commit messageGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-12Save and load dive sites in git formatGravatar Dirk Hohndel
Update the version to 3. Continue to read version 2 files and create dive sites on the fly. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-24api change in libgit2-0.22Gravatar Martin Gysel
Yet another api change in libgit2... let's quote the website "libgit2 is ... linkable library with a solid API ..." Signed-off-by: Martin Gysel <me@bearsh.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-10Refactor dctype -> divemodeGravatar Robert C. Helling
... and repair a failed rebase (sorry). Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-24CCR dive logs: git I/OGravatar willem ferguson
This patch privides for writing CCR dive log parameters to a git repository and for reading the data back from a git repository. This involves writing and reading the following members of the structures of sample: o2sensor[3] o2cylinderpressure and dc->no_o2sensors. Signed-off-by: willem ferguson <willemferguson@zoology.up.ac.za> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-20Prevent garbage from being saved in the userid fieldGravatar Dirk Hohndel
It seems that in some scenarios we end up with a string that isn't NUL terminated and that results in garbage being stored as userid. This patch is a little brute force but it fixes the problem even if a previous version os Subsurface ended up adding other text to the end of the userid. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-16Load and save the dc type for CCR divesGravatar Dirk Hohndel
Oddly we already had code to load this from XML, but nothing else. This makes the load from XML work like the rest of our code and adds the save to XML plus the load and save for the git format. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-16Save CCR cylinder use in XML and gitGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-07Load and save extra data in git formatGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-19Make planner work again for CCR divesGravatar Robert C. Helling
The latest CCR patches had rendered the planner not usable for CCR dives. This patch corrects this (and reenables the CCR set point column for segments). The problem was that a new member setpoint of struct divepoint had been introduced, but there was already po2 which had the same meaning. This patch merges the two and renames them setpoint to prevent future confusion. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-12Start sanitizing gaschange event informationGravatar Linus Torvalds
Decode the gasmix data into a sane format when creating the event, and add the (currently unused) ability to specify a gas change to a particular cylinder rather than (or in addition to) the gasmix. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-10Fix potential leak of branch in is_git_repositoryGravatar Anton Lundin
Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-09Add support divecomputer based TTSGravatar Anton Lundin
Since earlier have we had support for our own calculated TTS. This adds support for holding TTS values reported by a dive computer. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-29git-format: save dive picture dataGravatar Linus Torvalds
This doesn't actually parse the data at load time yet, but I need a save file to do that.. The diff looks larger than it is because this moves the "mktree()" function up earlier to be used by the picture saving code. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-03CCR code: Change to sample structureGravatar Willem Ferguson
1) All the variables in the sample structures are strongly typed 2) Two additional types were declared in units.h: o2pressure_t bearing_t 3) The following variables were added: diluentpressure o2setpoint o2sensor[3] 4) Changes to a number of files were made to chanf sample->po2 to sample->po2.mbar bearing to bearring.degrees Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-14git save: add list of dive computers to the commit messageGravatar Linus Torvalds
This makes it much more obvious what is going on when you save in between importing multiple dive computers, since the last dive description otherwise stays the same. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-14git save: don't crash if the last dive isn't in a tripGravatar Linus Torvalds
The git save tries to generate a nice commit message based on the most recent dive, but stupidly didn't check whether that dive was in a trip or not, and unconditionally used the trip pointer to see if there was a trip location. Which works well enough if you always generate trips, but is an unmitigated disaster otherwise. Oops. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-12Don't use locale for git save formatGravatar Linus Torvalds
I stupidly used "weekday()" without realizing we localize it. And we really don't want to make save formats be localized (we don't localize decimal numbers etc either). This fixes the git save format to just use a hardcoded weekday list. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-27make git save commit messages more informativeGravatar Linus Torvalds
Instead of just having "Created by subsurface <version>", put the number of dives and the location of the last dive in the message. That makes things like "gitk" show a much more useful view of what actually got saved. We still save the subsurface version in the body of the message, because that is interesting and relevant information. It's just not the *primary* relevant information. Anyway, with this, a git commit message might looke something like dive 474: North West Point (Christmas Island) Created by subsurface 4.0.96-17-g649e9ed89d9d which is much more relevant for the common case of adding new dives at the end. Of course, if the reason for the save is that you edited old dives, the relevance of the commit message telling you the number of dives you have in the log and the dive number is questionable. But then you have to look at the actual diff to see what's going on. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17Removed the globals 'userid' and 'save_userid_local' variablesGravatar Tomaz Canabrava
This is a preferences setting, it should belong to the preferences structure. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-14git-save: improve commit authorship dataGravatar Linus Torvalds
We used to always just commit as "subsurface@hohndel.org" because libgit-19 doesn't have the interfaces to do user name lookup. This does better if you have libgit-20, using "git_signature_default()" to get the actual user that does the saving. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-14Add option to save userid in data filesGravatar Venkatesh Shukla
The userid of Subsurface Webservice can be included in locally saved xml files and git repository. For xml files, it is stored in userid tag. For git repo, it is stored in 00-Subsurface file present in the repo. Preference dialog and webservice dialog modified to include option for saving userid locally. In case of difference in default userid and userid in local file, some semantics are followed. These can be referred to here: http://lists.hohndel.org/pipermail/subsurface/2014-April/011422.html Fixes #473 Signed-off-by: Venkatesh Shukla <venkatesh.shukla.eee11@iitbhu.ac.in> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-05Use helper function to write decimal numbersGravatar Gehad
Never ever use '%f' to write floating point data to a file. The stupid locale handling creates useless comma-infested output in some locales. Instead use one of our clever helper functions to do the right thing. Original patch by Gehad, modified by Linus to be a little more generic. Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-23save-git.c: fix another libgit2 API issueGravatar Lubomir I. Ivanov
GIT_CHECKOUT_OPTS_INIT, git_checkout_opts has changed to: GIT_CHECKOUT_OPTIONS_INIT, git_checkout_options Solution-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-19git object store: make it possible to work with checked-out git branchesGravatar Linus Torvalds
This makes the git object save logic also check out the changes in the working tree and index if the branch we save to is checked out. It used to be that we would just update the object store (and the branch ref, of course), but leave any checked-out state untouched. Note that if the working directory is dirty (ie you have made changes by hand and not committed them), the checkout will skip any dirty files and report it as a warning to the user. However, the save still succeeds (since the _real_ save goes to the backing store). NOTE NOTE NOTE! Both loading and saving very fundamentally work on the git object store level, and if you are working with a checked-out branch and make modifications to the working tree, saving will not touch those dirty files (so that you can try to recover your edits manually in the working tree), but it's worth pointing out that subsufrace loading state will totally ignore the working tree. So the only way to make subsurface *see* your changes is to commit them. Having edited state checked out in the working tree will only confuse you when subsurface first ignores it on reading, and then refuses to touch the checked-out state on writing. Put another way: working with a checked-out branch is now _possible_, but you need to be aware of the limitations. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-14Improved handling of git syntax names with no git repositoryGravatar Linus Torvalds
This makes "is_git_repository()" return non-NULL for all file names that match the git name pattern, even if we don't find an actual git repository there. That way, we won't fall back to writing out an XML file with an odd filename. If there is no actual git repository, we return a special invalid dummy pointer, and then the git reading and writing routines will catch it and return the appropriate error. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-14show the error string in the GUI rather than stderrGravatar Linus Torvalds
This makes the error string just be an internal "membuffer", which the GUI can fetch and show when errors occur. The error string keeps accumulating until somebody retrieves it with "get_error_string()". This should make any write errors actually show up to the user. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>