[PATCH] [RFC] convert: fix --datesort

Maxim Dounin mdounin at mdounin.ru
Thu Dec 20 09:52:18 CST 2007


Hello!

On Thu, 20 Dec 2007, Kirill Smelkov wrote:

> В сообщении от 19 декабря 2007 04:51 Matt Mackall написал(a):
>> On Wed, Dec 19, 2007 at 01:52:22AM +0300, Maxim Dounin wrote:
>>> Hello!
>>>
>>> On Thu, 13 Dec 2007, Kirill Smelkov wrote:
>>>> # HG changeset patch
>>>> # User Kirill Smelkov <kirr at mns.spb.ru>
>>>> # Date 1197567565 -10800
>>>> # Node ID 7a1570348d6df8f59289eddaee9452393033b078
>>>> # Parent  eb2f94f6aeabff1638e0ad3c46fcbe80bf4e8fc2
>>>> [RFC] convert: fix --datesort
>>>>
>>>> The problem is that previously commit.date was used for sorting, but
>>>> it's a string like "1 Jan xxx 2007", so it it wrong to use it for
>>>> sorting.
>>>>
>>>> Another problem is that why we are using depth for sorting -- I have no
>>>> clear answer -- it seems to be plain wrong.
>>>
>>> As far as I understand, depth is here to make sure parent changeset
>>> always commited before it's child regardless of dates specified.
>>>
>>> I don't think dropping this invariant is a good idea.
>>
>> Indeed, and it fails tests in our test suite.
>>
>> But never fear, I already fixed it and pushed it to mainline.
>
> I agree that commits habe to go after their parents, but sorting on depth is
> wrong too.
>
> Consider we have two named branches A & B,
>
> - then we do 100 commits on A
> - then 1 commit on B
> - then another 100 commits on A
> - then another 1 commit on B
>
> All these commits are ordered by date.
>
> Then we try to do hg convert --datesort, and what we'll have?
>
> not strictly correct, but this illustrates the bug:
>
> 1 commit on A,
> 1 commit on B
> 1 commit on A
> 1 commit on B
> 198 commits on A
>
> And this is plain wrong, and I was beaten by that!

Agreed, using depth as of now isn't do it's best for preserving date 
order.

The following patch makes it a bit better by incrementing depth only when 
changesets out of date order encountered. Though it still does strange 
things when out-of-date changesets found.

# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1198165526 -10800
# Node ID 9d4580136bd4ed45b6f7c899fc3133aed8cdf131
# Parent  4f977c6d3c036c9bf1d38140637199727b2f2a55
convert: fix --datesort to produce more correct order

Bump depth only if out-of-date-order changes encountered. This allows
us to correctly preserve date order for repos without out-of-date-order
changes.

diff -r 4f977c6d3c03 -r 9d4580136bd4 hgext/convert/convcmd.py
--- a/hgext/convert/convcmd.py  Wed Dec 19 19:23:18 2007 -0800
+++ b/hgext/convert/convcmd.py  Thu Dec 20 18:45:26 2007 +0300
@@ -143,7 +143,12 @@ class converter(object):
                  pl = [p for p in self.commitcache[n].parents
                        if p not in self.map]
                  if pl:
-                    depth[n] = max([depth[p] for p in pl]) + 1
+                    depth[n] = max([depth[p] for p in pl])
+                    wayback = [1 for p in pl
+                        if not util.parsedate(self.commitcache[n].date) >
+                               util.parsedate(self.commitcache[p].date)]
+                    if wayback:
+                        depth[n] += 1

              s = [(depth[n], util.parsedate(self.commitcache[n].date), n)
                   for n in s]



Maxim Dounin



More information about the Mercurial-devel mailing list