Hi,

here is one more patch to continue yesterday’s short series.

Best
Robert
From b4d637a8f01bc994eb8264a03f79ebf2da8359d3 Mon Sep 17 00:00:00 2001
From: "Robert C. Helling" <[email protected]>
Date: Tue, 24 Feb 2015 14:30:32 +0100
Subject: [PATCH] Add load and save git for image hashes and tame too
 aggressive parallelism

I don't use the git storage myself, but this should add the hashes there as 
well. PLEASE TEST!

Furthermore, only update the image display when image hashing is complete (not 
on a per directory basis
as that lead to problems with non-reentrant code).

Signed-off-by: Robert C. Helling <[email protected]>
---
 load-git.c           | 8 +++++++-
 qt-ui/mainwindow.cpp | 2 +-
 qthelper.cpp         | 7 ++++---
 qthelper.h           | 2 +-
 save-git.c           | 1 +
 5 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/load-git.c b/load-git.c
index 053a714..be25e8e 100644
--- a/load-git.c
+++ b/load-git.c
@@ -828,6 +828,12 @@ static void parse_picture_gps(char *line, struct membuffer 
*str, void *_pic)
        pic->longitude = parse_degrees(line, &line);
 }
 
+static void parse_picture_hash(char *line, struct membuffer *str, void *_pic)
+{
+       struct picture *pic = _pic;
+       pic->hash = get_utf8(str);
+}
+
 /* These need to be sorted! */
 struct keyword_action dc_action[] = {
 #undef D
@@ -900,7 +906,7 @@ static void settings_parser(char *line, struct membuffer 
*str, void *_unused)
 static struct keyword_action picture_action[] = {
 #undef D
 #define D(x) { #x, parse_picture_ ## x }
-       D(filename), D(gps)
+       D(filename), D(gps), D(hash)
 };
 
 static void picture_parser(char *line, struct membuffer *str, void *_pic)
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index f2d7869..520b457 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -332,7 +332,7 @@ void MainWindow::on_actionHash_images_triggered()
        if (dirnames.isEmpty())
                return;
        foreach (QString dir, dirnames) {
-               QtConcurrent::run(learnImages, QDir(dir), 10);
+               QtConcurrent::run(learnImages, QDir(dir), 10, 0);
        }
 
 }
diff --git a/qthelper.cpp b/qthelper.cpp
index 09d84d8..a1e01d4 100644
--- a/qthelper.cpp
+++ b/qthelper.cpp
@@ -460,7 +460,7 @@ void learnImage(const QByteArray filename)
        MainWindow::instance()->localFilenameOf[hashFile(filename.data())] = 
strdup(filename.data());
 }
 
-void learnImages(const QDir &dir, int maxdepth)
+void learnImages(const QDir &dir, int maxdepth, int depth)
 {
        QDir current(dir);
        QList<QByteArray> files;
@@ -468,7 +468,7 @@ void learnImages(const QDir &dir, int maxdepth)
 
        if (maxdepth) {
                foreach (QString dirname, dir.entryList(QStringList(), 
QDir::NoDotAndDotDot | QDir::Dirs)) {
-                       learnImages(QDir(dir.filePath(dirname)), maxdepth - 1);
+                       learnImages(QDir(dir.filePath(dirname)), maxdepth - 1, 
depth + 1);
                }
        }
 
@@ -481,5 +481,6 @@ void learnImages(const QDir &dir, int maxdepth)
        }
 
        QtConcurrent::blockingMap(files, learnImage);
-       DivePictureModel::instance()->updateDivePictures();
+       if (depth == 0)
+               DivePictureModel::instance()->updateDivePictures();
 }
diff --git a/qthelper.h b/qthelper.h
index 3826efa..b1ccb8a 100644
--- a/qthelper.h
+++ b/qthelper.h
@@ -21,5 +21,5 @@ void read_hashes();
 void write_hashes();
 void updateHash(struct picture *picture);
 QByteArray hashFile(const char *filename);
-void learnImages(const QDir &dir, int maxdepth);
+void learnImages(const QDir &dir, int maxdepth, int depth);
 #endif // QTHELPER_H
diff --git a/save-git.c b/save-git.c
index 0125f64..a7b5144 100644
--- a/save-git.c
+++ b/save-git.c
@@ -585,6 +585,7 @@ static int save_one_picture(git_repository *repo, struct 
dir *dir, struct pictur
 
        show_utf8(&buf, "filename ", pic->filename, "\n");
        show_gps(&buf, pic->latitude, pic->longitude);
+       show_utf8(&buf, "hash ", pic->hash, "\n");
 
        /* Picture loading will load even negative offsets.. */
        if (offset < 0) {
-- 
1.9.3 (Apple Git-50)



-- 
.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oOo.oO
Robert C. Helling     Elite Master Course Theoretical and Mathematical Physics
                      Scientific Coordinator
                      Ludwig Maximilians Universitaet Muenchen, Dept. Physik
                      Phone: +49 89 2180-4523  Theresienstr. 39, rm. B339
                      http://www.atdotde.de

Enhance your privacy, use cryptography! My PGP keys have fingerprints
A9D1 A01D 13A5 31FA 6515  BB44 0820 367C 36BC 0C1D    and
DCED 37B6 251C 7861 270D  5613 95C7 9D32 9A8D 9B8F





Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to