aboutsummaryrefslogtreecommitdiff
path: root/set_mtimes
diff options
context:
space:
mode:
authorThomas Schwinge <thomas@schwinge.name>2010-12-13 17:11:51 +0100
committerThomas Schwinge <thomas@schwinge.name>2010-12-13 17:11:51 +0100
commit2d75167da62e3486836e5f1773e5f1ab06e43fe8 (patch)
treee44fc83e0b1419836d1b21652ad1d38b8d0af2c4 /set_mtimes
parent217998d56f5b6424a685f8c87f2c0e924d1c89da (diff)
parent5c5c16e265d8ef56b71f319885f32bf144bdea23 (diff)
downloadweb-2d75167da62e3486836e5f1773e5f1ab06e43fe8.tar.gz
web-2d75167da62e3486836e5f1773e5f1ab06e43fe8.tar.bz2
web-2d75167da62e3486836e5f1773e5f1ab06e43fe8.zip
Merge branch 'master' into external_pager_mechanism
Conflicts: microkernel/mach/external_pager_mechanism.mdwn
Diffstat (limited to 'set_mtimes')
-rwxr-xr-xset_mtimes56
1 files changed, 56 insertions, 0 deletions
diff --git a/set_mtimes b/set_mtimes
new file mode 100755
index 00000000..7157e7f5
--- /dev/null
+++ b/set_mtimes
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+# Set the checked-out files' mtimes according to their last Git revision.
+
+# Written by Thomas Schwinge <tschwinge@gnu.org>
+
+trap '
+ if [ x"$tmp_dir" = x ]; then :; else
+ rm -rf -- "$tmp_dir"
+ fi
+' EXIT &&
+
+# TODO: handle arguments meaning to only process a subset (directories / files)
+# of the repository.
+if [ x"$#" = x0 ]; then :; else
+ echo >&2 No command line arguments expected.
+ exit 1
+fi &&
+
+tmp_dir=$(mktemp -d) &&
+
+tmp_ignore=$tmp_dir/ignore &&
+# TODO: have to add more flags?
+git ls-files \
+ > "$tmp_ignore" \
+ -d -m &&
+while read file; do
+ echo >&2 "*** WARNING: file <$file> locally changed or deleted, not touching"
+done < "$tmp_ignore" &&
+
+tmp_known=$tmp_dir/known &&
+git ls-files \
+ > "$tmp_known" \
+ -c &&
+
+tmp_consider=$tmp_dir/consider &&
+grep \
+ < "$tmp_known" \
+ > "$tmp_consider" \
+ -f "$tmp_ignore" -x -v &&
+
+while read file; do
+ # TODO: use %ci? TODO: can we optimize this to not have to invoke git log
+ # individually for every single file?
+ date_git=$(git log -1 --pretty=format:%ai -- "$file") &&
+ date_git=$(date --rfc-3339=ns -d "$date_git") &&
+ date_file=$(date --rfc-3339=ns -r "$file") &&
+ if [ x"$date_git" = x"$date_file" ]; then :; else
+ echo >&2 "*** INFO: file $file: mtime <$date_file> -> <$date_git>"
+ touch -m -d "$date_git" "$file"
+ fi \
+ || {
+ echo >&2 "*** ERROR: file <$file>, date_git <$date_git>, date_file <$date_file>"
+ exit 1
+ }
+done < "$tmp_consider"