[PATCH] convert: add config option to use the local time zone
Julian Cowley
julian at lava.net
Fri Nov 23 06:25:06 CST 2012
# HG changeset patch
# User Julian Cowley <julian at lava.net>
# Date 1353277610 36000
# Node ID 6cc1c8436aaf050255608210074b80ef4059b95f
# Parent fb14a5dcdc62987512820531fe60719d650491b6
convert: add config option to use the local time zone
The default for the time zone offset in a converted changeset has
always been 0 (UTC). With this patch, the converted changeset is
modified so that the local offset from UTC is specified as the time
zone offset.
The option is specified as the boolean convert.localtimezone (default
False). Example usage:
hg convert -s cvs --config convert.localtimezone=True example-cvs example-hg
IMPORTANT: the patch only applies to conversions from cvs or svn.
The documentation for the option only appears in those two sections
in the convert help text.
diff --git a/hgext/convert/__init__.py b/hgext/convert/__init__.py
--- a/hgext/convert/__init__.py
+++ b/hgext/convert/__init__.py
@@ -191,6 +191,10 @@
branch indicated in the regex as the second parent of the
changeset. Default is ``{{mergefrombranch ([-\\w]+)}}``
+ :convert.localtimezone: use local time (as determined by the TZ
+ environment variable) for changeset date/times. The default
+ is False (use UTC).
+
:hook.cvslog: Specify a Python function to be called at the end of
gathering the CVS log. The function is passed a list with the
log entries, and can modify the entries in-place, or add or
@@ -231,6 +235,10 @@
:convert.svn.trunk: specify the name of the trunk branch. The
default is ``trunk``.
+ :convert.localtimezone: use local time (as determined by the TZ
+ environment variable) for changeset date/times. The default
+ is False (use UTC).
+
Source history can be retrieved starting at a specific revision,
instead of being integrally converted. Only single branch
conversions are supported.
diff --git a/hgext/convert/common.py b/hgext/convert/common.py
--- a/hgext/convert/common.py
+++ b/hgext/convert/common.py
@@ -5,7 +5,7 @@
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
-import base64, errno, subprocess, os
+import base64, errno, subprocess, os, datetime
import cPickle as pickle
from mercurial import util
from mercurial.i18n import _
@@ -446,3 +446,10 @@
if e.errno != errno.ENOENT:
raise
return m
+
+def makedatetimestamp(t):
+ """Like util.makedate() but for time t instead of current time"""
+ delta = (datetime.datetime.utcfromtimestamp(t) -
+ datetime.datetime.fromtimestamp(t))
+ tz = delta.days * 86400 + delta.seconds
+ return t, tz
diff --git a/hgext/convert/cvs.py b/hgext/convert/cvs.py
--- a/hgext/convert/cvs.py
+++ b/hgext/convert/cvs.py
@@ -11,6 +11,7 @@
from mercurial.i18n import _
from common import NoRepo, commit, converter_source, checktool
+from common import makedatetimestamp
import cvsps
class convert_cvs(converter_source):
@@ -70,6 +71,8 @@
cs.author = self.recode(cs.author)
self.lastbranch[cs.branch] = id
cs.comment = self.recode(cs.comment)
+ if self.ui.configbool('convert', 'localtimezone'):
+ cs.date = makedatetimestamp(cs.date[0])
date = util.datestr(cs.date, '%Y-%m-%d %H:%M:%S %1%2')
self.tags.update(dict.fromkeys(cs.tags, id))
diff --git a/hgext/convert/subversion.py b/hgext/convert/subversion.py
--- a/hgext/convert/subversion.py
+++ b/hgext/convert/subversion.py
@@ -18,6 +18,7 @@
from common import NoRepo, MissingTool, commit, encodeargs, decodeargs
from common import commandline, converter_source, converter_sink, mapfile
+from common import makedatetimestamp
try:
from svn.core import SubversionException, Pool
@@ -802,6 +803,8 @@
# ISO-8601 conformant
# '2007-01-04T17:35:00.902377Z'
date = util.parsedate(date[:19] + " UTC", ["%Y-%m-%dT%H:%M:%S"])
+ if self.ui.configbool('convert', 'localtimezone'):
+ date = makedatetimestamp(date[0])
log = message and self.recode(message) or ''
author = author and self.recode(author) or ''
diff --git a/tests/test-convert-cvs.t b/tests/test-convert-cvs.t
--- a/tests/test-convert-cvs.t
+++ b/tests/test-convert-cvs.t
@@ -69,9 +69,16 @@
$TESTTMP/cvsrepo/src/b/c,v <-- *c (glob)
$ cd ..
-convert fresh repo
+convert fresh repo and also check localtimezone option
- $ hg convert src src-hg
+NOTE: This doesn't check all time zones -- it merely determines that
+the configuration option is taking effect.
+
+An arbitrary (U.S.) time zone is used here. TZ=US/Hawaii is selected
+since it does not use DST (unlike other U.S. time zones) and is always
+a fixed difference from UTC.
+
+ $ TZ=US/Hawaii hg convert --config convert.localtimezone=True src src-hg
initializing destination src-hg repository
connecting to $TESTTMP/cvsrepo
scanning source...
@@ -161,7 +168,7 @@
convert again
- $ hg convert src src-hg
+ $ TZ=US/Hawaii hg convert --config convert.localtimezone=True src src-hg
connecting to $TESTTMP/cvsrepo
scanning source...
collecting CVS rlog
@@ -221,7 +228,7 @@
convert again
- $ hg convert src src-hg
+ $ TZ=US/Hawaii hg convert --config convert.localtimezone=True src src-hg
connecting to $TESTTMP/cvsrepo
scanning source...
collecting CVS rlog
@@ -239,7 +246,7 @@
convert again with --filemap
- $ hg convert --filemap filemap src src-filemap
+ $ TZ=US/Hawaii hg convert --config convert.localtimezone=True --filemap filemap src src-filemap
connecting to $TESTTMP/cvsrepo
scanning source...
collecting CVS rlog
@@ -286,7 +293,7 @@
convert again
- $ hg convert --config convert.cvsps.fuzz=2 src src-hg
+ $ TZ=US/Hawaii hg convert --config convert.cvsps.fuzz=2 --config convert.localtimezone=True src src-hg
connecting to $TESTTMP/cvsrepo
scanning source...
collecting CVS rlog
@@ -300,25 +307,25 @@
2 funny
1 fuzzy
0 fuzzy
- $ hg -R src-hg glog --template '{rev} ({branches}) {desc} files: {files}\n'
- o 8 (branch) fuzzy files: b/c
+ $ hg -R src-hg glog --template '{rev} ({branches}) {desc} date: {date|date} files: {files}\n'
+ o 8 (branch) fuzzy date: * -1000 files: b/c (glob)
|
- o 7 (branch) fuzzy files: a
+ o 7 (branch) fuzzy date: * -1000 files: a (glob)
|
o 6 (branch) funny
| ----------------------------
- | log message files: a
- o 5 (branch) ci2 files: b/c
+ | log message date: * -1000 files: a (glob)
+ o 5 (branch) ci2 date: * -1000 files: b/c (glob)
- o 4 () ci1 files: a b/c
+ o 4 () ci1 date: * -1000 files: a b/c (glob)
|
- o 3 () update tags files: .hgtags
+ o 3 () update tags date: * +0000 files: .hgtags (glob)
|
- o 2 () ci0 files: b/c
+ o 2 () ci0 date: * -1000 files: b/c (glob)
|
- | o 1 (INITIAL) import files:
+ | o 1 (INITIAL) import date: * -1000 files: (glob)
|/
- o 0 () Initial revision files: a b/c
+ o 0 () Initial revision date: * -1000 files: a b/c (glob)
testing debugcvsps
diff --git a/tests/test-convert-svn-source.t b/tests/test-convert-svn-source.t
--- a/tests/test-convert-svn-source.t
+++ b/tests/test-convert-svn-source.t
@@ -63,9 +63,16 @@
Committed revision 5.
$ cd ..
-Convert to hg once
+Convert to hg once and also test localtimezone option
- $ hg convert "$SVNREPOURL/proj%20B" B-hg
+NOTE: This doesn't check all time zones -- it merely determines that
+the configuration option is taking effect.
+
+An arbitrary (U.S.) time zone is used here. TZ=US/Hawaii is selected
+since it does not use DST (unlike other U.S. time zones) and is always
+a fixed difference from UTC.
+
+ $ TZ=US/Hawaii hg convert --config convert.localtimezone=True "$SVNREPOURL/proj%20B" B-hg
initializing destination B-hg repository
scanning source...
sorting...
@@ -109,7 +116,7 @@
Test incremental conversion
- $ hg convert "$SVNREPOURL/proj%20B" B-hg
+ $ TZ=US/Hawaii hg convert --config convert.localtimezone=True "$SVNREPOURL/proj%20B" B-hg
scanning source...
sorting...
converting...
@@ -118,22 +125,22 @@
updating tags
$ cd B-hg
- $ hg glog --template '{rev} {desc|firstline} files: {files}\n'
- o 7 update tags files: .hgtags
+ $ hg glog --template '{rev} {desc|firstline} date: {date|date} files: {files}\n'
+ o 7 update tags date: * +0000 files: .hgtags (glob)
|
- o 6 work in progress files: letter2.txt
+ o 6 work in progress date: * -1000 files: letter2.txt (glob)
|
- o 5 second letter files: letter .txt letter2.txt
+ o 5 second letter date: * -1000 files: letter .txt letter2.txt (glob)
|
- o 4 update tags files: .hgtags
+ o 4 update tags date: * +0000 files: .hgtags (glob)
|
- o 3 nice day files: letter .txt
+ o 3 nice day date: * -1000 files: letter .txt (glob)
|
- o 2 world files: letter .txt
+ o 2 world date: * -1000 files: letter .txt (glob)
|
- o 1 hello files: letter .txt
+ o 1 hello date: * -1000 files: letter .txt (glob)
|
- o 0 init projB files:
+ o 0 init projB date: * -1000 files: (glob)
$ hg tags -q
tip
diff --git a/tests/test-convert.t b/tests/test-convert.t
--- a/tests/test-convert.t
+++ b/tests/test-convert.t
@@ -172,6 +172,10 @@
will add the most recent revision on the branch indicated in
the regex as the second parent of the changeset. Default is
"{{mergefrombranch ([-\w]+)}}"
+ convert.localtimezone
+ use local time (as determined by the TZ environment
+ variable) for changeset date/times. The default is False
+ (use UTC).
hook.cvslog Specify a Python function to be called at the end of
gathering the CVS log. The function is passed a list with
the log entries, and can modify the entries in-place, or add
@@ -211,6 +215,10 @@
convert.svn.trunk
specify the name of the trunk branch. The default is
"trunk".
+ convert.localtimezone
+ use local time (as determined by the TZ environment
+ variable) for changeset date/times. The default is False
+ (use UTC).
Source history can be retrieved starting at a specific revision, instead
of being integrally converted. Only single branch conversions are
More information about the Mercurial-devel
mailing list