summaryrefslogtreecommitdiffstats
path: root/save-git.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2014-03-09 13:33:28 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-03-09 19:36:29 -0700
commit2584b7e83132e5f63d94fff8fb7ffbc49259a83f (patch)
treefeca1f374e3b434ceb71ee085757c3eded2f2941 /save-git.c
parenta052c63b003d1f82bc5785617db4e3e285f82e00 (diff)
downloadsubsurface-2584b7e83132e5f63d94fff8fb7ffbc49259a83f.tar.gz
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>
Diffstat (limited to 'save-git.c')
-rw-r--r--save-git.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/save-git.c b/save-git.c
index 0f9dea95e..7b121a19b 100644
--- a/save-git.c
+++ b/save-git.c
@@ -469,13 +469,13 @@ static int blob_insert(git_repository *repo, struct dir *tree, struct membuffer
return ret;
}
-static int save_one_divecomputer(git_repository *repo, struct dir *tree, struct dive *dive, struct divecomputer *dc)
+static int save_one_divecomputer(git_repository *repo, struct dir *tree, struct dive *dive, struct divecomputer *dc, int idx)
{
int ret;
struct membuffer buf = { 0 };
save_dc(&buf, dive, dc);
- ret = blob_insert(repo, tree, &buf, "Divecomputer");
+ ret = blob_insert(repo, tree, &buf, "Divecomputer%c%03u", idx ? '-' : 0, idx);
if (ret)
report_error("divecomputer tree insert failed");
return ret;
@@ -501,10 +501,15 @@ static int save_one_dive(git_repository *repo, struct dir *tree, struct dive *di
if (ret)
return report_error("dive save-file tree insert failed");
- /* Save the dive computer data */
+ /*
+ * Save the dive computer data. If there is only one dive
+ * computer, use index 0 for that (which disables the index
+ * generation when naming it).
+ */
dc = &dive->dc;
+ nr = dc->next ? 1 : 0;
do {
- save_one_divecomputer(repo, subdir, dive, dc);
+ save_one_divecomputer(repo, subdir, dive, dc, nr++);
dc = dc->next;
} while (dc);