mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
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>
This commit is contained in:
parent
a052c63b00
commit
2584b7e831
1 changed files with 9 additions and 4 deletions
13
save-git.c
13
save-git.c
|
@ -469,13 +469,13 @@ static int blob_insert(git_repository *repo, struct dir *tree, struct membuffer
|
||||||
return ret;
|
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;
|
int ret;
|
||||||
struct membuffer buf = { 0 };
|
struct membuffer buf = { 0 };
|
||||||
|
|
||||||
save_dc(&buf, dive, dc);
|
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)
|
if (ret)
|
||||||
report_error("divecomputer tree insert failed");
|
report_error("divecomputer tree insert failed");
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -501,10 +501,15 @@ static int save_one_dive(git_repository *repo, struct dir *tree, struct dive *di
|
||||||
if (ret)
|
if (ret)
|
||||||
return report_error("dive save-file tree insert failed");
|
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;
|
dc = &dive->dc;
|
||||||
|
nr = dc->next ? 1 : 0;
|
||||||
do {
|
do {
|
||||||
save_one_divecomputer(repo, subdir, dive, dc);
|
save_one_divecomputer(repo, subdir, dive, dc, nr++);
|
||||||
dc = dc->next;
|
dc = dc->next;
|
||||||
} while (dc);
|
} while (dc);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue