[PATCH] cvsps: better use if commitids (when present) to detect changesets

Frank Kingswood frank at kingswood-consulting.co.uk
Mon Jan 14 15:13:55 CST 2013


# HG changeset patch
# User Frank Kingswood <frank at kingswood-consulting.co.uk>
# Date 1357853777 0
# Node ID 10b6ecdb07e43e3090873491ce6b966369aebfd0
# Parent  2eae2f9e85efbcfc5bf5ae40a1313237d71341b5
cvsps: better use if commitids (when present) to detect changesets
split one cvs test for cvs 1.12 and earlier

diff --git a/hgext/convert/cvsps.py b/hgext/convert/cvsps.py
--- a/hgext/convert/cvsps.py
+++ b/hgext/convert/cvsps.py
@@ -33,9 +33,14 @@
                       rlog output) or None
         .branchpoints - the branches that start at the current entry or empty
     '''
-    def __init__(self, **entries):
+    def __init__(self, **values):
+        self.branches=[]
+        self.branchpoints=set()
+        self.commitid=None
+        self.mergepoint=None
+        self.parent=None
         self.synthetic = False
-        self.__dict__.update(entries)
+        self.__dict__.update(values)
 
     def __repr__(self):
         items = ("%s=%r"%(k, self.__dict__[k]) for k in sorted(self.__dict__))
@@ -307,12 +312,7 @@
             e = logentry(rcs=scache(rcs),
                          file=scache(filename),
                          revision=tuple([int(x) for x in
-                                         match.group(1).split('.')]),
-                         branches=[],
-                         parent=None,
-                         commitid=None,
-                         mergepoint=None,
-                         branchpoints=set())
+                                         match.group(1).split('.')]))
 
             state = 6
 
@@ -495,9 +495,11 @@
         .mergepoint- the branch that has been merged from or None
         .branchpoints- the branches that start at the current entry or empty
     '''
-    def __init__(self, **entries):
+    def __init__(self, **values):
+        self.branchpoints = set()
+        self.entries=[]
         self.synthetic = False
-        self.__dict__.update(entries)
+        self.__dict__.update(values)
 
     def __repr__(self):
         items = ("%s=%r"%(k, self.__dict__[k]) for k in sorted(self.__dict__))
@@ -508,13 +510,14 @@
 
     ui.status(_('creating changesets\n'))
 
-    # Merge changesets
-    log.sort(key=lambda x: (x.commitid, x.comment, x.author, x.branch, x.date,
-                            x.branchpoints))
+    # Sort before merging changesets.
+    log.sort(key=lambda x: (x.commitid, x.branchpoints, x.comment, x.author,
+                            x.branch, x.date))
 
     changesets = []
     files = set()
     c = None
+    cdate = 0
     for i, e in enumerate(log):
 
         # Check if log entry belongs to the current changeset or not.
@@ -533,22 +536,26 @@
         # first changeset and bar the next and MYBRANCH and MYBRANCH2
         # should both start off of the bar changeset. No provisions are
         # made to ensure that this is, in fact, what happens.
-        if not (c and e.branchpoints == c.branchpoints and
-                (# cvs commitids
-                 (e.commitid is not None and e.commitid == c.commitid) or
-                 (# no commitids, use fuzzy commit detection
-                  (e.commitid is None or c.commitid is None) and
-                   e.comment == c.comment and
-                   e.author == c.author and
-                   e.branch == c.branch and
-                   ((c.date[0] + c.date[1]) <=
-                    (e.date[0] + e.date[1]) <=
-                    (c.date[0] + c.date[1]) + fuzz) and
-                   e.file not in files))):
+
+        if c is None:
+            same = False
+        elif e.commitid is not None and c.commitid is not None:
+            # CVS commitids
+            same = e.commitid == c.commitid
+        else:
+            # No CVS commitids, use fuzzy commit detection
+            same = (e.branchpoints == c.branchpoints and
+                    e.comment == c.comment and
+                    e.author == c.author and
+                    e.branch == c.branch and
+                    cdate <= (e.date[0] + e.date[1]) <= (cdate + fuzz) and
+                    e.file not in files)
+
+        if not same:
             c = changeset(comment=e.comment, author=e.author,
                           branch=e.branch, date=e.date,
-                          entries=[], mergepoint=e.mergepoint,
-                          branchpoints=e.branchpoints, commitid=e.commitid)
+                          mergepoint=e.mergepoint,
+                          commitid=e.commitid)
             changesets.append(c)
 
             files = set()
@@ -556,9 +563,11 @@
                 t = '%d %s' % (len(changesets), repr(e.comment)[1:-1])
                 ui.status(util.ellipsis(t, 80) + '\n')
 
+        c.branchpoints.update(e.branchpoints)
         c.entries.append(e)
         files.add(e.file)
         c.date = e.date       # changeset date is date of latest commit in it
+        cdate = c.date[0] + c.date[1]
 
     # Mark synthetic changesets
 
diff --git a/tests/test-convert-cvs-branch.t b/tests/test-convert-cvs-branch.t
--- a/tests/test-convert-cvs-branch.t
+++ b/tests/test-convert-cvs-branch.t
@@ -67,11 +67,10 @@
   collecting CVS rlog
   7 log entries
   creating changesets
-  5 changeset entries
+  4 changeset entries
   sorting...
   converting...
-  4 Initial revision
-  3 init
+  3 Initial revision
   2 mod a
   1 mod b
   0 mod a again
@@ -80,15 +79,13 @@
 Check the result
 
   $ hg -R src-hg glog --template '{rev} ({branches}) {desc} files: {files}\n'
-  o  5 () update tags files: .hgtags
+  o  4 () update tags files: .hgtags
   |
-  | o  4 (BRANCH) mod a again files: a
+  | o  3 (BRANCH) mod a again files: a
   | |
-  | o  3 (BRANCH) mod b files: b
+  | o  2 (BRANCH) mod b files: b
   | |
-  | o  2 (BRANCH) mod a files: a
-  | |
-  | o  1 (v0) init files:
+  | o  1 (BRANCH) mod a files: a
   |/
   o  0 () Initial revision files: a b
   
diff --git a/tests/test-convert-cvs.t b/tests/test-convert-cvs-commitids.t
copy from tests/test-convert-cvs.t
copy to tests/test-convert-cvs-commitids.t
--- a/tests/test-convert-cvs.t
+++ b/tests/test-convert-cvs-commitids.t
@@ -1,5 +1,5 @@
 
-  $ "$TESTDIR/hghave" cvs || exit 80
+  $ "$TESTDIR/hghave" cvs112 || exit 80
   $ cvscall()
   > {
   >     cvs -f "$@"
@@ -86,16 +86,16 @@
   5 log entries
   cvslog hook: 5 entries
   creating changesets
-  3 changeset entries
-  cvschangesets hook: 3 changesets
+  2 changeset entries
+  cvschangesets hook: 2 changesets
   sorting...
   converting...
-  2 Initial revision
   1 import
   0 ci0
   updating tags
   $ hgcat a
-  a
+  a: no such file in rev * (glob)
+  [1]
   $ hgcat b/c
   c
   c
@@ -111,14 +111,11 @@
   5 log entries
   cvslog hook: 5 entries
   creating changesets
-  3 changeset entries
-  cvschangesets hook: 3 changesets
+  2 changeset entries
+  cvschangesets hook: 2 changesets
   sorting...
   converting...
-  2 Initial revision
   1 import
-  filtering out empty revision
-  repository tip rolled back to revision 0 (undo commit)
   0 ci0
   updating tags
   $ hgcat b/c
@@ -127,7 +124,7 @@
   $ hg -R src-filemap log --template '{rev} {desc} files: {files}\n'
   2 update tags files: .hgtags
   1 ci0 files: b/c
-  0 Initial revision files: b/c
+  0 import files: b/c
 
 convert full repository (issue1649)
 
@@ -146,12 +143,12 @@
   scanning source...
   collecting CVS rlog
   creating changesets
-  4 changeset entries
   sorting...
   converting...
   updating tags
   $ hg cat -r tip --cwd srcfull-hg src/a
-  a
+  src/a: no such file in rev * (glob)
+  [1]
   $ hg cat -r tip --cwd srcfull-hg src/b/c
   c
   c
@@ -175,8 +172,8 @@
   7 log entries
   cvslog hook: 7 entries
   creating changesets
-  4 changeset entries
-  cvschangesets hook: 4 changesets
+  3 changeset entries
+  cvschangesets hook: 3 changesets
   sorting...
   converting...
   0 ci1
@@ -197,8 +194,8 @@
   7 log entries
   cvslog hook: 7 entries
   creating changesets
-  4 changeset entries
-  cvschangesets hook: 4 changesets
+  3 changeset entries
+  cvschangesets hook: 3 changesets
   sorting...
   converting...
   0 ci1
@@ -210,7 +207,7 @@
   3 ci1 files: b/c
   2 update tags files: .hgtags
   1 ci0 files: b/c
-  0 Initial revision files: b/c
+  0 import files: b/c
 
 commit branch
 
@@ -235,8 +232,8 @@
   8 log entries
   cvslog hook: 8 entries
   creating changesets
-  5 changeset entries
-  cvschangesets hook: 5 changesets
+  4 changeset entries
+  cvschangesets hook: 4 changesets
   sorting...
   converting...
   0 ci2
@@ -253,8 +250,8 @@
   8 log entries
   cvslog hook: 8 entries
   creating changesets
-  5 changeset entries
-  cvschangesets hook: 5 changesets
+  4 changeset entries
+  cvschangesets hook: 4 changesets
   sorting...
   converting...
   0 ci2
@@ -266,7 +263,7 @@
   3 ci1 files: b/c
   2 update tags files: .hgtags
   1 ci0 files: b/c
-  0 Initial revision files: b/c
+  0 import files: b/c
 
 commit a new revision with funny log message
 
@@ -278,191 +275,43 @@
   > log message' . | grep '<--' |\
   >  sed -e 's:.*src/\(.*\),v.*:checking in src/\1,v:g'
   checking in src/a,v
-
-commit new file revisions with some fuzz
-
-  $ sleep 1
-  $ echo f >> a
-  $ cvscall -q commit -mfuzzy . | grep '<--'
-  $TESTTMP/cvsrepo/src/a,v  <--  a
-  $ sleep 4 # the two changes will be split if fuzz < 4
-  $ echo g >> b/c
-  $ cvscall -q commit -mfuzzy . | grep '<--'
-  $TESTTMP/cvsrepo/src/b/c,v  <--  *c (glob)
   $ cd ..
 
 convert again
 
-  $ TZ=US/Hawaii hg convert --config convert.cvsps.fuzz=2 --config convert.localtimezone=True src src-hg
+  $ TZ=US/Hawaii hg convert --config convert.localtimezone=True src src-hg
   connecting to $TESTTMP/cvsrepo
   scanning source...
   collecting CVS rlog
-  11 log entries
-  cvslog hook: 11 entries
+  9 log entries
+  cvslog hook: 9 entries
   creating changesets
-  8 changeset entries
-  cvschangesets hook: 8 changesets
+  5 changeset entries
+  cvschangesets hook: 5 changesets
   sorting...
   converting...
-  2 funny
-  1 fuzzy
-  0 fuzzy
-  $ 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)
+  0 funny
+
+graphical log
+
+  $ hg -R src-hg glog --style compact
+  o  5[tip]   * (glob)
+  |    funny
   |
-  o  7 (branch) fuzzy date: * -1000 files: a (glob)
+  o  4:-1   * (glob)
+       ci2
+  
+  o  3   * (glob)
+  |    ci1
   |
-  o  6 (branch) funny
-  |  ----------------------------
-  |  log message date: * -1000 files: a (glob)
-  o  5 (branch) ci2 date: * -1000 files: b/c (glob)
+  o  2   * (glob)
+  |    update tags
+  |
+  o  1:-1   * (glob)
+       ci0
   
-  o  4 () ci1 date: * -1000 files: a b/c (glob)
-  |
-  o  3 () update tags date: * +0000 files: .hgtags (glob)
-  |
-  o  2 () ci0 date: * -1000 files: b/c (glob)
-  |
-  | o  1 (INITIAL) import date: * -1000 files: (glob)
-  |/
-  o  0 () Initial revision date: * -1000 files: a b/c (glob)
+  o  0[start]   * (glob)
+       import
   
 
-testing debugcvsps
 
-  $ cd src
-  $ hg debugcvsps --fuzz=2
-  collecting CVS rlog
-  11 log entries
-  cvslog hook: 11 entries
-  creating changesets
-  10 changeset entries
-  cvschangesets hook: 10 changesets
-  ---------------------
-  PatchSet 1 
-  Date: * (glob)
-  Author: * (glob)
-  Branch: HEAD
-  Tag: (none) 
-  Branchpoints: INITIAL 
-  Log:
-  Initial revision
-  
-  Members: 
-  	a:INITIAL->1.1 
-  
-  ---------------------
-  PatchSet 2 
-  Date: * (glob)
-  Author: * (glob)
-  Branch: HEAD
-  Tag: (none) 
-  Branchpoints: INITIAL, branch 
-  Log:
-  Initial revision
-  
-  Members: 
-  	b/c:INITIAL->1.1 
-  
-  ---------------------
-  PatchSet 3 
-  Date: * (glob)
-  Author: * (glob)
-  Branch: INITIAL
-  Tag: start 
-  Log:
-  import
-  
-  Members: 
-  	a:1.1->1.1.1.1 
-  	b/c:1.1->1.1.1.1 
-  
-  ---------------------
-  PatchSet 4 
-  Date: * (glob)
-  Author: * (glob)
-  Branch: HEAD
-  Tag: (none) 
-  Log:
-  ci0
-  
-  Members: 
-  	b/c:1.1->1.2 
-  
-  ---------------------
-  PatchSet 5 
-  Date: * (glob)
-  Author: * (glob)
-  Branch: HEAD
-  Tag: (none) 
-  Log:
-  ci1
-  
-  Members: 
-  	b/c:1.2->1.3 
-  
-  ---------------------
-  PatchSet 6 
-  Date: * (glob)
-  Author: * (glob)
-  Branch: HEAD
-  Tag: (none) 
-  Branchpoints: branch 
-  Log:
-  ci1
-  
-  Members: 
-  	a:1.1->1.2 
-  
-  ---------------------
-  PatchSet 7 
-  Date: * (glob)
-  Author: * (glob)
-  Branch: branch
-  Tag: (none) 
-  Log:
-  ci2
-  
-  Members: 
-  	b/c:1.1->1.1.2.1 
-  
-  ---------------------
-  PatchSet 8 
-  Date: * (glob)
-  Author: * (glob)
-  Branch: branch
-  Tag: (none) 
-  Log:
-  funny
-  ----------------------------
-  log message
-  
-  Members: 
-  	a:1.2->1.2.2.1 
-  
-  ---------------------
-  PatchSet 9 
-  Date: * (glob)
-  Author: * (glob)
-  Branch: branch
-  Tag: (none) 
-  Log:
-  fuzzy
-  
-  Members: 
-  	a:1.2.2.1->1.2.2.2 
-  
-  ---------------------
-  PatchSet 10 
-  Date: * (glob)
-  Author: * (glob)
-  Branch: branch
-  Tag: (none) 
-  Log:
-  fuzzy
-  
-  Members: 
-  	b/c:1.1.2.1->1.1.2.2 
-  
-
-  $ cd ..
diff --git a/tests/test-convert-cvs-synthetic.t b/tests/test-convert-cvs-synthetic.t
--- a/tests/test-convert-cvs-synthetic.t
+++ b/tests/test-convert-cvs-synthetic.t
@@ -1,6 +1,6 @@
 This feature requires use of builtin cvsps!
 
-  $ "$TESTDIR/hghave" cvs || exit 80
+  $ "$TESTDIR/hghave" cvs112 || exit 80
   $ echo "[extensions]" >> $HGRCPATH
   $ echo "convert = " >> $HGRCPATH
   $ echo "graphlog = " >> $HGRCPATH
@@ -140,13 +140,12 @@
   collecting CVS rlog
   15 log entries
   creating changesets
-  9 changeset entries
+  8 changeset entries
   sorting...
   converting...
-  8 add file1 on trunk
-  7 add file2
-  6 MERGE from v1_0: add file2
-  5 file file3 was initially added on branch v1_1.
+  7 add file1 on trunk
+  6 add file2
+  5 MERGE from v1_0: add file2
   4 add file3, file4 on branch v1_1
   3 add file5 on v1_2
   2 add file6 on trunk post-v1_2
@@ -156,20 +155,18 @@
 hg glog output (#1)
 
   $ hg -R proj.hg glog --template "{rev} {desc}\n"
-  o  8 MERGE from v1_2: add file5
+  o  7 MERGE from v1_2: add file5
   |
-  | o  7 MERGE from HEAD: add file6
+  | o  6 MERGE from HEAD: add file6
   | |
-  o |  6 add file6 on trunk post-v1_2
+  o |  5 add file6 on trunk post-v1_2
   | |
-  | o  5 add file5 on v1_2
+  | o  4 add file5 on v1_2
+  |/
+  | o  3 add file3, file4 on branch v1_1
   | |
-  | | o  4 add file3, file4 on branch v1_1
-  | | |
-  o | |  3 file file3 was initially added on branch v1_1.
-  |/ /
   | o  2 MERGE from v1_0: add file2
-  |/
+  | |
   | o  1 add file2
   |/
   o  0 add file1 on trunk
@@ -187,13 +184,12 @@
   collecting CVS rlog
   15 log entries
   creating changesets
-  9 changeset entries
+  8 changeset entries
   sorting...
   converting...
-  8 add file1 on trunk
-  7 add file2
-  6 MERGE from v1_0: add file2
-  5 file file3 was initially added on branch v1_1.
+  7 add file1 on trunk
+  6 add file2
+  5 MERGE from v1_0: add file2
   4 add file3, file4 on branch v1_1
   3 add file5 on v1_2
   2 add file6 on trunk post-v1_2
@@ -203,20 +199,18 @@
 hg glog output (#2)
 
   $ hg -R proj.hg2 glog --template "{rev} {desc}\n"
-  o  8 MERGE from v1_2: add file5
+  o  7 MERGE from v1_2: add file5
   |
-  | o  7 MERGE from HEAD: add file6
+  | o  6 MERGE from HEAD: add file6
   | |
-  o |  6 add file6 on trunk post-v1_2
+  o |  5 add file6 on trunk post-v1_2
   | |
-  | o  5 add file5 on v1_2
+  | o  4 add file5 on v1_2
+  |/
+  | o  3 add file3, file4 on branch v1_1
   | |
-  | | o  4 add file3, file4 on branch v1_1
-  | | |
-  o | |  3 file file3 was initially added on branch v1_1.
-  |/ /
   | o  2 MERGE from v1_0: add file2
-  |/
+  | |
   | o  1 add file2
   |/
   o  0 add file1 on trunk
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
@@ -1,5 +1,6 @@
 
   $ "$TESTDIR/hghave" cvs || exit 80
+  $ "$TESTDIR/hghave" cvs112 && exit 80
   $ cvscall()
   > {
   >     cvs -f "$@"
@@ -466,3 +467,4 @@
   
 
   $ cd ..
+


More information about the Mercurial-devel mailing list