From 71194e54cd50a20d6d1dbe7e883e5a07ec6150e2 Mon Sep 17 00:00:00 2001 From: fpi Date: Mon, 27 Jul 2020 10:11:25 +0200 Subject: Add experimental way to reduce amount of tangling Works by saving the git commit hash upon tangling. Currently this does not record if tangling fails for some reason. --- .gitignore | 1 + Makefile | 5 ++++- README.org | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index f757d17..0aca97e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ tangle/* +hash/* *.patch \ No newline at end of file diff --git a/Makefile b/Makefile index f7412b5..d381bbf 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ dst_readme := tangle.sh merge.sh pull.sh link.sh dots.sh -.PHONY: merge install link tangle fetch pull +.PHONY: merge install link tangle fetch pull clean merge: tangle/merge.sh tangle/merge.sh @@ -10,6 +10,9 @@ install: tangle link tangle: tangle/tangle.sh tangle/tangle.sh +clean: + rm hash/* + link: tangle/link.sh tangle/link.sh diff --git a/README.org b/README.org index 0afa693..77f7917 100644 --- a/README.org +++ b/README.org @@ -1,3 +1,4 @@ +#+PROPERTY: header-args:shell :noweb yes * My dotfiles The config files are organized in [[https://www.gnu.org/software/emacs/][emacs]] [[https://orgmode.org/][org mode]] files. They are tangled and symlinked to the appropriate directories. @@ -60,6 +61,12 @@ configuration files and it also needs to be loaded & setup. For details see [[file:emacs-init.org::org-crypt-tangle-setup][emacs-init.org]]. #+begin_src shell :shebang "#!/bin/bash" :tangle tangle/tangle.sh +files=$(ls *.org *.org.gpg) + +<> + +echo "Tangling files:$tanglefiles ..." + emacs --batch --eval="\ (progn (require 'org) (require 'org-crypt) @@ -74,7 +81,58 @@ emacs --batch --eval="\ (org-encrypt-entries) (save-without-hook))) (let ((org-confirm-babel-evaluate nil)) - (mapc 'org-babel-tangle-file (split-string \"$(ls *.org *.org.gpg)\"))))" + (mapc 'org-babel-tangle-file (split-string \"$tanglefiles\"))))" +#+end_src + +*** Saving commit hashes to reduce tangling +To reduce the amount of unnecessary tangling, save the commit hash +upon tangling and check it before tangling again. + +Get the commit hash of a file using ~git log~. + +#+NAME: gethash +#+begin_src shell +function gethash { + git log -n 1 --pretty=format:%H -- $1 +} +#+end_src + +We can save all commit hashes by looping over all files. + +#+NAME: savehashes +#+begin_src shell +HASHDIR="hash" +<> +for file in $files +do + gethash $file > $HASHDIR/$file +done +#+end_src + +But we really want to check the saved hash against the current hash +first. If they do not match keep the file for tangling. + +#+NAME: checkhashes +#+begin_src shell +HASHDIR="hash" +tanglefiles="" +<> + +exec 3>&2 +exec 2> /dev/null # disable stderr + +for file in $files +do + if [ $(cat $HASHDIR/$file) == $(gethash $file) ] + then + : # noop + else # if strings not equal or ~cat~ fails + tanglefiles="$tanglefiles $file" + gethash $file > $HASHDIR/$file # save hash + fi +done + +exec 2>&3 #reset stderr #+end_src ** Creating symlinks -- cgit v1.2.3