]> git.notmuchmail.org Git - notmuch/blobdiff - lib/database.cc
lib: Abstract the extraction of a relative path from set_filename
[notmuch] / lib / database.cc
index 23ddd4ae1314b2186b7839364b06cc0d25b5a575..261be01604cb5bffa34143ca9f1d6212d64725e1 100644 (file)
@@ -587,6 +587,40 @@ timestamp_db_key (const char *key)
        return strdup (key);
 }
 
+/* Given a legal 'path' for the database, return the relative path.
+ *
+ * The return value will be a pointer to the originl path contents,
+ * and will be either the original string (if 'path' was relative) or
+ * a portion of the string (if path was absolute and begins with the
+ * database path).
+ */
+const char *
+_notmuch_database_relative_path (notmuch_database_t *notmuch,
+                                const char *path)
+{
+    const char *db_path, *relative;
+    unsigned int db_path_len;
+
+    db_path = notmuch_database_get_path (notmuch);
+    db_path_len = strlen (db_path);
+
+    relative = path;
+
+    if (*relative == '/') {
+       while (*relative == '/' && *(relative+1) == '/')
+           relative++;
+
+       if (strncmp (relative, db_path, db_path_len) == 0)
+       {
+           relative += db_path_len;
+           while (*relative == '/')
+               relative++;
+       }
+    }
+
+    return relative;
+}
+
 notmuch_status_t
 notmuch_database_set_timestamp (notmuch_database_t *notmuch,
                                const char *key, time_t timestamp)
@@ -855,12 +889,11 @@ _notmuch_database_link_message_to_children (notmuch_database_t *notmuch,
  *
  * We first look at 'message_file' and its link-relevant headers
  * (References and In-Reply-To) for message IDs. We also look in the
- * database for existing message that reference 'message'.p
+ * database for existing message that reference 'message'.
  *
- * The end result is to call _notmuch_message_add_thread_id with one
- * or more thread IDs to which this message belongs, (including
- * generating a new thread ID if necessary if the message doesn't
- * connect to any existing threads).
+ * The end result is to call _notmuch_message_ensure_thread_id which
+ * generates a new thread ID if the message doesn't connect to any
+ * existing threads.
  */
 static notmuch_status_t
 _notmuch_database_link_message (notmuch_database_t *notmuch,