[gnome-builder/wip/tree-menu: 38/44] autotools: check .git/index for more accurate datetime info



commit 30e18c6c60d23a531944f8475f56461b9772c024
Author: Christian Hergert <christian hergert me>
Date:   Thu Apr 2 21:08:46 2015 -0700

    autotools: check .git/index for more accurate datetime info
    
    This is very much a leaking of abstractions, but I don't have a clear idea
    of what he abstraction would look like to merge the various systems. So
    this trick will do for now.

 libide/autotools/ide-autotools-project-miner.c |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)
---
diff --git a/libide/autotools/ide-autotools-project-miner.c b/libide/autotools/ide-autotools-project-miner.c
index 046e38a..8200927 100644
--- a/libide/autotools/ide-autotools-project-miner.c
+++ b/libide/autotools/ide-autotools-project-miner.c
@@ -43,12 +43,15 @@ static GParamSpec *gParamSpecs [LAST_PROP];
 
 static void
 ide_autotools_project_miner_discovered (IdeAutotoolsProjectMiner *self,
+                                        GCancellable             *cancellable,
                                         GFile                    *directory,
                                         GFileInfo                *file_info)
 {
   g_autofree gchar *uri = NULL;
   g_autofree gchar *name = NULL;
   g_autoptr(GFile) file = NULL;
+  g_autoptr(GFile) index_file = NULL;
+  g_autoptr(GFileInfo) index_info = NULL;
   g_autoptr(IdeProjectInfo) project_info = NULL;
   g_autoptr(GDateTime) last_modified_at = NULL;
   const gchar *filename;
@@ -65,6 +68,20 @@ ide_autotools_project_miner_discovered (IdeAutotoolsProjectMiner *self,
 
   /* TODO: better time tracking */
   mtime = g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
+
+  /*
+   * If there is a git repo, trust the .git/index file for time info,
+   * it is more reliable than our directory mtime.
+   */
+  index_file = g_file_get_child (directory, ".git/index");
+  index_info = g_file_query_info (index_file,
+                                  G_FILE_ATTRIBUTE_TIME_MODIFIED,
+                                  G_FILE_QUERY_INFO_NONE,
+                                  cancellable,
+                                  NULL);
+  if (index_info != NULL)
+    mtime = g_file_info_get_attribute_uint64 (index_info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
+
   last_modified_at = g_date_time_new_from_unix_local (mtime);
 
   filename = g_file_info_get_attribute_byte_string (file_info, G_FILE_ATTRIBUTE_STANDARD_NAME);
@@ -144,7 +161,7 @@ ide_autotools_project_miner_mine_directory (IdeAutotoolsProjectMiner *self,
           if ((0 == g_strcmp0 (filename, "configure.ac")) ||
               (0 == g_strcmp0 (filename, "configure.in")))
             {
-              ide_autotools_project_miner_discovered (self, directory, file_info);
+              ide_autotools_project_miner_discovered (self, cancellable, directory, file_info);
               g_clear_object (&file_info);
               return;
             }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]