[PATCH] convert svn with local timezone in revision dates

Herbert Griebel herbertg at gmx.at
Sat Mar 21 13:54:53 CDT 2009


> Could you at least factor it out to a function in subversion.py?
Yes, no problem, but first I wait for some other responses about the patch.

> And: I suspect your patch is much more likely to be accepted if you
> add some test code.
Testing is not simple in that case because it would depend on
the timezone. Don't know if a shell script can do this (would
be glad if someone could provide this), if not, there would be
a new py script for test.

> Also: should this behavior be configurable?
I also thought about making it configurable so that one can
specify the timezone, but that would add a new option.

Currently I add all my modifications directly to the hg code
when converting, e.g.

  if author == 'max':
     timezone = -0700
  ...

So my idea was to add an option that allows a customization
py script. For example the user must specify
a py script which is called in a context with special
variables defined: author, message, date, ...

Then the user writes code like this:

  def customrev(author, date)
    date = localtimezone(date)
    if author == 'john':
      timezone = -0700
    if author == 'dave':
      author = 'David Miller <dave.miller at miller.com>'
    ...
    return author, date

The code is executed in its own context and protected (necessary to prevent exploits).
I would do it by importing the script in a dedicated module that also provides
the localtimezone function, simplified it will somehow look like this:

def localtimezone(date):
   return ...

def execuserscript(userscript, author, date)
    mod = __builtins__ ["__import__"] (userscript)
    mod.localtimezone = localtimezone
    author, date = mod.customrev(author, date)
    return author, date

I bet this could be done in multiple ways, but I used it as above
a couple of times and it works with no problems.
If you give examples for the code, everybody can write his own code,
even none programmers will have no troubles.
This would be a very powerful feature (not possible or very hard if you don't
have python btw) and very flexible.


Herbert


Greg Ward wrote:
> On Fri, Mar 20, 2009 at 6:40 PM, Herbert Griebel <herbertg at gmx.at> wrote:
>> # HG changeset patch
>> # User Herbert Griebel <herbertg at gmx.at>
>> # Date 1237588609 -3600
>> # Node ID 520f89b525f21583770ec3e16d47a850eedc33d2
>> # Parent  f711b8e0d2b335398074422037617ed10c258da3
>> convert svn with local timezone in revision dates
>>
>> SVN does not save timezone information and it must be added when
>> converting to HG. Most people will convert their own repos which
>> are created in their timezone, therefore using the local timezone
>> is much more likely to be the correct one, and is a better default
>> than timezone 0.
> 
> I have contemplated making a similar change to the CVS convertor.
> (CVS stores UTC timestamps, and hg naturally converts those to being
> explicitly in UTC.)  I think your little timezone munger would work
> for CVS conversion too.  Maybe it could go in util.py?  Could you at
> least factor it out to a function in subversion.py?  That'll make it
> easier for me to move when/if I try to do the same to CVS conversion.
> 
> Also: should this behaviour be configurable?
> 
> And: I suspect your patch is much more likely to be accepted if you
> add some test code.
> 
> Greg
> 


More information about the Mercurial-devel mailing list