Skip to content

Instantly share code, notes, and snippets.

@MrSwed
Forked from Cojad/git-cache-meta.sh
Last active February 7, 2020 23:08
Show Gist options
  • Save MrSwed/2860da5affc94adf8db1 to your computer and use it in GitHub Desktop.
Save MrSwed/2860da5affc94adf8db1 to your computer and use it in GitHub Desktop.
#!/bin/sh -e
#git-cache-meta -- simple file meta data caching and applying.
#Simpler than etckeeper, metastore, setgitperms, etc.
#from http://www.kerneltrap.org/mailarchive/git/2009/1/9/4654694
#modified by n1k
# - save all files metadata not only from other users
# - save numeric uid and gid
# 2012-03-05 - added filetime, andris9
# 2012-05-22 - added fix for non ASCII characters and list size, merge chgrp into chown command
: ${GIT_CACHE_META_FILE=.git_cache_meta}
if [ -n "$(find -prune -printf '%Tz %Az\n' | tr -d ' 0-9+-')" ]; then
echo "%z not supported in 'strftime' in C library." >&2
exit 1
fi
case $@ in
--store|--stdout)
case $1 in --store) exec > $GIT_CACHE_META_FILE; esac
git ls-files -z | xargs -0 -I NAME find NAME \
\( -printf 'chown -h %U ' -exec ls --quoting-style=shell '{}' \; \) , \
\( -printf 'chgrp -h %G ' -exec ls --quoting-style=shell '{}' \; \) , \
\( \! -type l -printf 'chmod %#m ' -exec ls --quoting-style=shell '{}' \; \) , \
\( -printf 'touch -c -h -m -d "%TY-%Tm-%Td %TH:%TM:%TS %Tz" ' -exec ls --quoting-style=shell '{}' \; \) , \
\( -printf 'touch -c -h -a -d "%AY-%Am-%Ad %AH:%AM:%AS %Az" ' -exec ls --quoting-style=shell '{}' \; \) ;;
--apply) sh -e $GIT_CACHE_META_FILE;;
*) 1>&2 echo "Usage: $0 --store|--stdout|--apply"; exit 1;;
esac
#!/bin/sh -e
#git-cache-time -- simple file timestamp caching and applying.
#Simple solution to store/restore timestamp from git repository
# - save only file modification timestamp
# 2014-02-25 change filetime from accessed time to modified time by cojad
# 2012-03-05 - added filetime, andris9
#modified by n1k
#from http://www.kerneltrap.org/mailarchive/git/2009/1/9/4654694
: ${GIT_CACHE_META_FILE=.git_cache_meta}
echo Start `date`
case $@ in
--store|-f|-s|--stdout|-c|-o)
case $1 in --store|-f|-s) exec > $GIT_CACHE_META_FILE; esac
git ls-files | while read l; do echo `date -r "$l" +'"%F %T"'` \"$l\" ; done ;;
--apply|-r|-a) while read l; do eval "touch -c -m -d $l"; done < $GIT_CACHE_META_FILE;;
*) 1>&2 echo "Usage:"
echo " $0 --store|--stdout|--apply";
echo " --store -f -s store timestamp in file";
echo " --stdout -c -o output to cosole";
echo " --apply -r -a restore timestamp"; exit 1;;
esac
exec >&0
echo end `date`

source:

git-cache-time              Works like git-cache-meta but only store file timestamp

git-cache-meta --store      Cache all meta include numeric uid/gid/permission in .git_cache_meta
git-cache-meta -f           Alias of --store

git-cache-meta --stdout     Same as --store but output in console
git-cache-meta -c           Alias of --stdout

destination:

git-cache-meta              Works like git-cache-meta but only store file timestamp
                            but restore "all" the meta in .git_cache_meta
                            
git-cache-meta --apply      Apply/Restore meta saved in .git_cache_meta
git-cache-meta -r           Alias of --apply
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment