[PATCH] git save format: don't save redundant sample information

Linus Torvalds torvalds at linux-foundation.org
Thu Jul 20 21:10:57 PDT 2017


From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Thu, 20 Jul 2017 20:56:58 -0700
Subject: [PATCH] git save format: don't save redundant sample information

When we load sample data from a git save-file, we always default to
using the state from the previous sample (except for the special case of
cylinder pressure where an empty value does not mean "same", but
"interpolate", see core/load-git.c: new_sample()).

But the corollary to that is that it's always redundant to save sample
data that hasn't changed since the previous sample.

For some reason, the rbt, bearing and heartrate sample data didn't
follow that rule, and instead saved with lots of extra reduncancy.

(The alternative would be to clear those samples at load time, and make
them act like the pressure data, but it would appear that all these
three values may as well just have the normal "if no change, don't save
them" semantics).

Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---

I noticed this when I was checking that we don't screw up the pressure 
sensor data on save time (well, at least not the simple cases). 

Our compass bearing saving in particular is a bit confused, since "0" is a 
valid bearing (and "show_index()" skips zero data), but it is what it is. 
This is at least better than what we used to do, namely save the same 
bearing over and over and over again (and skip a zero bearing).

I didn't check the xml case, maybe I'll get around to it later. I would 
expect similar issues there.

 core/save-git.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/core/save-git.c b/core/save-git.c
index 9979aaf0..2647b88a 100644
--- a/core/save-git.c
+++ b/core/save-git.c
@@ -286,8 +286,10 @@ static void save_sample(struct membuffer *b, struct sample *sample, struct sampl
 		old->cns = sample->cns;
 	}
 
-	if (sample->rbt.seconds)
+	if (sample->rbt.seconds != old->rbt.seconds) {
 		put_format(b, " rbt=%u:%02u", FRACTION(sample->rbt.seconds, 60));
+		old->rbt.seconds = sample->rbt.seconds;
+	}
 
 	if (sample->o2sensor[0].mbar != old->o2sensor[0].mbar) {
 		put_milli(b, " sensor1=", sample->o2sensor[0].mbar, "bar");
@@ -308,8 +310,14 @@ static void save_sample(struct membuffer *b, struct sample *sample, struct sampl
 		put_milli(b, " po2=", sample->setpoint.mbar, "bar");
 		old->setpoint = sample->setpoint;
 	}
-	show_index(b, sample->heartbeat, "heartbeat=", "");
-	show_index(b, sample->bearing.degrees, "bearing=", "°");
+	if (sample->heartbeat != old->heartbeat) {
+		show_index(b, sample->heartbeat, "heartbeat=", "");
+		old->heartbeat = sample->heartbeat;
+	}
+	if (sample->bearing.degrees != old->bearing.degrees) {
+		show_index(b, sample->bearing.degrees, "bearing=", "°");
+		old->bearing.degrees = sample->bearing.degrees;
+	}
 	put_format(b, "\n");
 }
 
-- 
2.13.1.518.g0d864c4df



More information about the subsurface mailing list