# The reverse of Rodrigo Silva's "git-restore-mtime" script.
# v1.52, Silas S. Brown 2019-23, public domain, no warranty
# v1.53, Silas S. Brown 2019-23, public domain, no warranty
# Might be useful for "git"ifying historical code, as at
# least the file's modification time should put an upper
...
...
@@ -42,6 +42,10 @@
unset Day
if["$1"="--day"];then Day=1;shift;fi
if["$2"="--day"];then Day=1;fi
if["$Day"= 1 ];then
if which python 2>/dev/null >/dev/null;then Python=python;elif which python3 2>/dev/null >/dev/null;then Python=python3;elif which python2.7 2>/dev/null >/dev/null;then Python=python2.7;else echo"Cannot find python command, required for --day";exit 1;fi
fi
if["$1"="--rewrite"];then# (must be run at top-level of the repo)
mv-i .git/config /tmp/old-git-config ||exit 1
...
...
@@ -65,12 +69,11 @@ else
exit 1
fi
if["$2"="--day"];then Day=1;fi
if["$1"="--restamp"];then git rm-r--cached.; git commit -am"temporary removal for timestamp correction";fi
find --*-type f -not-name'*~'-not-name .DS_Store -execpython -c'import os,sys;a=sys.argv[1];print(str(os.stat(a).st_mtime)+" "+a)''{}'';' 2>/dev/null|python -c$'import sys,time,os,pipes\ndef cond(a,b,c):\n if a: return b\n return c\ndf,dt={},{}\nfor d,t,f in sorted([(int(float(l.split()[0])/(24*3600)),float(l.split()[0]),l.split(None,1)[1].rstrip()) for l in sys.stdin]):\n if not d in df: df[d],dt[d]=set(),0\n df[d].add(f);dt[d]=max(dt[d],t)\nfor d in sorted(df.keys()):\n os.environ["GIT_COMMITTER_DATE"]=time.asctime(time.localtime(dt[d]))\n for x in sorted(df[d]): os.system("git add -v "+pipes.quote(x))\n r=os.system("git commit --date=\\"$GIT_COMMITTER_DATE\\" -am \\"add %s\\"" % (cond(len(df[d])>5,"%d files" % len(df[d]),", ".join(sorted(df[d]))),))\n if "ExtraCmd" in os.environ and not r and os.system(os.environ["ExtraCmd"]): raise Exception("git push failed or interrupted")'
find --*-type f -not-name'*~'-not-name .DS_Store -exec$Python-c'import os,sys;a=sys.argv[1];print(str(os.stat(a).st_mtime)+" "+a)''{}'';' 2>/dev/null|$Python-c$'import sys,time,os,pipes\ndef cond(a,b,c):\n if a: return b\n return c\ndf,dt={},{}\nfor d,t,f in sorted([(int(float(l.split()[0])/(24*3600)),float(l.split()[0]),l.split(None,1)[1].rstrip()) for l in sys.stdin]):\n if not d in df: df[d],dt[d]=set(),0\n df[d].add(f);dt[d]=max(dt[d],t)\nfor d in sorted(df.keys()):\n os.environ["GIT_COMMITTER_DATE"]=time.asctime(time.localtime(dt[d]))\n for x in sorted(df[d]): os.system("git add -v "+pipes.quote(x))\n r=os.system("git commit --date=\\"$GIT_COMMITTER_DATE\\" -am \\"add %s\\"" % (cond(len(df[d])>5,"%d files" % len(df[d]),", ".join(sorted(df[d]))),))\n if "ExtraCmd" in os.environ and not r and os.system(os.environ["ExtraCmd"]): raise Exception("git push failed or interrupted")'
# (if files already added, 'git commit' will fail and 'git push' won't happen; if one 'git push' fails, next one will be larger, so we check for fail so interrupt / resume is easier)