Patchwork hgconvert: preserve revision timestamps from hg to svn

login
register
mail settings
Submitter Florent Angebault
Date July 12, 2013, 3:52 p.m.
Message ID <5834870243cb49bb1c31.1373644374@tanuki.etai.fr>
Download mbox | patch
Permalink /patch/1845/
State Changes Requested
Headers show

Comments

Florent Angebault - July 12, 2013, 3:52 p.m.
# HG changeset patch
# User Florent Angebault <florent.angebault@free.fr>
# Date 1373641599 -7200
#      Fri Jul 12 17:06:39 2013 +0200
# Node ID 5834870243cb49bb1c31554bced1fd5b09b4850c
# Parent  41c4bdd1d585a9196bd6c668fd9fce5e67a1028a
hgconvert: preserve revision timestamps from hg to svn
Christian Ebert - July 12, 2013, 6:36 p.m.
* Florent Angebault on Friday, July 12, 2013 at 17:52:54 +0200
> # HG changeset patch
> # User Florent Angebault <florent.angebault@free.fr>
> # Date 1373641599 -7200
> #      Fri Jul 12 17:06:39 2013 +0200
> # Node ID 5834870243cb49bb1c31554bced1fd5b09b4850c
> # Parent  41c4bdd1d585a9196bd6c668fd9fce5e67a1028a
> hgconvert: preserve revision timestamps from hg to svn
> 
> diff --git a/hgext/convert/subversion.py b/hgext/convert/subversion.py
> --- a/hgext/convert/subversion.py
> +++ b/hgext/convert/subversion.py
> @@ -2,7 +2,7 @@
> #
> # Copyright(C) 2007 Daniel Holth et al
> 
> -import os, re, sys, tempfile, urllib, urllib2, xml.dom.minidom
> +import os, re, sys, tempfile, urllib, urllib2, xml.dom.minidom, dateutil.parser

dateutil.parser is not a standard module, I don't think. Why not
use hg's util.parsedate()?

> import cPickle as pickle
> 
> from mercurial import strutil, scmutil, util, encoding
> @@ -992,6 +992,7 @@
> ACTION="$5"
> 
> if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:log" ]; then exit 0; fi
> +if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:date" ]; then exit 0; fi
> if [ "$ACTION" = "A" -a "$PROPNAME" = "hg:convert-branch" ]; then exit 0; fi
> if [ "$ACTION" = "A" -a "$PROPNAME" = "hg:convert-rev" ]; then exit 0; fi
> 
> @@ -1242,6 +1243,11 @@
>             if commit.branch and commit.branch != 'default':
>                 self.run('propset', 'hg:convert-branch', commit.branch,
>                          revprop=True, revision=rev)
> +            if commit.date:
> +                date = dateutil.parser.parse(commit.date)

I think this should be    date = util.parsedate(commit.date)[0]

> +                self.run('propset', 'svn:date',
> +                         date.strftime('%Y-%m-%dT%H:%M:%S.%fZ'),

probably:                   util.datestr((date, 0), '%Y-%m-%dT%H:%M:%S.%fZ)

Not 100% sure about omitting TZ and the float though.
Augie Fackler - July 16, 2013, 3:25 p.m.
On Fri, Jul 12, 2013 at 07:36:47PM +0100, Christian Ebert wrote:
> * Florent Angebault on Friday, July 12, 2013 at 17:52:54 +0200
> > # HG changeset patch
> > # User Florent Angebault <florent.angebault@free.fr>
> > # Date 1373641599 -7200
> > #      Fri Jul 12 17:06:39 2013 +0200
> > # Node ID 5834870243cb49bb1c31554bced1fd5b09b4850c
> > # Parent  41c4bdd1d585a9196bd6c668fd9fce5e67a1028a
> > hgconvert: preserve revision timestamps from hg to svn
> >
> > diff --git a/hgext/convert/subversion.py b/hgext/convert/subversion.py
> > --- a/hgext/convert/subversion.py
> > +++ b/hgext/convert/subversion.py
> > @@ -2,7 +2,7 @@
> > #
> > # Copyright(C) 2007 Daniel Holth et al
> >
> > -import os, re, sys, tempfile, urllib, urllib2, xml.dom.minidom
> > +import os, re, sys, tempfile, urllib, urllib2, xml.dom.minidom, dateutil.parser
>
> dateutil.parser is not a standard module, I don't think. Why not
> use hg's util.parsedate()?

Indeed. Seems to be some kind of ubuntu-ism, it exists on my
workstation, but not on my FreeBSD server.

>
> > import cPickle as pickle
> >
> > from mercurial import strutil, scmutil, util, encoding
> > @@ -992,6 +992,7 @@
> > ACTION="$5"
> >
> > if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:log" ]; then exit 0; fi
> > +if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:date" ]; then exit 0; fi
> > if [ "$ACTION" = "A" -a "$PROPNAME" = "hg:convert-branch" ]; then exit 0; fi
> > if [ "$ACTION" = "A" -a "$PROPNAME" = "hg:convert-rev" ]; then exit 0; fi
> >
> > @@ -1242,6 +1243,11 @@
> >             if commit.branch and commit.branch != 'default':
> >                 self.run('propset', 'hg:convert-branch', commit.branch,
> >                          revprop=True, revision=rev)
> > +            if commit.date:
> > +                date = dateutil.parser.parse(commit.date)
>
> I think this should be    date = util.parsedate(commit.date)[0]
>
> > +                self.run('propset', 'svn:date',
> > +                         date.strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
>
> probably:                   util.datestr((date, 0), '%Y-%m-%dT%H:%M:%S.%fZ)
>
> Not 100% sure about omitting TZ and the float though.
>
> --
> theatre - books - texts - movies
> Black Trash Productions at home: http://www.blacktrash.org
> Black Trash Productions on Facebook:
> http://www.facebook.com/blacktrashproductions
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/hgext/convert/subversion.py b/hgext/convert/subversion.py
--- a/hgext/convert/subversion.py
+++ b/hgext/convert/subversion.py
@@ -2,7 +2,7 @@ 
 #
 # Copyright(C) 2007 Daniel Holth et al
 
-import os, re, sys, tempfile, urllib, urllib2, xml.dom.minidom
+import os, re, sys, tempfile, urllib, urllib2, xml.dom.minidom, dateutil.parser
 import cPickle as pickle
 
 from mercurial import strutil, scmutil, util, encoding
@@ -992,6 +992,7 @@ 
 ACTION="$5"
 
 if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:log" ]; then exit 0; fi
+if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:date" ]; then exit 0; fi
 if [ "$ACTION" = "A" -a "$PROPNAME" = "hg:convert-branch" ]; then exit 0; fi
 if [ "$ACTION" = "A" -a "$PROPNAME" = "hg:convert-rev" ]; then exit 0; fi
 
@@ -1242,6 +1243,11 @@ 
             if commit.branch and commit.branch != 'default':
                 self.run('propset', 'hg:convert-branch', commit.branch,
                          revprop=True, revision=rev)
+            if commit.date:
+                date = dateutil.parser.parse(commit.date)
+                self.run('propset', 'svn:date',
+                         date.strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
+                         revprop=True, revision=rev)
             for parent in parents:
                 self.addchild(parent, rev)
             return self.revid(rev)