Open glensc opened 8 years ago
here's sample FILTER_BRANCH_CALLBACK
that converts dates to certain timezone (requires pytz and dateutil packages):
Before: '2015-04-11 15:34:24 +0000'
After: '2015-04-11 18:34:24 +0300'
import pytz
from dateutil.parser import parse
DATE_TIME_FORMAT = "%Y-%m-%d %H:%M:%S %z"
TZ = pytz.timezone('Europe/Tallinn')
def convert_localtime(timestr):
localtime = parse(timestr).astimezone(TZ)
return localtime.strftime(DATE_TIME_FORMAT)
def my_filter_callback(path, entry, metadata, treedir):
# convert to local time
metadata['GIT_AUTHOR_DATE'] = convert_localtime(metadata['GIT_AUTHOR_DATE'])
metadata['GIT_COMMITTER_DATE'] = convert_localtime(metadata['GIT_COMMITTER_DATE'])
FILTER_BRANCH_CALLBACK = my_filter_callback
added the hook and example how to use it. looks good for merge!
@fragglet have got chance to give look at this?
@fragglet responded to current design decisions.
@fragglet https://github.com/fragglet/agito/pull/12#issuecomment-263023083 see my comments for reasons and say your final words. i don't need this otherwise, but would like to get it contributed back, someone might find it useful as i did.
simple implementation for #11
it currently just appends timezone info to
GIT_COMMITTER_DATE
,GIT_AUTHOR_DATE
metadata values, so the change is not compatible if somebody modifies metadata date fields viaFILTER_BRANCH_CALLBACK
. however the conversion will abort with parse error, so it's not harmful.if not using filter branch callback, no changes are visible, as
+0000
timezone is used.ideally to be compatible with
git filter-branch
should support all three Git date formats, but I haven't found good support in Python base libraries to do such parsing and Dulwich also doesn't have such methods.