Patchwork D9715: convert: set date and time for svn commits

login
register
mail settings
Submitter phabricator
Date Jan. 8, 2021, 11:41 p.m.
Message ID <differential-rev-PHID-DREV-cxfgg3dkzkr6bfm6ddym-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48026/
State Superseded
Headers show

Comments

phabricator - Jan. 8, 2021, 11:41 p.m.
nslsrv created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Committing to subversion repository is changed to use commit dates from
  the source. Subversion always uses commit dates with UTC timezone, so only
  timestamps are used.
  
  Test `test-convert-svn-sink.t` uses `svnxml.py` script to dump history of svn
  repositories. Atm the script is not printing `date` field from svn log. This
  patch changes this to allow checks on correctness of date and time convertion.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9715

AFFECTED FILES
  hgext/convert/subversion.py
  tests/svnxml.py
  tests/test-convert-hg-svn.t
  tests/test-convert-svn-sink.t

CHANGE DETAILS




To: nslsrv, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-convert-svn-sink.t b/tests/test-convert-svn-sink.t
--- a/tests/test-convert-svn-sink.t
+++ b/tests/test-convert-svn-sink.t
@@ -54,10 +54,12 @@ 
    2 2 test a
   revision: 2
   author: test
+  date: 1970-01-01T00:00:01.000000Z
   msg: modify a file
    M /a
   revision: 1
   author: test
+  date: 1970-01-01T00:00:00.000000Z
   msg: add a file
    A /a
    A /d1
@@ -95,6 +97,7 @@ 
    3 3 test b
   revision: 3
   author: test
+  date: 1970-01-01T00:00:02.000000Z
   msg: rename a file
    D /a
    A /b (from /a@2)
@@ -131,6 +134,7 @@ 
    4 4 test c
   revision: 4
   author: test
+  date: 1970-01-01T00:00:03.000000Z
   msg: copy a file
    A /c (from /b@3)
   $ ls a a-hg-wc
@@ -167,6 +171,7 @@ 
    5 5 test .
   revision: 5
   author: test
+  date: 1970-01-01T00:00:04.000000Z
   msg: remove a file
    D /b
   $ ls a a-hg-wc
@@ -209,6 +214,7 @@ 
    6 6 test c
   revision: 6
   author: test
+  date: 1970-01-01T00:00:05.000000Z
   msg: make a file executable
    M /c
 #if execbit
@@ -247,6 +253,7 @@ 
    8 8 test newlink
   revision: 8
   author: test
+  date: 1970-01-01T00:00:00.000000Z
   msg: move symlink
    D /link
    A /newlink (from /link@7)
@@ -278,6 +285,7 @@ 
    7 7 test f
   revision: 7
   author: test
+  date: 1970-01-01T00:00:00.000000Z
   msg: f
    D /c
    A /d
@@ -315,6 +323,7 @@ 
    1 1 test d1/a
   revision: 1
   author: test
+  date: 1970-01-01T00:00:00.000000Z
   msg: add executable file in new directory
    A /d1
    A /d1/a
@@ -343,6 +352,7 @@ 
    2 2 test d2/a
   revision: 2
   author: test
+  date: 1970-01-01T00:00:01.000000Z
   msg: copy file to new directory
    A /d2
    A /d2/a (from /d1/a@1)
@@ -416,21 +426,25 @@ 
    4 4 test right-2
   revision: 4
   author: test
+  date: 1970-01-01T00:00:05.000000Z
   msg: merge
    A /right-1
    A /right-2
   revision: 3
   author: test
+  date: 1970-01-01T00:00:02.000000Z
   msg: left-2
    M /b
    A /left-2
   revision: 2
   author: test
+  date: 1970-01-01T00:00:01.000000Z
   msg: left-1
    M /b
    A /left-1
   revision: 1
   author: test
+  date: 1970-01-01T00:00:00.000000Z
   msg: base
    A /b
 
@@ -459,10 +473,12 @@ 
    2 2 test .hgtags
   revision: 2
   author: test
+  date: 1970-01-01T00:00:01.000000Z
   msg: Tagged as v1.0
    A /.hgtags
   revision: 1
   author: test
+  date: 1970-01-01T00:00:00.000000Z
   msg: Add file a
    A /a
   $ rm -rf a a-hg a-hg-wc
@@ -494,10 +510,12 @@ 
    2 2 test exec
   revision: 2
   author: test
+  date: 1970-01-01T00:00:02.000000Z
   msg: remove executable bit
    M /exec
   revision: 1
   author: test
+  date: 1970-01-01T00:00:01.000000Z
   msg: create executable
    A /exec
   $ test ! -x a-hg-wc/exec
@@ -540,10 +558,12 @@ 
    2 2 test b
   revision: 2
   author: test
+  date: 1970-01-01T00:00:00.000000Z
   msg: Another change
    A /b
   revision: 1
   author: test
+  date: 1970-01-01T00:00:00.000000Z
   msg: Some change
    A /a
 
diff --git a/tests/test-convert-hg-svn.t b/tests/test-convert-hg-svn.t
--- a/tests/test-convert-hg-svn.t
+++ b/tests/test-convert-hg-svn.t
@@ -24,6 +24,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
   > 
diff --git a/tests/svnxml.py b/tests/svnxml.py
--- a/tests/svnxml.py
+++ b/tests/svnxml.py
@@ -15,6 +15,7 @@ 
     e['revision'] = entry.getAttribute('revision')
     e['author'] = xmltext(entry.getElementsByTagName('author')[0])
     e['msg'] = xmltext(entry.getElementsByTagName('msg')[0])
+    e['date'] = xmltext(entry.getElementsByTagName('date')[0])
     e['paths'] = []
     paths = entry.getElementsByTagName('paths')
     if paths:
@@ -42,7 +43,7 @@ 
     except AttributeError:
         fp = sys.stdout
     for e in entries:
-        for k in ('revision', 'author', 'msg'):
+        for k in ('revision', 'author', 'date', 'msg'):
             fp.write(('%s: %s\n' % (k, e[k])).encode('utf-8'))
         for path, action, fpath, frev in sorted(e['paths']):
             frominfo = b''
diff --git a/hgext/convert/subversion.py b/hgext/convert/subversion.py
--- a/hgext/convert/subversion.py
+++ b/hgext/convert/subversion.py
@@ -1389,6 +1389,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
 
@@ -1636,6 +1637,9 @@ 
         fp = os.fdopen(fd, 'wb')
         fp.write(util.tonativeeol(commit.desc))
         fp.close()
+        # Subverson always uses UTC to represent date and time
+        date = dateutil.parsedate(commit.date)
+        svndate = dateutil.datestr((date[0], 0), b'%Y-%m-%dT%H:%M:%S.000000Z')
         try:
             output = self.run0(
                 b'commit',
@@ -1667,6 +1671,14 @@ 
                     revprop=True,
                     revision=rev,
                 )
+            # The only way to set date and time for svn commit is to use propset after commit is done
+            self.run(
+                b'propset',
+                b'svn:date',
+                svndate,
+                revprop=True,
+                revision=rev,
+            )
             for parent in parents:
                 self.addchild(parent, rev)
             return self.revid(rev)