Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; in elisp land associative arrays are usually lists, not maps...
- (setq nb-git-commits-per-file-alist '(()))
- ;; (nb-git-commits-for-file "/tmp/nosuchfile") ;; -> -
- ;; (nb-git-commits-for-file "~/path/to/file/in/a/git/repo") ;; -> nb commits
- (defun nb-git-commits-for-file (file)
- ;; Very fugly shell command but it should get the job done
- (shell-command-to-string
- (concat "cd $(dirname $(realpath " file "))"
- " && git log --oneline $(realpath " file ") 2> /dev/null"
- " | wc -l | tr -d '\n' | sed -e 's/^0$/-/'")))
- (defun update-nb-git-commits-per-file-alist (file)
- (add-to-list 'nb-git-commits-per-file-alist
- (cons file (nb-git-commits-for-file file))))
- ;; (find-cached-nb-git-commits-or-update-alist "/tmp/nosuchfile") ;; -> -
- (defun find-cached-nb-git-commits-or-update-alist (file)
- (let* ((maybe-res (assoc file nb-git-commits-per-file-alist)))
- (if maybe-res
- (cdr maybe-res)
- (progn
- ;; we haven't cached the number of git commits for that file yet
- (update-nb-git-commits-per-file-alist file)
- ;; now the entry should be in the alist
- (cdr (assoc file nb-git-commits-per-file-alist))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement