aboutsummaryrefslogtreecommitdiffstats
path: root/core/load-git.c
AgeCommit message (Collapse)Author
2020-02-15load-git: fix up any corrupted modechange event namesGravatar Linus Torvalds
Because of the multiple string confusion, we'd get the names wrong for modechange events. If we then made other changes to the dive and saved the end result back, they'd now be wrong in the git cloud storage too. Fix it up manually by just noticing that there's a 'divemode' string on the event line, which can only happen with modechange events. Maybe we should report the fixup? This just silently fixes it (but only for the git save format). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-02-15load-git: clean up string handling during parsingGravatar Linus Torvalds
We had some fairly obscure rules for how strings were parsed, and it actually caused bugs when the same line had multiple strings in it. That normally doesn't happen, and the cases where it was _supposed_ to happen had special cases for it (divecomputer ID lines, and tag lines). But by mistake, we had introduced a case of that for the event line handling in commit b9174332d ("Read and write divemode changes (xml and git)"), and nobody realized that the divemode string addition meant that "oops, now it's corrupting the event name". An event line could look like this: event 40:00 type=8 divemode="OC" name="modechange" where we now had both that "OC" and "modechange" strings, and the code to pick the name just picked the first string. So we'd end up effectively mis-parsing the above line as event 40:00 type=8 divemode="OC" name="OC" which is obviously wrong. The dive mode didn't really need to be a string in the first place (there is nothing to quote, and no spaces in it), but hey, here we are. We can't just magially fix the existing broken saves. So make it more straightforward to handle strings in the git format line parser. We still stash the different decoded strings together in one special memory buffer, but now the parser helpers automatically untangle it as they traverse the key value pairs. This is still overly subtle code, and it doesn't fix the cases where we've saved the wrong data back. That comes later. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-01-10code cleanup: introduce empty_cylinder constantGravatar Dirk Hohndel
This deals with the issue of initializing structs in C++. 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-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-08-04Cleanup: use clear_git_id() instead of setting saved_git_idGravatar Berthold Stoeger
For better encapsulation, use clear_git_id() in clear_dive_file_data() instead of setting saved_git_id directly. Thus, memory management of the saved_git_id value is encapsulated and can be modified more easily. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-04Coding style: add spaces in load-git.cGravatar Berthold Stoeger
Add spaces before and after multiplication and addition operators. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-04Git: Make parser reentrantGravatar Berthold Stoeger
The git parser was using a number of global static variables. Remove them by introducing a parser state, which is passed down to the call hierarchy. Advantages: 1) Removes global variables and makes the parser (mostly) reentrant. 2) More flexible - e.g. when parsing samples, the parser can now access the dive to check if the cylinder number is valid. 3) Less weak typing through "void *". Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-04Cleanup: make functions in core/load-git.c localGravatar Berthold Stoeger
The function get_divemode() and git_tree_entry_blob() were not used outside of load-git.c. Make them of static linkage. 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-10Git: handle excess of cylinders or weightsystems gracefullyGravatar Berthold Stoeger
Currently, the git parser happily trashes memory if a git repository contains too many weightsystems or cylinders. This should only happen in testing, but nevertheless try to handle it gracefully and ignore excess cylinders / weightsystems. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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-05-11Cleanup: move parse_location() declaration into header fileGravatar Berthold Stoeger
The parse_location() function was used in three places. In two of them, the declaration was in the translation unit. Instead, move the declaration into a header file, to avoid duplication and the possibility of inconsistencies. The "units.h" header was chosen as this is where location_t is defined. Moreover, make the string argument to parse_location() "const char *", so that it can be used on non-owned buffers. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Dive site: add dive site ref-countingGravatar Berthold Stoeger
Instead of setting dive->dive_site directly, call the add_dive_to_dive_site() and unregister_dive_from_dive_site() functions. In the parser this turned out to be a bit tricky. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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: set UUID only on save or loadGravatar Berthold Stoeger
Since the UUID will be overwritten on save and is only used on save and load, set it only on save or load. For other created dive sites, leave the UUID field uninitialized. This means that the UUID will change between saves. Let's see how the git saver handles that. 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-03-27Cleanup: provide printGPSCoords in C and C++ versionsGravatar Berthold Stoeger
printGPSCoords() returned a newly allocated C-style string. Most callers simply made a QString out of it and freed the C-style string. This is paradoxical, as printGPSCoords internally works with QStrings and converts them to C-style on return. Therefore, let printGPSCoords() return a QString and create a printGPSCoordsC() wrapper for the two C-callers. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-03-24Cleanup: fix printGPSCoords signature and leaksGravatar Berthold Stoeger
The printGPSCoords() function returns a copied C-style string. Since the owndership is transferred to the caller, the correct return type is "char *" instead of "const char *". Thus a number of casts when calling free can be removed. Moreover a number of callers didn't free the string and thus were leaking memory. Fix them. Ultimately we might want two versions of the function: one for QString, one for C-style strings. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-09Core: add trip_table parameter to trip-functionsGravatar Berthold Stoeger
Currently trips are added to the global trip table. If we want to make dive-import undoable, we should be able to parse trips of a log-file into a distinct table. Therefore, add a trip_table parameter to - insert_trip() - create_and_hookup_trip_from_dive() - autogroup_dives() - unregister_trip() - remove_dive_from_trip() Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-21Git parser: don't produce user-visible error on git parsingGravatar Berthold Stoeger
In 64e6e435f82801f4f440ef5b1caf58a91a7c9929 the when field of struct trip was removed. Accordingly it was not read from git repositories. This produced a large amount of user-visible error messages. Reinstate the trip-date and time parsing functions, but ignore the value. 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-11-18Core: unify insert_trip() and insert_trip_dont_merge()Gravatar Berthold Stoeger
There were two versions of the insert_trip() function: one would merge trips if a trip with the same date already existed, the other wouldn't. The latter was introduced with the dive-list undo work. The problem is that the "date" of a trip (i.e. the first dive) seems ill-defined as this is a volatile value. Moreover in the context of making dive-import undoable this is a very dangerous notion, as the caller needs control over when the dives are added to a trip. Therefore, unify these two functions and never merge trips. The decision on merging dives now has to made by the caller. This will be implemented in a future commit. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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: return pointer to dive_site in create_dive_site_*()Gravatar Berthold Stoeger
This changes more of the dive-site interface to return pointers instead of UUIDs. Currently, most call sites directly extract UUIDs afterwards. Ultimately, the UUIDs will be generally replaced by pointers, which will then simplify these callers. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29Dive site: return pointer to dive_site in get_dive_site_*()Gravatar Berthold Stoeger
As a first step in removing dive-site uuids, change the interface of the get_dive_site_*() functions to return pointers instead of uuids. This makes code a bit more complicated in places where the uuid is extracted afterwards (needed NULL check). Nevertheless, these places should disappear once pointers instead of uuids are stored in the dive-structures. 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-10-11Undo: make diverse trip-related operations undo-ableGravatar Berthold Stoeger
AddDivesToTrip, CreateTrip, AutogroupDives, RemoveAutogenTrips and MergeTrips basically all did the same thing as RemoveDivesFromTrip, which was already implemented. Thus, factor our the common functionality and hook it up to make all these functions undo-able. Don't do the autogroup-call everytime the dive-list is rebuilt (that would create innumberable undo-actions), but only on dive-load / import or if expressly asked by the user [by switching the autogroup flag]. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-09-11cleanup[1/6]: do not set userid/save_userid_local from storageGravatar Jan Mulder
This the first of a set of cleanups related to the removal of 2 preferences: save_userid_local and userid. The commits are ordered so that a sane running state remains, should a bisect ever lands here. Here, just read a git or XML logbook including the to be removed preferences, as existing users can have this data sitting around. The only thing done here is not to store the possibly read data for the mentioned preferences. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-07-07git storage: avoid warning about "Unmatched action 'hash'"Gravatar Dirk Hohndel
In commit f3ef38ca0d ("Dive pictures: remove hashes") we removed picture hashes, but removing them from the git parser causes an ugly red warning when opening an existing cloud storage repo. With this patch we just silently ignore the hash. Fixes #1473 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
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>
2018-05-14Rename enum dive_comp_type to divemode_tGravatar Robert C. Helling
...as the usuage is not anymore about a computer but a momentary dive mode. Rename the end indicator as well. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-05-14Read and write divemode changes (xml and git)Gravatar Willem Ferguson
This provides for reading of divemode change events from dive logs and for writing them to dive logs. This applies to xml and git divelogs. Divemode change events have the following structure: event->name = "modechange" event->value = integer corresponding to enum dive_comp_type (dive.c), reflecting the type of divemode change (OC, CCR, PSCR, etc). In the dive log file, the event value is written as a string that corresponds to each of the enum values, e.g. <event name='modechange' divemode='OC' /> This xml is also read from the dive log file and translated to an appropriate value of event->value. The file diveeventitem.cpp was udated to reflect this new way of dealing with divemode change events. Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
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-03-05Cleanup: Remove hash field from picture-structureGravatar Berthold Stoeger
The hash field in the picture-structure was in principle non-operational. It was set on loading, but never actually changed. The authoritative hash comes from the filename->hash map. Therefore, make this explicit by removing the hash field from the picture structure. Instead of filling the picture structure on loading, add the hash directly to the filename->hash map. This is done in the register_hash() function, which does not overwrite old entries. I.e. the local hash has priority over the save-file. This policy might be refined in the future. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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-01-19Improve profile display in plannerGravatar Willem Ferguson
This patch allows the planner to save the last manually-entered dive planner point of a dive plan. When the plan has been saved and re-opened for edit, the time of the last-entered dive planner point is used to ensure that dive planning continues from the same point in the profile as was when the original dive plan was saved. Mechanism: 1) In dive.h, create a new dc attribute dc->last_manual_time with data type of duration_t. 2) In diveplanner.c, ensure that the last manually-entered dive planner point is saved in dc->last_manual_time. 3) In save-xml.c, create a new XML attribute for the <divecomputer> element, named last-manual-time. For dive plans, the element would now look like: <divecomputer model='planned dive' last-manual-time='31:17 min'> 4) In parse-xml.c, insert code that recognises the last-manual-time XML attribute, reads the time value and assigns this time to dc->last_manual_time. 5) In diveplannermodel.cpp, method DiveplannerPointModel::loadfromdive, insert code that sets the appropriate boolean value to dp->entered by comparing newtime (i.e. time of dp) with dc->last_manual_time. 6) Diveplannermodel.cpp also accepts profile data from normal dives in the dive log, whether hand-entered or loaded from dive computer. It looks like the reduction of dive points for dives with >100 points continues to work ok. The result is that when a dive plan is saved with manually entered points up to e.g. 10 minutes into the dive, it can be re-opened for edit in the dive planner and the planner re-creates the plan with manually entered points up to 10 minutes. The rest of the points are "soft" points, shaped by the deco calculations of the planner. Improvements: Improve code for profile display in dive planner This responds to #1052. Change load-git.c and save-git.c so that the last-manual-time is also saved in the git-format dive log. Several stylistic changes in text for consistent C source code. Improvement of dive planner profile display: Do some simplification of my alterations to diveplannermodel.cpp Two small style changes in planner.c and diveplannermodel.cpp as requested ny @neolit123 Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-11Introduce helper function empty_string()Gravatar Berthold Stoeger
There are ca. 50 constructs of the kind same_string(s, "") to test for empty or null strings. Replace them by the new helper function empty_string(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-04Turn autogroup from short into boolGravatar Berthold Stoeger
All users of autogroup are clearly expecting a boolean value, so let the type reflect this. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-26Cleanup: avoid dereferencing NULL pointerGravatar Dirk Hohndel
Coverity CID 208323 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-20core: ignore erroneous quotes as wellGravatar Jan Mulder
A small redo of 78bafe8f620a066. The quotes cause the original functionality not to work. Ignore them as well. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-18core: ignore bogus m in cylinderGravatar Jan Mulder
A bogus key/value pair was introduced in the cylinder, consisting of a lonely "m" without value. This is caused by commit 46004c39e26 and fixed in 48d9c8eb6eb0. See referenced commits for more info. Just ignore this key/value pair. No processing is broken due to this, as the git storage stores only metric SI type data. In fact, the m unit is superfluous anyway. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-11-27Store and load the planner related depth info of a cylinder in logfileGravatar Stefan Fuchs
Store cylinder.depth in XML files and in git storage. This info is in fact the gas switch depth of a specific gas/cylinder in the planner. This change avoids the need of typing in a user specific depth value again when replanning an existing planned dive. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>