source:
git-cache-meta --store
destination:
git-cache-meta --apply
| #!/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 | |
| #modified by the-mars | |
| # - 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 | |
| # 2014-03-18 - the-mars: store properties for dirs too | |
| # 2015-04-17 - time zone offset fallback; fix leading-dash-name error; avoid deeper find; | |
| # better quote file names; better directory listing; merge short opts; by Danny Lin | |
| : ${GIT_CACHE_META_FILE=.git_cache_meta} | |
| : ${Tz:=$(find -prune -printf '%Tz')} | |
| : ${Tz:=$(date +%z)} | |
| if ! [ "$Tz" ]; 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-tree --name-only -rdz $(git write-tree) | xargs -0 -I NAME find ./NAME -maxdepth 0 \ | |
| \( \! -type l -printf 'chmod %#m \0%p\n' \) , \ | |
| \( -printf 'touch -cmd "%TY-%Tm-%Td %TH:%TM:%TS '$Tz'" \0%p\n' \) , \ | |
| \( -printf 'touch -cad "%AY-%Am-%Ad %AH:%AM:%AS '$Tz'" \0%p\n' \) | |
| git ls-files -z | xargs -0 -I NAME find ./NAME -maxdepth 0 \ | |
| \( \! -type l -printf 'chmod %#m \0%p\n' \) , \ | |
| \( -printf 'touch -cmd "%TY-%Tm-%Td %TH:%TM:%TS '$Tz'" \0%p\n' \) , \ | |
| \( -printf 'touch -cad "%AY-%Am-%Ad %AH:%AM:%AS '$Tz'" \0%p\n' \) | |
| } | awk 'BEGIN {FS="\0"}; {print $1 "'\''" gensub(/'\''/, "'\''\\\\'\'''\''", "g", $2) "'\''" }' ;; | |
| --apply) sh -e $GIT_CACHE_META_FILE;; | |
| *) 1>&2 echo "Usage: $0 --store|--stdout|--apply"; exit 1;; | |
| esac |
| #!/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 | |
| #modified by the-mars | |
| # - 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 | |
| # 2014-03-18 - the-mars: store properties for dirs too | |
| # 2015-04-17 - time zone offset fallback; fix leading-dash-name error; avoid deeper find; | |
| # better quote file names; better directory listing; merge short opts; by Danny Lin | |
| : ${GIT_CACHE_META_FILE=.git_cache_meta} | |
| : ${Tz:=$(find -prune -printf '%Tz')} | |
| : ${Tz:=$(date +%z)} | |
| if ! [ "$Tz" ]; 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-tree --name-only -rdz $(git write-tree) | xargs -0 -I NAME find ./NAME -maxdepth 0 \ | |
| \( -printf 'chown -h %U:%G \0%p\n' \) , \ | |
| \( \! -type l -printf 'chmod %#m \0%p\n' \) , \ | |
| \( -printf 'touch -hcmd "%TY-%Tm-%Td %TH:%TM:%TS '$Tz'" \0%p\n' \) , \ | |
| \( -printf 'touch -hcad "%AY-%Am-%Ad %AH:%AM:%AS '$Tz'" \0%p\n' \) | |
| git ls-files -z | xargs -0 -I NAME find ./NAME -maxdepth 0 \ | |
| \( -printf 'chown -h %U:%G \0%p\n' \) , \ | |
| \( \! -type l -printf 'chmod %#m \0%p\n' \) , \ | |
| \( -printf 'touch -hcmd "%TY-%Tm-%Td %TH:%TM:%TS '$Tz'" \0%p\n' \) , \ | |
| \( -printf 'touch -hcad "%AY-%Am-%Ad %AH:%AM:%AS '$Tz'" \0%p\n' \) | |
| } | awk 'BEGIN {FS="\0"}; {print $1 "'\''" gensub(/'\''/, "'\''\\\\'\'''\''", "g", $2) "'\''" }' ;; | |
| --apply) sh -e $GIT_CACHE_META_FILE;; | |
| *) 1>&2 echo "Usage: $0 --store|--stdout|--apply"; exit 1;; | |
| esac |
source:
git-cache-meta --store
destination:
git-cache-meta --apply