Advertisement
Guest User

Untitled

a guest
Mar 4th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.05 KB | None | 0 0
  1. (setq nb-git-commits-per-file-alist '(()))
  2.  
  3. ;; (nb-git-commits-for-file "/tmp/nosuchfile")              ;;  ->  -
  4. ;; (nb-git-commits-for-file "~/path/to/file/in/a/git/repo") ;;  ->  nb commits
  5. (defun nb-git-commits-for-file (file)
  6.   ;; Very fugly shell command but it should get the job done
  7.   (shell-command-to-string
  8.    (concat "cd $(dirname $(realpath " file "))"
  9.            " && git log --oneline $(realpath " file ") 2> /dev/null"
  10.            " | wc -l | tr -d '\n' | sed -e 's/^0$/-/'")))
  11.  
  12. ;; (update-nb-git-commits-per-file-alist "/home/e/prjs/hf/project.clj")
  13. (defun update-nb-git-commits-per-file-alist (file)
  14.   ;; we both update the alist and return the nb of commits for file
  15.   (cdr (car (add-to-list 'nb-git-commits-per-file-alist
  16.                      (cons file (nb-git-commits-for-file file))))))
  17.  
  18. ;; (find-cached-nb-git-commits-or-update-alist "/tmp/nosuchfile") ;;  ->  -
  19. (defun find-cached-nb-git-commits-or-update-alist (file)
  20.   (or (cdr (assoc file nb-git-commits-per-file-alist))
  21.       (update-nb-git-commits-per-file-alist file)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement