Patchwork [evolve-ext-V4] evolve: add new methods _evolvestatewrite, _evolvestateread, _evolvestatedelete

login
register
mail settings
Submitter Shusen LIU
Date Jan. 20, 2016, 11:22 p.m.
Message ID <8057f7ade74eb66cf97e.1453332152@dev1221.lla1.facebook.com>
Download mbox | patch
Permalink /patch/12853/
State Changes Requested
Delegated to: Pierre-Yves David
Headers show

Comments

Shusen LIU - Jan. 20, 2016, 11:22 p.m.
# HG changeset patch
# User Shusen LIU <liushusen@fb.com>
# Date 1453329104 28800
#      Wed Jan 20 14:31:44 2016 -0800
# Node ID 8057f7ade74eb66cf97eb177b84785c995dfd0c8
# Parent  91e67ad4cb6c783fa1a32e03359aa6d73c765129
evolve: add new methods _evolvestatewrite, _evolvestateread, _evolvestatedelete

This patch introduces three new methods to read/write/delete data in vfs file
'evolvestate'. Provide the first version of impl of these methods, the
_fm0evolvestateversion = 0.
This enable us to persist evolvestate data, restore evolvestate data, and
delete it after it's no longer needed. And allows us to support a continued
keywork to implement evolve state.
Pierre-Yves David - Jan. 22, 2016, 6:51 p.m.
This is the second V4, is that a V5 ?

On 01/20/2016 03:22 PM, Shusen LIU wrote:
> # HG changeset patch
> # User Shusen LIU <liushusen@fb.com>
> # Date 1453329104 28800
> #      Wed Jan 20 14:31:44 2016 -0800
> # Node ID 8057f7ade74eb66cf97eb177b84785c995dfd0c8
> # Parent  91e67ad4cb6c783fa1a32e03359aa6d73c765129
> evolve: add new methods _evolvestatewrite, _evolvestateread, _evolvestatedelete
>
> This patch introduces three new methods to read/write/delete data in vfs file
> 'evolvestate'. Provide the first version of impl of these methods, the
> _fm0evolvestateversion = 0.
> This enable us to persist evolvestate data, restore evolvestate data, and
> delete it after it's no longer needed. And allows us to support a continued
> keywork to implement evolve state.
>
> diff --git a/hgext/evolve.py b/hgext/evolve.py
> --- a/hgext/evolve.py
> +++ b/hgext/evolve.py
> @@ -67,6 +67,7 @@
>   import collections
>   import socket
>   import errno
> +import json
>   sha1re = re.compile(r'\b[0-9a-f]{6,40}\b')
>
>   import mercurial
> @@ -3723,3 +3724,40 @@
>           repo._bookmarks[book] = dest.node()
>       if oldbookmarks or destbookmarks:
>           repo._bookmarks.recordchange(tr)
> +
> +## Parsing and writing of version "0"
> +#
> +# The file contains two line.
> +# First line is the version number.
> +# Second line is the the data in json format
> +
> +_fm0evolvestateversion = 0
> +
> +def _fm0evolvestateread(repo):
> +    serialized_data = repo.vfs.read('evolvestate').split('\n')[1]
> +    data = dict([(str(k), str(v))
> +                 for k,v in json.loads(serialized_data).iteritems()])
> +    return data
> +
> +def _fm0evolvestatewrite(repo, data):
> +    serialized_data = json.dumps(data)
> +    repo.vfs.write('evolvestate',
> +                   '\n'.join([str(_fm0evolvestateversion), serialized_data]))
> +
> +# mapping to read/write various evolvestate formats
> +# <version> -> (reader, writer)
> +formats = {_fm0evolvestateversion: (_fm0evolvestateread, _fm0evolvestatewrite),}
> +defaultversion = _fm0evolvestateversion
> +
> +def _evolvestatewrite(repo, data, version=defaultversion):
> +    formats[version][1](repo, data)
> +
> +def _evolvestateread(repo):
> +    diskversion = int(repo.vfs.read('evolvestate').split('\n')[0])
> +    if diskversion not in formats:
> +        raise error.Abort(_('parsing evolvestate: unknown version %r')
> +                         % diskversion)
> +    return formats[diskversion][0](repo)
> +
> +def _evolvestatedelete(repo):
> +    util.unlinkpath(repo.join('evolvestate'), ignoremissing=True)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel
>
Shusen LIU - Jan. 24, 2016, 11:57 p.m.
This is actually V5, sorry for wrong version number.



On 1/22/16, 18:51, "Pierre-Yves David" <pierre-yves.david@ens-lyon.org> wrote:

>This is the second V4, is that a V5 ?

>

>On 01/20/2016 03:22 PM, Shusen LIU wrote:

>> # HG changeset patch

>> # User Shusen LIU <liushusen@fb.com>

>> # Date 1453329104 28800

>> #      Wed Jan 20 14:31:44 2016 -0800

>> # Node ID 8057f7ade74eb66cf97eb177b84785c995dfd0c8

>> # Parent  91e67ad4cb6c783fa1a32e03359aa6d73c765129

>> evolve: add new methods _evolvestatewrite, _evolvestateread, _evolvestatedelete

>>

>> This patch introduces three new methods to read/write/delete data in vfs file

>> 'evolvestate'. Provide the first version of impl of these methods, the

>> _fm0evolvestateversion = 0.

>> This enable us to persist evolvestate data, restore evolvestate data, and

>> delete it after it's no longer needed. And allows us to support a continued

>> keywork to implement evolve state.

>>

>> diff --git a/hgext/evolve.py b/hgext/evolve.py

>> --- a/hgext/evolve.py

>> +++ b/hgext/evolve.py

>> @@ -67,6 +67,7 @@

>>   import collections

>>   import socket

>>   import errno

>> +import json

>>   sha1re = re.compile(r'\b[0-9a-f]{6,40}\b')

>>

>>   import mercurial

>> @@ -3723,3 +3724,40 @@

>>           repo._bookmarks[book] = dest.node()

>>       if oldbookmarks or destbookmarks:

>>           repo._bookmarks.recordchange(tr)

>> +

>> +## Parsing and writing of version "0"

>> +#

>> +# The file contains two line.

>> +# First line is the version number.

>> +# Second line is the the data in json format

>> +

>> +_fm0evolvestateversion = 0

>> +

>> +def _fm0evolvestateread(repo):

>> +    serialized_data = repo.vfs.read('evolvestate').split('\n')[1]

>> +    data = dict([(str(k), str(v))

>> +                 for k,v in json.loads(serialized_data).iteritems()])

>> +    return data

>> +

>> +def _fm0evolvestatewrite(repo, data):

>> +    serialized_data = json.dumps(data)

>> +    repo.vfs.write('evolvestate',

>> +                   '\n'.join([str(_fm0evolvestateversion), serialized_data]))

>> +

>> +# mapping to read/write various evolvestate formats

>> +# <version> -> (reader, writer)

>> +formats = {_fm0evolvestateversion: (_fm0evolvestateread, _fm0evolvestatewrite),}

>> +defaultversion = _fm0evolvestateversion

>> +

>> +def _evolvestatewrite(repo, data, version=defaultversion):

>> +    formats[version][1](repo, data)

>> +

>> +def _evolvestateread(repo):

>> +    diskversion = int(repo.vfs.read('evolvestate').split('\n')[0])

>> +    if diskversion not in formats:

>> +        raise error.Abort(_('parsing evolvestate: unknown version %r')

>> +                         % diskversion)

>> +    return formats[diskversion][0](repo)

>> +

>> +def _evolvestatedelete(repo):

>> +    util.unlinkpath(repo.join('evolvestate'), ignoremissing=True)

>> _______________________________________________

>> Mercurial-devel mailing list

>> Mercurial-devel@selenic.com

>> https://selenic.com/mailman/listinfo/mercurial-devel

>>

>

>-- 

>Pierre-Yves David

Patch

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -67,6 +67,7 @@ 
 import collections
 import socket
 import errno
+import json
 sha1re = re.compile(r'\b[0-9a-f]{6,40}\b')
 
 import mercurial
@@ -3723,3 +3724,40 @@ 
         repo._bookmarks[book] = dest.node()
     if oldbookmarks or destbookmarks:
         repo._bookmarks.recordchange(tr)
+
+## Parsing and writing of version "0"
+#
+# The file contains two line.
+# First line is the version number.
+# Second line is the the data in json format
+
+_fm0evolvestateversion = 0
+
+def _fm0evolvestateread(repo):
+    serialized_data = repo.vfs.read('evolvestate').split('\n')[1]
+    data = dict([(str(k), str(v))
+                 for k,v in json.loads(serialized_data).iteritems()])
+    return data
+
+def _fm0evolvestatewrite(repo, data):
+    serialized_data = json.dumps(data)
+    repo.vfs.write('evolvestate',
+                   '\n'.join([str(_fm0evolvestateversion), serialized_data]))
+
+# mapping to read/write various evolvestate formats
+# <version> -> (reader, writer)
+formats = {_fm0evolvestateversion: (_fm0evolvestateread, _fm0evolvestatewrite),}
+defaultversion = _fm0evolvestateversion
+
+def _evolvestatewrite(repo, data, version=defaultversion):
+    formats[version][1](repo, data)
+
+def _evolvestateread(repo):
+    diskversion = int(repo.vfs.read('evolvestate').split('\n')[0])
+    if diskversion not in formats:
+        raise error.Abort(_('parsing evolvestate: unknown version %r')
+                         % diskversion)
+    return formats[diskversion][0](repo)
+
+def _evolvestatedelete(repo):
+    util.unlinkpath(repo.join('evolvestate'), ignoremissing=True)