]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch-new.c
new: read db_files and db_subdirs only if mtime changed
[notmuch] / notmuch-new.c
index 1473d2e69449c80e596b0440bbd6269c31d8fd61..31d45532aa0494934ec545c77ff40130bc27b007 100644 (file)
@@ -117,15 +117,19 @@ generic_print_progress (const char *action, const char *object,
     printf ("%s %d ", action, processed);
 
     if (total) {
-       double time_remaining;
-
-       time_remaining = ((total - processed) / rate_overall);
-       printf ("of %d %s (", total, object);
-       notmuch_time_print_formatted_seconds (time_remaining);
-       printf (" remaining).\033[K\r");
+       printf ("of %d %s", total, object);
+       if (processed > 0 && elapsed_overall > 0.5) {
+           double time_remaining = ((total - processed) / rate_overall);
+           printf (" (");
+           notmuch_time_print_formatted_seconds (time_remaining);
+           printf (" remaining)");
+       }
     } else {
-       printf ("%s (%d %s/sec.)\033[K\r", object, (int) rate_overall, object);
+       printf ("%s", object);
+       if (elapsed_overall > 0.5)
+           printf (" (%d %s/sec.)", (int) rate_overall, object);
     }
+    printf (".\033[K\r");
 
     fflush (stdout);
 }
@@ -243,15 +247,7 @@ add_files_recursive (notmuch_database_t *notmuch,
     directory = notmuch_database_get_directory (notmuch, path);
     db_mtime = notmuch_directory_get_mtime (directory);
 
-    if (db_mtime == 0) {
-       new_directory = TRUE;
-       db_files = NULL;
-       db_subdirs = NULL;
-    } else {
-       new_directory = FALSE;
-       db_files = notmuch_directory_get_child_files (directory);
-       db_subdirs = notmuch_directory_get_child_directories (directory);
-    }
+    new_directory = db_mtime ? FALSE : TRUE;
 
     /* If the database knows about this directory, then we sort based
      * on strcmp to match the database sorting. Otherwise, we can do
@@ -324,6 +320,11 @@ add_files_recursive (notmuch_database_t *notmuch,
     if (fs_mtime == db_mtime)
        goto DONE;
 
+    if (!new_directory) {
+       db_files = notmuch_directory_get_child_files (directory);
+       db_subdirs = notmuch_directory_get_child_directories (directory);
+    }
+
     /* Pass 2: Scan for new files, removed files, and removed directories. */
     for (i = 0; i < num_fs_entries; i++)
     {