D3572: state: don't have a dict like interface for cmdstate class

2018-05-21 Thread pulkit (Pulkit Goyal)
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG36a5a1239a15: state: dont have a dict like interface 
for cmdstate class (authored by pulkit, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3572?vs=8732=8851

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

AFFECTED FILES
  mercurial/state.py

CHANGE DETAILS

diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -46,31 +46,12 @@
 """
 self._repo = repo
 self.fname = fname
-if not opts:
-self.opts = {}
-else:
-self.opts = opts
-
-def __nonzero__(self):
-return self.exists()
-
-def __getitem__(self, key):
-return self.opts[key]
 
-def __setitem__(self, key, value):
-updates = {key: value}
-self.opts.update(updates)
+def read(self):
+"""read the existing state file and return a dict of data stored"""
+return self._read()
 
-def load(self):
-"""load the existing state file into the class object"""
-op = self._read()
-self.opts.update(op)
-
-def addopts(self, opts):
-"""add more key-value pairs to the data stored by the object"""
-self.opts.update(opts)
-
-def save(self):
+def save(self, data):
 """write all the state data stored to .hg/ file
 
 we use third-party library cbor to serialize data to write in the file.



To: pulkit, #hg-reviewers, martinvonz
Cc: martinvonz, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3572: state: don't have a dict like interface for cmdstate class

2018-05-18 Thread pulkit (Pulkit Goyal)
pulkit updated this revision to Diff 8732.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3572?vs=8721=8732

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

AFFECTED FILES
  mercurial/state.py

CHANGE DETAILS

diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -46,31 +46,12 @@
 """
 self._repo = repo
 self.fname = fname
-if not opts:
-self.opts = {}
-else:
-self.opts = opts
-
-def __nonzero__(self):
-return self.exists()
-
-def __getitem__(self, key):
-return self.opts[key]
 
-def __setitem__(self, key, value):
-updates = {key: value}
-self.opts.update(updates)
+def read(self):
+"""read the existing state file and return a dict of data stored"""
+return self._read()
 
-def load(self):
-"""load the existing state file into the class object"""
-op = self._read()
-self.opts.update(op)
-
-def addopts(self, opts):
-"""add more key-value pairs to the data stored by the object"""
-self.opts.update(opts)
-
-def save(self):
+def save(self, data):
 """write all the state data stored to .hg/ file
 
 we use third-party library cbor to serialize data to write in the file.



To: pulkit, #hg-reviewers
Cc: martinvonz, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3572: state: don't have a dict like interface for cmdstate class

2018-05-17 Thread pulkit (Pulkit Goyal)
pulkit added inline comments.

INLINE COMMENTS

> martinvonz wrote in state.py:59-63
> Is this a direct consequence of removing the dict interface or could it be 
> split out into a separate patch?

I will split it into a separate patch.

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers
Cc: martinvonz, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3572: state: don't have a dict like interface for cmdstate class

2018-05-17 Thread martinvonz (Martin von Zweigbergk)
martinvonz added inline comments.

INLINE COMMENTS

> state.py:59-63
> +try:
> +iv = int(version)
> +except ValueError:
> +raise error.ProgrammingError("version of state file should be"
> + " an integer")

Is this a direct consequence of removing the dict interface or could it be 
split out into a separate patch?

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers
Cc: martinvonz, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3572: state: don't have a dict like interface for cmdstate class

2018-05-17 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This patch changes the cmdstate class to stop having a dict like interface and
  delete the __nonzero__ function. After this patch, the save fuction takes a 
dict
  to store the data and read function returns a dict of the data stored.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/state.py

CHANGE DETAILS

diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -46,42 +46,35 @@
 """
 self._repo = repo
 self.fname = fname
-if not opts:
-self.opts = {}
-else:
-self.opts = opts
-
-def __nonzero__(self):
-return self.exists()
-
-def __getitem__(self, key):
-return self.opts[key]
 
-def __setitem__(self, key, value):
-updates = {key: value}
-self.opts.update(updates)
+def read(self):
+"""read the existing state file and return a dict of data stored"""
+return self._read()
 
-def load(self):
-"""load the existing state file into the class object"""
-op = self._read()
-self.opts.update(op)
-
-def addopts(self, opts):
-"""add more key-value pairs to the data stored by the object"""
-self.opts.update(opts)
-
-def save(self):
+def save(self, version, data):
 """write all the state data stored to .hg/ file
 
 we use third-party library cbor to serialize data to write in the file.
 """
+try:
+iv = int(version)
+except ValueError:
+raise error.ProgrammingError("version of state file should be"
+ " an integer")
+
 with self._repo.vfs(self.fname, 'wb', atomictemp=True) as fp:
+fp.write('%d\n' % iv)
 cbor.dump(self.opts, fp)
 
 def _read(self):
 """reads the state file and returns a dictionary which contain
 data in the same format as it was before storing"""
 with self._repo.vfs(self.fname, 'rb') as fp:
+try:
+version = int(fp.readline())
+except ValueError:
+raise error.ProgrammingError("unknown version of state file"
+ " found")
 return cbor.load(fp)
 
 def delete(self):



To: pulkit, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel