Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.20 KB | None | 0 0
  1. ;; in elisp land associative arrays are usually lists, not maps...
  2. (setq nb-git-commits-per-file-alist '(()))
  3.  
  4. ;; (nb-git-commits-for-file "/tmp/nosuchfile")              ;;  ->  -
  5. ;; (nb-git-commits-for-file "~/path/to/file/in/a/git/repo") ;;  ->  nb commits
  6. (defun nb-git-commits-for-file (file)
  7.   ;; Very fugly shell command but it should get the job done
  8.   (shell-command-to-string
  9.    (concat "cd $(dirname $(realpath " file "))"
  10.            " && git log --oneline $(realpath " file ") 2> /dev/null"
  11.            " | wc -l | tr -d '\n' | sed -e 's/^0$/-/'")))
  12.  
  13. (defun update-nb-git-commits-per-file-alist (file)
  14.   (add-to-list 'nb-git-commits-per-file-alist
  15.                (cons file (nb-git-commits-for-file file))))
  16.  
  17. ;; (find-cached-nb-git-commits-or-update-alist "/tmp/nosuchfile") ;;  ->  -
  18. (defun find-cached-nb-git-commits-or-update-alist (file)
  19.   (let* ((maybe-res (assoc file nb-git-commits-per-file-alist)))
  20.     (if maybe-res
  21.         (cdr maybe-res)
  22.       (progn
  23.         ;; we haven't cached the number of git commits for that file yet
  24.         (update-nb-git-commits-per-file-alist file)
  25.         ;; now the entry should be in the alist
  26.         (cdr (assoc file nb-git-commits-per-file-alist))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement