Patchwork cvsps: fix computation of parent revisions when log caching is on

login
register
mail settings
Submitter Emanuele Giaquinta
Date Oct. 7, 2015, 10:32 a.m.
Message ID <20151007103238.GB35606@t30500-la053.org.aalto.fi>
Download mbox | patch
Permalink /patch/10853/
State Superseded
Commit c60dfcc0abf2fadad062511a6c17837c8a1271f7
Headers show

Comments

Emanuele Giaquinta - Oct. 7, 2015, 10:32 a.m.
# HG changeset patch
# User Emanuele Giaquinta <emanuele.giaquinta@gmail.com>
# Date 1444206832 -10800
#      Wed Oct 07 11:33:52 2015 +0300
# Node ID cacca520238c70e0411905230c67a7e8132436ef
# Parent  efd57cd6fd1d5eb76102fabfc45676873bbba29d
cvsps: fix computation of parent revisions when log caching is on

cvsps computes the parent revisions of log entries by walking the cvs log
sorted by (rcs, revision) and by iteratively maintaining a 'versions'
dictionary which maps a (rcs, branch) pair onto the last revision seen for that
pair. When log caching is on and a log cache exists, cvsps fails to set the
parent revisions of new log entries because it does not iterate over the log
cache in the parents computation. A complication is that a file rcs can change
(move to/from the attic), with respect to its value in the log cache, if the
file is removed/added back. This patch adds an iteration over the log cache to
update the rcs of cached log entries, if changed, and to properly populate the
'versions' dictionary.
Augie Fackler - Oct. 8, 2015, 5:39 p.m.
On Wed, Oct 07, 2015 at 01:32:38PM +0300, Emanuele Giaquinta wrote:
> # HG changeset patch
> # User Emanuele Giaquinta <emanuele.giaquinta@gmail.com>
> # Date 1444206832 -10800
> #      Wed Oct 07 11:33:52 2015 +0300
> # Node ID cacca520238c70e0411905230c67a7e8132436ef
> # Parent  efd57cd6fd1d5eb76102fabfc45676873bbba29d
> cvsps: fix computation of parent revisions when log caching is on

seems mostly good, one question below

>
> cvsps computes the parent revisions of log entries by walking the cvs log
> sorted by (rcs, revision) and by iteratively maintaining a 'versions'
> dictionary which maps a (rcs, branch) pair onto the last revision seen for that
> pair. When log caching is on and a log cache exists, cvsps fails to set the
> parent revisions of new log entries because it does not iterate over the log
> cache in the parents computation. A complication is that a file rcs can change
> (move to/from the attic), with respect to its value in the log cache, if the
> file is removed/added back. This patch adds an iteration over the log cache to
> update the rcs of cached log entries, if changed, and to properly populate the
> 'versions' dictionary.
>

[snip]

> diff -r efd57cd6fd1d -r cacca520238c tests/test-cvsps.t
> --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
> +++ b/tests/test-cvsps.t	Wed Oct 07 11:33:52 2015 +0300
> @@ -0,0 +1,95 @@
> +#require cvs

is there any way this test can piggyback on one of the existing CVS tests?

> +
> +  $ cvscall()
> +  > {
> +  >     cvs -f "$@" > /dev/null
> +  > }
> +  $ cat <<EOF >> $HGRCPATH
> +  > [extensions]
> +  > convert =
> +  > EOF
> +
> +create cvs repository
> +
> +  $ mkdir cvsrepo
> +  $ cd cvsrepo
> +  $ CVSROOT=`pwd`
> +  $ export CVSROOT
> +  $ CVS_OPTIONS=-f
> +  $ export CVS_OPTIONS
> +  $ cd ..
> +  $ rmdir cvsrepo
> +  $ cvscall -q -d "$CVSROOT" init
> +
> +Create a new project
> +
> +  $ mkdir src
> +  $ cd src
> +  $ echo "1" > a
> +  $ echo "1" > b
> +  $ cvscall import -m "init" src v0 r0 | sort
> +  $ cd ..
> +  $ cvscall co src
> +  cvs checkout: Updating src
> +  $ cd src
> +
> +Create the cvsps cache file
> +
> +  $ hg debugcvsps -x >/dev/null
> +
> +Modify file a and remove file b
> +
> +  $ echo "2" >> a
> +  $ cvscall rm -f b
> +  cvs remove: scheduling `b' for removal
> +  cvs remove: use 'cvs commit' to remove this file permanently
> +  $ cvscall ci -m 'update'
> +  cvs commit: Examining .
> +
> +Update and verify the cache file
> +
> +  $ hg debugcvsps -u
> +  collecting CVS rlog
> +  6 log entries
> +  creating changesets
> +  3 changeset entries
> +  ---------------------
> +  PatchSet 1
> +  Date: * (glob)
> +  Author: * (glob)
> +  Branch: HEAD
> +  Tag: (none)
> +  Branchpoints: v0
> +  Log:
> +  Initial revision
> +
> +  Members:
> +     a:INITIAL->1.1
> +     b:INITIAL->1.1
> +
> +  ---------------------
> +  PatchSet 2
> +  Date: * (glob)
> +  Author: * (glob)
> +  Branch: v0
> +  Tag: r0
> +  Log:
> +  init
> +
> +  Members:
> +     a:1.1->1.1.1.1
> +     b:1.1->1.1.1.1
> +
> +  ---------------------
> +  PatchSet 3
> +  Date: * (glob)
> +  Author: * (glob)
> +  Branch: HEAD
> +  Tag: (none)
> +  Log:
> +  update
> +
> +  Members:
> +     a:1.1->1.2
> +     b:1.1->1.2(DEAD)
> +
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel
Emanuele Giaquinta - Oct. 9, 2015, 12:30 p.m.
Hi,

On Thu, Oct 08, 2015 at 01:39:46PM -0400, Augie Fackler wrote:
> On Wed, Oct 07, 2015 at 01:32:38PM +0300, Emanuele Giaquinta wrote:
> > # HG changeset patch
> > # User Emanuele Giaquinta <emanuele.giaquinta@gmail.com>
> > # Date 1444206832 -10800
> > #      Wed Oct 07 11:33:52 2015 +0300
> > # Node ID cacca520238c70e0411905230c67a7e8132436ef
> > # Parent  efd57cd6fd1d5eb76102fabfc45676873bbba29d
> > cvsps: fix computation of parent revisions when log caching is on
> 
> seems mostly good, one question below
> 
> >
> > cvsps computes the parent revisions of log entries by walking the cvs log
> > sorted by (rcs, revision) and by iteratively maintaining a 'versions'
> > dictionary which maps a (rcs, branch) pair onto the last revision seen for that
> > pair. When log caching is on and a log cache exists, cvsps fails to set the
> > parent revisions of new log entries because it does not iterate over the log
> > cache in the parents computation. A complication is that a file rcs can change
> > (move to/from the attic), with respect to its value in the log cache, if the
> > file is removed/added back. This patch adds an iteration over the log cache to
> > update the rcs of cached log entries, if changed, and to properly populate the
> > 'versions' dictionary.
> >
> 
> [snip]
> 
> > diff -r efd57cd6fd1d -r cacca520238c tests/test-cvsps.t
> > --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
> > +++ b/tests/test-cvsps.t	Wed Oct 07 11:33:52 2015 +0300
> > @@ -0,0 +1,95 @@
> > +#require cvs
> 
> is there any way this test can piggyback on one of the existing CVS tests?

I moved the test in test-convert-cvs.t and sent an updated patch.

Emanuele

Patch

diff -r efd57cd6fd1d -r cacca520238c hgext/convert/cvsps.py
--- a/hgext/convert/cvsps.py	Fri Sep 25 12:39:23 2015 -0700
+++ b/hgext/convert/cvsps.py	Wed Oct 07 11:33:52 2015 +0300
@@ -207,6 +207,7 @@ 
     # state machine begins here
     tags = {}     # dictionary of revisions on current file with their tags
     branchmap = {} # mapping between branch names and revision numbers
+    rcsmap = {}
     state = 0
     store = False # set when a new record can be appended
 
@@ -439,6 +440,8 @@ 
 
             log.append(e)
 
+            rcsmap[e.rcs.replace('/Attic/', '/')] = e.rcs
+
             if len(log) % 100 == 0:
                 ui.status(util.ellipsis('%d %s' % (len(log), e.file), 80)+'\n')
 
@@ -446,6 +449,13 @@ 
 
     # find parent revisions of individual files
     versions = {}
+    for e in sorted(oldlog, key=lambda x: (x.rcs, x.revision)):
+        rcs = e.rcs.replace('/Attic/', '/')
+        if rcs in rcsmap:
+            e.rcs = rcsmap[rcs]
+        branch = e.revision[:-1]
+        versions[(e.rcs, branch)] = e.revision
+
     for e in log:
         branch = e.revision[:-1]
         p = versions.get((e.rcs, branch), None)
diff -r efd57cd6fd1d -r cacca520238c tests/test-cvsps.t
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-cvsps.t	Wed Oct 07 11:33:52 2015 +0300
@@ -0,0 +1,95 @@ 
+#require cvs
+
+  $ cvscall()
+  > {
+  >     cvs -f "$@" > /dev/null
+  > }
+  $ cat <<EOF >> $HGRCPATH
+  > [extensions]
+  > convert =
+  > EOF
+
+create cvs repository
+
+  $ mkdir cvsrepo
+  $ cd cvsrepo
+  $ CVSROOT=`pwd`
+  $ export CVSROOT
+  $ CVS_OPTIONS=-f
+  $ export CVS_OPTIONS
+  $ cd ..
+  $ rmdir cvsrepo
+  $ cvscall -q -d "$CVSROOT" init
+
+Create a new project
+
+  $ mkdir src
+  $ cd src
+  $ echo "1" > a
+  $ echo "1" > b
+  $ cvscall import -m "init" src v0 r0 | sort
+  $ cd ..
+  $ cvscall co src
+  cvs checkout: Updating src
+  $ cd src
+
+Create the cvsps cache file
+
+  $ hg debugcvsps -x >/dev/null
+
+Modify file a and remove file b
+
+  $ echo "2" >> a
+  $ cvscall rm -f b
+  cvs remove: scheduling `b' for removal
+  cvs remove: use 'cvs commit' to remove this file permanently
+  $ cvscall ci -m 'update'
+  cvs commit: Examining .
+
+Update and verify the cache file
+
+  $ hg debugcvsps -u
+  collecting CVS rlog
+  6 log entries
+  creating changesets
+  3 changeset entries
+  ---------------------
+  PatchSet 1 
+  Date: * (glob)
+  Author: * (glob)
+  Branch: HEAD
+  Tag: (none) 
+  Branchpoints: v0 
+  Log:
+  Initial revision
+  
+  Members: 
+  	a:INITIAL->1.1 
+  	b:INITIAL->1.1 
+  
+  ---------------------
+  PatchSet 2 
+  Date: * (glob)
+  Author: * (glob)
+  Branch: v0
+  Tag: r0 
+  Log:
+  init
+  
+  Members: 
+  	a:1.1->1.1.1.1 
+  	b:1.1->1.1.1.1 
+  
+  ---------------------
+  PatchSet 3 
+  Date: * (glob)
+  Author: * (glob)
+  Branch: HEAD
+  Tag: (none) 
+  Log:
+  update
+  
+  Members: 
+  	a:1.1->1.2 
+  	b:1.1->1.2(DEAD) 
+