aboutsummaryrefslogtreecommitdiffstats
path: root/core/save-git.c
AgeCommit message (Collapse)Author
2020-10-26cleanup: fix resource leakGravatar Dirk Hohndel
And address typo in comment. Fixes CID 362915 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-25cleanup: split out divecomputer functions from dive.cGravatar Berthold Stoeger
Since dive.c is so huge, split out divecomputer-related functions into divecomputer.[c|h], sample.[c|h] and extradata.[c|h]. This does not give huge compile time improvements, since struct dive contains a struct divecomputer and therefore dive.h has to include divecomputer.h. However, it make things distinctly more clear. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25cleanup: break out event-related code into event.[c|h]Gravatar Berthold Stoeger
In an effort to reduce the size of dive.h and dive.c, break out the event related functions. Moreover event-names were handled by the profile-code, collect that also in the new source files. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16core: use C accessors in core/save-git.c instead of callbackGravatar Berthold Stoeger
Now we can simply loop over the list of devices. In this case, it's not much more readable, but at least we don't have that nasty pass user-data through "void *" pattern. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29filter: implement saving of filter presets to git repositoriesGravatar Berthold Stoeger
On the mailing list it was decided that users might want to move their filter presets across computers via the cloud. Notably, in the future one might access statistics on mobile and these might by controlled by filter presets. The git save routines use the same string formatting as the XML save routines. The string formatting is found in core/filterconstraint.cpp. Thus, duplication of code and inconsistencies should be minimized. Each filter preset is saved into a file in the "02-Filterpresets" folder in the root of the git repository. Each file consists of one "name" line, zero or one "fulltext" line and zero or more "constraint" lines. The modes, types and the actual payload is controlled via attributes. Thus, a preset file might look like this: name "test" fulltext mode="substring" query="clown" constraint type="location" stringmode="starstwith" data="mafia" constraint type="sac" rangemode="range" negate data="5000,10000" Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06media: use table instead of linked list for mediaGravatar Berthold Stoeger
For consistency with equipment, use our table macros for pictures. Generally tables (arrays) are preferred over linked lists, because they allow random access. This is mostly copy & paste of the equipment code. Sadly, our table macros are quite messy and need some revamping. Therefore, the resulting code is likewise somewhat messy. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01cleanup: move declaration of utc_mk* functions to new subsurface-time.h headerGravatar Berthold Stoeger
No point in slurping in all of dive.h for translation units that only want to do some time manipulation without ever touching a dive. Don't call the header "time.h", because we don't want to end up in a confusion with the system header of the same name. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01cleanup: move dive_table from dive.h to divelist.hGravatar Berthold Stoeger
This allows us to decouple dive.h and divelist.h, a small step in include disentangling. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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 additional debug outputGravatar Dirk Hohndel
This helps the user figure out why we weren't able to write a tree. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-10Merge pull request #2737 from Subsurface-divelog/libgitCleanupGravatar Dirk Hohndel
Libgit cleanup
2020-04-10media: move picture function from dive.c to picture.cGravatar Berthold Stoeger
Currently, move only those functions that do not access dive structures. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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-09cloud-storage: simplify creation of git authorshipGravatar Dirk Hohndel
While having the local user information in the repo on Linux seemed clever when we implemented it, it's inconsistent with all the other platforms. Let's just not do that unless the user has indeed set a global name/email pair for git. Instead indicate if this was Subsurface or Subsurface-mobile. 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-03-20Core: introduce invalid flag for divesGravatar Berthold Stoeger
Implement reading/writing the flag from/to XML/git. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-10cloud storage: add list of changes made to commit messagesGravatar Dirk Hohndel
This should make it easier to figure out what operations lead to the commit that is written to git. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-06core: read and write the user-specified salinityGravatar willemferguson
Both XML and git storage are added. Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-03Desktop: add additional star widgets to Information tabGravatar willemferguson
Provide file I/O for those star widgets that are enabled. The values of the widgets can be stored to and read from either xml or git. Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-11-09Cylinders: access cylinders with get_cylinder()Gravatar Berthold Stoeger
Instead of accessing the cylinder table directly, use the get_cylinder() function. This gives less unwieldy expressions. But more importantly, the function does bound checking. This is crucial for now as the code hasn't be properly audited since the change to arbitrarily sized cylinder tables. Accesses of invalid cylinder indexes may lead to silent data-corruption that is sometimes not even noticed by valgrind. Returning NULL instead of an invalid pointer will make debugging much easier. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Core: remove MAX_CYLINDERS restrictionGravatar Berthold Stoeger
Instead of using fixed size arrays, use a new cylinder_table structure. The code copies the weightsystem code, but is significantly more complex because cylinders are such an integral part of the core. Two functions to access the cylinders were added: get_cylinder() and get_or_create_cylinder() The former does a simple array access and supposes that the cylinder exists. The latter is used by the parser(s) and if a cylinder with the given id does not exist, cylinders up to that id are generated. One point will make C programmers cringe: the cylinder structure is passed by value. This is due to the way the table-macros work. A refactoring of the table macros is planned. It has to be noted that the size of a cylinder_t is 64 bytes, i.e. 8 long words on a 64-bit architecture, so passing on the stack is probably not even significantly slower than passing as reference. 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-18Core: dynamically resize weight tableGravatar Berthold Stoeger
Replace the fixed-size weightsystem table by a dynamically relocated table. Reuse the table-macros used in other parts of the code. The table stores weightsystem entries, not pointers to weightsystems. Thus, ownership of the description string is taken when adding a weightsystem. An extra function adds a cloned weightsystem at the end of the table. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-14Fix cylinder gas type saving when we have bogus gas use dataGravatar Linus Torvalds
Steve Williams reported a crash when saving a previously loaded dive as xml, and gave a gdb backtrace. It turns out that if we can't parse the cylinder use type (OC, diluent, oxygen, unused) we initialize the cylinder use to an invalid type, and then when we save it, we mess up. Fix it up by doing proper limit checking before accessing the "cylinderuse_text[]" array when saving. Reported-by: Steve <stevewilliams@internode.on.net> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-06-19Cleanup: move trip-related functions into own translation unitGravatar Berthold Stoeger
These functions were spread out over dive.c and divelist.c. Move them into their own file to make all this a bit less monolithic. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19Cleanup: move tag functions into own translation unitGravatar Berthold Stoeger
Make dive.h a bit slimmer. It's only a drop in the bucket - but at least when modifying tag functions not the *whole* application is rebuilt anymore. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-15Convert the atmospheric pressure in the Information Tab to an editable fieldGravatar willemferguson
The Information tab shows the atmospheric pressure. Make this value editable and also ensure that changes to it are undo-able. Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
2019-04-12Remove check for whether a site is used before saving it.Gravatar Doug Junkins
Signed-off-by: Doug Junkins <junkins@foghead.com>
2019-04-12Dive sites: prepare for dive site ref-countingGravatar Berthold Stoeger
Add a dive site table to each dive site to keep track of dives that have been added to a dive site. Add two functions to add dives to / remove dives from dive sites. Since dive sites now contain a dive table, the order of includes had to be changed: "divesite.h" now includes "dive.h" and not vice-versa. This caused some include churn. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Dive site: add dive site table parameter to dive site functionsGravatar Berthold Stoeger
To enable undo of dive site functions, it is crucial to work with different dive site tables. Therefore add a dive site table parameter to dive site functions. For now, always pass the global dive site table. Thus, this commit shouldn't alter any functionality. After this change, a simple search for dive_site_table reveals all places where the global dive site table is accessed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-02-28Cleanup: remove deletion of webservice dive sitesGravatar Berthold Stoeger
In the XML and git savers, unchanged webservice-dive sites were deleted. Since the webservice is not functional anymore, remove this code. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-16Don't allow empty username for gitGravatar Robert C. Helling
When no real name is set in /etc/passwd the username ends up being ",,,". Git does not like that. Actually, only the part before the first comma is the name, the rest is office and phone number. We don't want those. Before we only testing for the username being a NULL pointer. Reported-by: Keith Grimes Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-01-09Core: keep trips in table(s)Gravatar Berthold Stoeger
Currently, all trips are kept in a linked list. Replace the list by a table in analogy to dive_table. Use this to keep the trip_table sorted as suggested by dump_trip_list(). When inserting a trip into the table do that after adding the dives, to avoid warnings coming out of dump_trip_list(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-07Dive sites: don't delete unused dive sites on saveGravatar Berthold Stoeger
Unused dive sites were deleted on save. This clashed with the undo system in the following scenario: 1) Delete single-use dive site. 2) Save (dive site deleted) 3) Undo (reference to freed dive site) Therefore, as a quick-fix, keep the referenced dive site around. Note that this also means that empty dive sites must not be deleted, as it might refer to a dive in the undo system. Instead only clear references to empty dive sites in the global dive table. Factor this functionality out, as it was common to the XML and git savers. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-20Core: replace tripflag by notrip booleanGravatar Berthold Stoeger
The only remaining use of the tripflag was to mark dives that were removed explicitly from a trip, i.e. shouldn't be autogrouped. Therefore replace the enum by a simple boolean. Currently, there is no way of unsetting the notrip flag. But this shouldn't result in a user-visible change. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-18Core: remove "when" field of struct dive_tripGravatar Berthold Stoeger
The when field gives the time of the first dive. Instead of keeping this field in sync, replace it by a function that determines the time of the first dive. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-31Core: Do not crash on save dives with no dive site (git storage)Gravatar Jan Mulder
And fix a crash very similar to the previous commit. When trying to save (to git) with an empty dive site, ssrf crashes. Again, add a simple guard to prevent this. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-10-29Dive site: replace dive->dive_site_uuid by dive_siteGravatar Berthold Stoeger
Replace the UUID reference of struct dive by a pointer to dive_site. This commit is rather large in lines, but nevertheless quite simple since most of the UUID->pointer work was done in previous commits. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29Dive site: pass dive-site pointer to delete_dive_site()Gravatar Berthold Stoeger
Instead of passing a uuid, pass a pointer to the dive site. This is small step in an effort to remove uuids. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29Dive site: pass dive-site pointer to is_dive_site_used()Gravatar Berthold Stoeger
Instead of passing a uuid, pass a pointer to the dive site. This is small step in an effort to remove uuids. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-21Add 'location_t' data structureGravatar Linus Torvalds
Instead of having people treat latitude and longitude as separate things, just add a 'location_t' data structure that contains both. Almost all cases want to always act on them together. This is really just prep-work for adding a few more locations that we track: I want to add a entry/exit location to each dive (independent of the dive site) because of how the Garmin Descent gives us the information (and hopefully, some day, other dive computers too). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-11cleanup[3/6]: do not save the userid any moreGravatar Jan Mulder
Do not save the to be deleted prefences any more. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
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-08-23Cleanup: pass gasmix by valueGravatar Berthold Stoeger
In a previous commit, the get_gasmix_* functions were changed to return by value. For consistency, also pass gasmix by value. Note that on common 64-bit platforms struct gasmix is the size of a pointer [2 * 32 bit vs. 64 bit] and therefore uses the same space on the stack. On 32-bit platforms, the stack use is probably doubled, but in return a dereference is avoided. Supporting arbitrary gas-mixes (H2, Ar, ...) will be such an invasive change that going back to pointers is probably the least of our worries. This commit is a step in const-ifying input parameters (passing by value is the ultimate way of signaling that the input parameter will not be changed [unless there are references to said parameter]). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-23Cleanup: return gasmix by valueGravatar Berthold Stoeger
Currently, get_gasmix_from_event() and get_gasmix() return pointers to either static or to (possibly changing) dive data. This seems like a dangerous practice and the returned data should be used immediately. Instead, return the gasmix by value. This is in preparation of const-ifying input parameters of a number of core functions, which will ultimately let the merge() function take const-arguments in preparation of undo of dive-merging. On common 64-bit systems gasmix (two "int"s) is the size of a pointer and can be returned in a register. On 32-bit systems a pointer to the struct to be filled out will be passed. Since get_gasmix() now returns a value, the first invocation is tested by a NULL-initialized "struct event *". Document this in a comment. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-07-18Cleanup: rename trip->index to trip->savedGravatar Berthold Stoeger
The index-field was misused by the IO routines to mark which dives had been saved. Somewhat questionable, but let's at least name the field accordingly. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-07-07save-git: allocate user_info members on the heapGravatar Lubomir I. Ivanov
subsurface_user_info() only works on Linux (linux.c), but it doesn't allocate values on the heap. Solve this ownership problem by always allocating .name and .email on the heap in subsurface_user_info() and freeing in the caller. If subsurface_user_info() did not modify any of the values from NULL, use default ones, but allocate them on the heap too. Ref #1346 Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2018-07-04Dive pictures: remove hashesGravatar Berthold Stoeger
In the last commits, the canonical-to-local filename map was made independent from the image hashes and the location of moved images was based on filename not hashes. The hashes are now in principle unused (except for conversion of old-style local filename lookups). Therefore, remove the hashes in this commit. This makes addition of images distinctly faster. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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-24Cleanup: remove code related to picture-storage in git repositoriesGravatar Berthold Stoeger
Saving of pictures to git repositories was disabled. Finally remove this code and the corresponding load code. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>