emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/hyperbole 992870d 12/53: Speeded up search for and addi


From: Robert Weiner
Subject: [elpa] externals/hyperbole 992870d 12/53: Speeded up search for and addition of a single git project to the dir cache.
Date: Wed, 15 Nov 2017 22:47:00 -0500 (EST)

branch: externals/hyperbole
commit 992870d70b84355c6b059b0952cbc79ac5ce963f
Author: Bob Weiner <address@hidden>
Commit: Bob Weiner <address@hidden>

    Speeded up search for and addition of a single git project to the dir cache.
    * hib-social.el (hibtypes-git-add-project-to-repos-cache)
                    (hibtypes-git-build-or-add-to-repos-cache): Added to allow
        for adding a single new project to the cache.
---
 Changes       |  6 ++++--
 hib-social.el | 39 +++++++++++++++++++++++++++++++++++----
 2 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/Changes b/Changes
index f960dd4..ada158e 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 2017-09-22  Bob Weiner  <address@hidden>
 
+* hib-social.el (hibtypes-git-add-project-to-repos-cache)
+                (hibtypes-git-build-or-add-to-repos-cache): Added to allow
+    for adding a single new project to the cache.
+
 * hact.el (actype:act): Expand arguments as pathnames only in functions
     defined with defact (actions may be regular defuns as well).
 
@@ -24,8 +28,6 @@
 
 * hib-social.el: Added full Commentary with implicit link examples.
 
-----
-
 2017-09-20  Bob Weiner  <address@hidden>
 
 * DEMO (Git References): Added.
diff --git a/hib-social.el b/hib-social.el
index ee095bf..1255818 100644
--- a/hib-social.el
+++ b/hib-social.el
@@ -361,6 +361,36 @@ Return t if built, nil otherwise."
     (message "Please wait while all local git repositories are found...Done")
     t))
 
+(defun hibtypes-git-add-project-to-repos-cache (project)
+  "Locate PROJECT directory and add to the cache of local git repo directories 
in `hibtypes-git-repos-cache'.
+Return the project directory found or nil if none."
+  (message "Please wait while %s's local git repository is found..." project)
+  (let ((project-dir (shell-command-to-string
+                     (format "%s -l1 /%s/.git | sed -e 's+/.git++' | tr -d 
'\n'"
+                             (if (and (boundp 'locate-command) (string-match 
"locate" locate-command))
+                                 locate-command
+                               "locate")
+                             project
+                             hibtypes-git-repos-cache))))
+    (message "")
+    (when (and (> (length project-dir) 0) (= ?/ (aref project-dir 0)))
+      ;; project-dir a directory, prepend it to the cache file...
+      (shell-command-to-string (format "echo -e \"%s\n$(cat %s)\" > %s"
+                                      project-dir hibtypes-git-repos-cache
+                                      hibtypes-git-repos-cache))
+      ;; ...and return it.
+      project-dir)))
+
+(defun hibtypes-git-build-or-add-to-repos-cache (project &optional prompt-flag)
+  "Store cache of local git repo directories in `hibtypes-git-repos-cache'.
+With optional prompt-flag non-nil, prompt user whether to build the cache 
before building.
+Return t if built, nil otherwise."
+  (if (and (file-readable-p hibtypes-git-repos-cache)
+          ;; Non-zero file size
+          (not (zerop (nth 7 (file-attributes hibtypes-git-repos-cache)))))
+      (hibtypes-git-add-project-to-repos-cache project)
+    (hibtypes-git-build-repos-cache t)))
+
 (defun hibtypes-git-project-directory (project)
   "Given git PROJECT name, return local git repository directory or nil if 
none found."
   (if (or (and (file-readable-p hibtypes-git-repos-cache)
@@ -368,7 +398,7 @@ Return t if built, nil otherwise."
               (not (zerop (nth 7 (file-attributes hibtypes-git-repos-cache)))))
          (hibtypes-git-build-repos-cache t))
       ;; echo -n deletes trailing newline
-      (shell-command-to-string (format "echo -n `grep -m1 '/%s$' %s`" project 
hibtypes-git-repos-cache))
+      (shell-command-to-string (format "grep -m1 '/%s$' %s | tr -d '\n'" 
project hibtypes-git-repos-cache))
     (message "")
     nil))
 
@@ -456,9 +486,10 @@ PROJECT value is provided, it defaults to the value of
          (if (or (null project-dir) (equal project-dir ""))
              (if (and project
                       ;; Maybe the Hyperbole git project cache is
-                      ;; out-of-date and needs to be rebuilt.  Prompt
-                      ;; user and if rebuilt, continue.
-                      (hibtypes-git-build-repos-cache t))
+                      ;; out-of-date and needs to be rebuilt or added
+                      ;; to.  Prompt user and if rebuilt or added to,
+                      ;; continue.
+                      (hibtypes-git-build-or-add-to-repos-cache project t))
                  (setq project-dir (and project 
(hibtypes-git-project-directory project)))
                (error "(git-reference): No git directory found for project 
`%s'" project)))
          (if (equal project-dir "") (setq project-dir nil))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]