Commit graph

5289 commits

Author SHA1 Message Date
Linus Torvalds
eb47b2a8d8 Get rid of crazy empty tag_list element at the start
So this is totally unrelated to the git repository format, except for
the fact that I noticed it while writing the git saving code.

The subsurface divetag list handling is being stupid, and has a
initial dummy entry at the head of the list for no good reason.

I say "no good reason", because there *is* a reason for it: it allows
code to avoid the special case of empty list and adding entries to
before the first entry etc etc.  But that reason is a really *bad*
reason, because it's valid only because people don't understand basic
list manipulation and pointers to pointers.

So get rid of the dummy element, and do things right instead - by
passing a *pointer* to the list, instead of the list. And then when
traversing the list and looking for a place to insert things, don't go
to the next entry - just update the "pointer to pointer" to point to
the address of the next entry. Each entry in a C linked list is no
different than the list itself, so you can use the pointer to the
pointer to the next entry as a pointer to the list.

This is a pet peeve of mine. The real beauty of pointers can never be
understood unless you understand the indirection they allow. People
who grew up with Pascal and were corrupted by that mindset are
mentally stunted. Niklaus Wirth has a lot to answer for!

But never fear. You too can overcome that mental limitation, it just
needs some brain exercise. Reading this patch may help. In particular,
contemplate the new "taglist_add_divetag()".

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-10 11:36:17 -07:00
Lakshman
e8ee701d35 Fixed Subsurface coding style for classes in vim.
With the current suggested settings in `CodingStyle` content
of class blocks gets indented. To avoid this, value `g0` is
added to cinoptions. In addition to this `TODO` thing, few
additional options are suggested.

 - Included the value `(0` to cinoptions, to comply with the
   discontinuation of continuous lines as per Subsurface
   coding style recommendations.

Add two options that aren't exactly about coding style but about
convenience:

 - `hls` option to highlight all search options.
 - `is` option to do incremental search

Signed-off-by: Lakshman Anumolu <acrlakshman@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-10 11:34:49 -07:00
Lubomir I. Ivanov
41cec17cff Profile2: reset the zoom level when a new profile is drawn
If the user has zoomed in but then changes to a new dive,
we may want to reset the scale back to the original value (1.0)
based on the current zoomLevel, so that the profile is not stuck
in zoomed mode.

This patch adds a snippet that resets the QGraphicsView scale,
zoomLevel variable and also the toolTip position.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-10 09:02:31 -07:00
Lubomir I. Ivanov
324b8cbff1 Profile2: use a different image when no profile is visible
This patch adds a new image resource named poster.png which,
is shown instead of the 3 posters. The main reason for that
is due to the poster text not being visible. This new image
is pretty much the Subsurface logo only.

It also removes the grid lines, while the poster is visible.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-10 09:02:25 -07:00
Lubomir I. Ivanov
7d9849cfed Profile2: use an implicit initializer for a struct array
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-10 09:02:01 -07:00
Lubomir I. Ivanov
0325b267ee Profile2: fix some initializer list order warnings
Such can be disabled with -Wno-reorder and are clearly
more of a nuisance, but C++98 12.6.2.5 says the order should be
the same as in the class declaration.

On theory this would only speed the compile times a tiny amount.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-10 09:01:58 -07:00
Dirk Hohndel
b1d1c88822 Fix uninitialized variable
s could be used without being set.

Also convert the file to utf-8 - for some reason it was created as
iso8859.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-09 21:25:20 -07:00
Dirk Hohndel
7f32f930ef Increase static buffer size
While 100 was almost certainly long enough for all the non-string data
that we'd find on a single line, it was a little too close for comfort.
So let's go total overkill and not worry about it.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-09 21:06:18 -07:00
Linus Torvalds
1fc783aed5 Read salinity from git objects
Simple oversight on the reading side.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-09 21:04:05 -07:00
Linus Torvalds
4312b155e1 parse divecomputer model nickname/firmware/serial information
This was the final piece we didn't read.  I can now read my XML file,
write it to a git repository, read it back, and write it to a new XML
file, and the final XML file is bit-for-bit identical with the original
one.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-09 19:36:40 -07:00
Linus Torvalds
6f3be56d8d Add event parsing to the git object tree loader
This makes us parse everything we save, and I can load my XML file, save
it as a git file, load that git file, save it as a new XML file, and the
end result is identical.

Well...  *ALMOST* identical.  We currently don't save the dive computer
nickname and serial/firmware information in the git repository, so that
does get lost in translation.  But all the actual dive data is there.

NOTE! I have currently only worked with my own dive files.  They are
reasonably complex and complete, and do have a lot of the interesting
cases covered (like multiple dive computers etc), but there's no CCR
information, and all the dives are in trips, so this does need more
testing. It's at the very least very close.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-09 19:36:39 -07:00
Linus Torvalds
6ef38967ff parse cylinder and weightsystem information
This makes the sample parsing helper function for key-value pair parsing
more generic, and uses it for parsing cylinders and weightsystems too.

Events still to go, and then we have the "setting" section (for dive
computer nicknames and firmware information) that we don't actually save
yet in the git format.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-09 19:36:38 -07:00
Linus Torvalds
820cbe96da Parse key/value pairs in dive computer samples too
This gets us the stopdepth, cns, bearing etc information.  We're getting
really close to parsing everything, but are still missing event parsing,
and cylinder/weight data.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-09 19:36:38 -07:00
Linus Torvalds
7991e36c56 Parse basic dive computer sample data
This doesn't yet parse the (less common) "key=value" type sample data,
so it's not complete, but the framework for that is in place too.

With this, we now parse all the basics, and the most noticeable missing
part is the cylinder and weigthsystem data.  Lack of cylinder data in
particular means that SAC-rates etc don't get calculated, but other than
that it looks almost complete - you don't miss the missing event and
sample details unless you look for them.

I'll get the missing pieces done too, but this basic sample parsing was
visually a big step.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-09 19:36:35 -07:00
Linus Torvalds
5fcb36f5a8 Parse basic trip and dive data from the git blobs
Some things are still missing: samples and events, and cylinder and
weightsystem information.  But most of the basics are there (although
the lack of sample data makes a big visual impact)

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-09 19:36:35 -07:00
Linus Torvalds
719656b438 Start actually parsing the git object data
This implements the simple line parser (including the multiline strings
with escape characters).  What a difference a good file format makes:
this is nothing like the pain that is XML.

That said, it only does the line/string parsing right now, it doesn't
actually then look at what the lines say.  So no human-noticeable
improvements in the actual data shown by subsurface.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-09 19:36:34 -07:00
Linus Torvalds
34fb8240da git repository reading: start reading the actual file contents
If we want to scale to thousands of dives, we'll eventually want to read
the dive computer files lazily when actually needed, but for now we do
everything synchronously.  Even if that may actually be slower than
parsing one big XML file.

The git object store is pretty efficient, but especially with some
history, the compression and delta application will certainly not be
free.

This does all the git object unpacking, but none of the actual data
parsing yet.  But as part of looking up the file objects, we do get the
dive number (which is in the name of the dive file).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-09 19:36:33 -07:00
Linus Torvalds
f0985644b6 git dive loading: actually insert the dives into the dive table
The biggest part of this commit is the comment about the woeful state of
the "git_tree_walk()" interface - the interface is not really very good
for seeing any recursive state, since it just walks the tree pretty much
linearly.

But the only real recursive state we care about is the trip, and in all
normal situations the "trip this dive is in" is the same thing as "what
was the last trip directory we traversed", so a linear walk works fine.

The one exception is if a dive isn't in a trip at all, in which case
"last trip directory" obviously isn't what we want.

But rather than do our own tree walking by hand (and just passing the
trip information in the natural recursive manner when traversing the
tree), we hack around it by just looking at the path to the dive.

That one-liner trivial hack has now generated about 20 lines of
explanation of it.

ANYWAY.  With this, we parse the dive and trip hierarchy properly, and
instead of just printing out the data, we might as well insert the dives
and trips into the subsurface data structures.

Note: the only data we have about the dive and trip right now is what is
visible in the directory structure, since we don't look at the actual
dive file at all (not even the name of it, which contains the dive
number).  So the end result will be just a sea of empty dives and the
trips they are contained in.  The dives have a date and time, and the
trip has a date, though.

So this is *not* useful for actually saving and loading data, but the
data we do load is easily visualized inside subsurface, so as I'm
starting to add real dive data parsing code, it will all be much more
visually satisfying.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-09 19:36:32 -07:00
Linus Torvalds
5ec0dbbce8 git save format: add dive computer nicknames and firmware details
This adds a top-level "00-Subsurface" file that sorts first in the git
tree, and contains version information, dive computer nicknames and
settings.  Although right now the settings are just the autogroup thing.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-09 19:36:31 -07:00
Linus Torvalds
1e8c828396 Fix event saving in git format due to wrong argument order
Oops.  Really stupid bug in event saving, resulting in bad event lines,
that I didn't notice until I started trying to parse them.

The argument order is a bit mixed up, which is partly why this happened.
But considering that this is the worst bug I've hit so far in the saving
code, I guess I shouldn't complain too much.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-09 19:36:30 -07:00
Linus Torvalds
2584b7e831 Enumerate dive computers when saving them in the git repository
We want to make sure that we load them in the same order we save them,
and while using the hash made the divecomputer names unique, it didn't
sort them.  You couldn't tell with just one or two dive computers, but
if you have three or more dive computers on a dive, the order of any but
the first ended up depending on the ordering of the unique hash
extensions.

So just append a numeric index instead of relying on the hash to make
the names unique.  But skip the index if there is just one dive
computer.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-09 19:36:29 -07:00
Tomaz Canabrava
a052c63b00 Fix retrieving the initial position of the Notification Area.
We had all in place, all that was missing was to actually load
the position stored on the settings for the tooltips.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-09 08:50:54 -07:00
Tomaz Canabrava
24c5b2e3c1 Code Cleanup ( that fix 2 bugs )
This code cleanup fixes the two issues that I raised on
my last e-mail. hurrah.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-09 08:50:54 -07:00
Dirk Hohndel
b6bbfdcc5f Avoid calling free on uninitialized dive variable
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-08 17:27:33 -08:00
Dirk Hohndel
eef3d63de6 Uemis GPS location tracking seems backwards
I can't figure out how this ever worked...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-08 16:55:25 -08:00
Dirk Hohndel
0b7c11a597 Another case of 'dereference before NULL check'
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-08 16:49:34 -08:00
Dirk Hohndel
9ee0bfe633 Don't use dive before checking it against NULL
Dive gets dereferenced in get_surface_pressure_in_mbar().

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-08 16:47:06 -08:00
Linus Torvalds
989c8f0110 Fix totally broken put_vformat() implementation
I'm ashamed.  put_vbuffer() worked perfectly fine for the normal case
when everything fit in our simple buffer on-stack, but the fallback case
was broken in so many ways that I'm just going to go sit in a corner and
cry myself to sleep.

And dammit, I _knew_ how to do it right.  I knew you had to do a
"va_copy()" and couldn't just keep re-using 'args'.  I've done this
before.  But I half-arsed it, and nobody ever noticed, because you
wouldn't do C style format strings for big strings.

"128 bytes is enough for everybody".

And as penance for this idiocy, I just spent too much time trying to
figure out what was wrong in my git loading code when my debug printouts
caused SIGSEGV's.

Sigh.

Anyway, now it should hopefully be correct, and the code is smarter
about things too, not having that extra buffer since we already *have* a
buffer in the "struct membuffer" we are working with.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-08 16:32:31 -08:00
Linus Torvalds
cc3a184adf Add initial parser for git trees
It doesn't actually parse the files themselves, but it does walk the
object tree and print out the dives and trips it finds.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-08 07:46:50 -08:00
Linus Torvalds
6d0011947b Use symbolic names for the git file types
Instead of hardcoding the regular file mode (0100644 is the traditional
Unix S_IFREG file mode with -rw-r--r-- protections), use
GIT_FILEMODE_BLOB (and GIT_FILEMODE_TREE for 040000 - S_IFDIR).

The numbers were historically indeed the regular S_IFREG/S_IFDIR values,
but since those aren't portable, git ended up defining their own.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-08 07:46:20 -08:00
Tomaz Canabrava
5bba84e57f Fix colors on the new profile.
This patch fixes the colors on the new profile, the init of the colors map
was not being done. This fixes it.

A few problems were spotted on the new profile dealing with the ruler
graph and a newly added dive, when using the dive add dialog.

I'll be on it later.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-07 20:37:17 -08:00
Dirk Hohndel
04382a1943 Remove unused parameter to tree_insert()
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-07 20:36:22 -08:00
Dirk Hohndel
37c1e8147a Don't have the put_something() functions return success
We didn't use the return value anywhere.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-07 20:33:22 -08:00
Linus Torvalds
de6e7d894e Flesh out git save format
This fixes up the writing of the git format to the point that it might
be getting close to complete. In particular:

 - Add subsurface version information into commit message as requested by Dirk

 - Fix missed string quoting ('\' needs to be quoted as '\\')

 - rename "git_save_error()" as "report_error()", since we'll want to
   use this for the loading code too.

 - Improve on dive and trip name generation

 - create a date-based directory hierarchy

 - save dive computer data as individual files

 - actually save the trip information

There might be further changes as I start to actually *read* the git
files, of course.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-07 16:36:11 -08:00
Linus Torvalds
0b8deb2a15 Add C string helper to membuffer interface
I don't know why I didn't do this from the beginning.  We often build up
a membuffer and then want to use it as a C string.  You could do it by
hand by adding the zero byte at the end, but that's just annoying.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-07 16:36:11 -08:00
Dirk Hohndel
4edf37f9be Update cross building for Windows on Linux
This updates the instructions and the plumbing to be able to link against
a locally built libgit2

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-07 16:33:00 -08:00
Dirk Hohndel
18303b6f43 Fix compile problem
QPointer was undefined (oddly I didn't run into this when test building
earlier).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-07 10:03:03 -08:00
Giuseppe 'ferdy' Miceli
fcc2af6941 Add libgit2 dependency to INSTALL file (MacPorts stanza)
Signed-off-by: Giuseppe 'ferdy' Miceli <ferdy@ferdy.it>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-07 09:25:28 -08:00
Dirk Hohndel
3b1624ec69 Add a workaround for using post 0.20 git versions of libgit2
Add the following to your qmake command line and things should compile
again:

qmake ... CONFIG+=libgit21-api

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-07 09:23:42 -08:00
Tomaz Canabrava
00c97e710f Remove a Lot of Dead Code.
This is just removal of dead code from the old profile, probably there's
still a bit more to remove, but this is a very good cleanup already.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-07 08:56:06 -08:00
Tomaz Canabrava
8f43ad8100 Remove the code for the old Profile.
This is simply a code removal, nothing was touched besides the
profilegraphics.h/cpp files.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-07 08:55:22 -08:00
Tomaz Canabrava
ac9a23ef3b Remove the old profile from the main screen of Subsurface
This patch partially removes the code for the old profile from
Subsurface. It removes the use of the old profile on the mainwindow,
but keeping the code in the tree for now.

A bit of code-cleanup also entered this commit because I had to change
every instance of the code that used the old profile.

Now to the real code-cleanup

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-07 08:54:20 -08:00
Tomaz Canabrava
6dec4b0556 Fix a crash on changing dives when the ruler is used.
The ruler is a weird beast - it has two child objects that access the
parent to call another function, that call the child functions.

When I updated the plot_info I didn't take that into consideration, what
happened is that when I set the parent's plot_info, the children's
plot_info are still invalid, but the update method is called anyhow.

This patch updates all plot_info's before calling anything else.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-07 08:53:14 -08:00
Tomaz Canabrava
8034106219 Fix compilation with libgit2 0.20
Linus was wrong - the change to the API happened after 0.20 was released.
So libgit2 0.20 still needs the fix.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-07 08:51:20 -08:00
Dirk Hohndel
211ff0e63b Fix theoretical uninitialized read
We should never read cur_pr[cyl] if cyl isn't used during a dive - but for
cylinders that are used cur_pr[cyl] is initialized. But just to catch
errors elsewhere, let's not leave cur_pr[cyl] uninitialized.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-06 16:16:10 -08:00
Dirk Hohndel
8ab1fa3983 Fix memory leak when parsing a dive fails
We had all these repetitive calls to dc_parser_destroy but didn't free the
already allocated dive.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-06 15:36:46 -08:00
Dirk Hohndel
b51dd0a84b Prevent another file descriptor leak
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-06 15:08:27 -08:00
Linus Torvalds
689fe36030 Initial implementation of git save format
This saves the dive data into a git object repository instead of a
single XML file.

We create a git object tree with each dive as a separate file,
hierarchically by trip and date.

NOTE 1: This largely duplicates the XML saving code, because trying to
share it seemed just too painful: the logic is very similar, but the
details of the actual strings end up differing sufficiently that there
are tons of trivial differences.

The git save format is line-based with minimal quoting, while XML quotes
everything with either "<..\>" or using single quotes around attributes.

NOTE 2: You currently need a dummy "file" to save to, which points to
the real save location: the git repository and branch to be used.  We
should make this a config thing, but for testing, do something like
this:

	echo git /home/torvalds/scuba:linus > git-test

to create that git information file, and when you use "Save To" and
specify "git-test" as the file to save to, subsurface will use the new
git save logic to save to the branch "linus" in the repository found at
"/home/torvalds/scuba".

NOTE 3: The git save format uses just the git object directory, it does
*not* check out the result in any git working tree or index.  So after
you do a save, you can do

     git log -p linus

to see what actually happened in that branch, but it will not affect any
actual checked-out state in the repository.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-06 14:52:03 -08:00
Dirk Hohndel
c64227efe0 Fix real memory leak
We can't keep the cache around (even though it's tempting) as the next
iteration might change the start time of the planned dive or other
parameters which would make the cached data invalid.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-06 14:26:33 -08:00
Dirk Hohndel
3e8e005aa3 Deal with theoretical memory leaks
This is rather academic, but it will make Coverity happy.
If we start running out of memory we should make sure we don't leak any
more memory.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-06 14:19:42 -08:00