Submitter | Katsunori FUJIWARA |
---|---|
Date | May 28, 2014, 3 p.m. |
Message ID | <7a947a99d8c7313cdf49.1401289216@juju> |
Download | mbox | patch |
Permalink | /patch/4888/ |
State | Changes Requested |
Headers | show |
Comments
On Thu, 2014-05-29 at 00:00 +0900, FUJIWARA Katsunori wrote: > # HG changeset patch > # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp> > # Date 1401288802 -32400 > # Wed May 28 23:53:22 2014 +0900 > # Node ID 7a947a99d8c7313cdf49d474bdba2e9d97298556 > # Parent 7ece02ee1e7207b7894a665d0b42f807243a6ba6 > vfs: introduce "readlines" and "tryreadlines" > > This patch allows "readlines" and "tryreadlines" to take "mode" > argument, because "subrepo" requires to read files not in "rb" > (binary, default for vfs) but in "r" (text) mode in the succeeding > patch. Is there a reason you think that's not a bug in subrepo?
At Fri, 11 Jul 2014 17:14:30 -0500, Matt Mackall wrote: > > On Thu, 2014-05-29 at 00:00 +0900, FUJIWARA Katsunori wrote: > > # HG changeset patch > > # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp> > > # Date 1401288802 -32400 > > # Wed May 28 23:53:22 2014 +0900 > > # Node ID 7a947a99d8c7313cdf49d474bdba2e9d97298556 > > # Parent 7ece02ee1e7207b7894a665d0b42f807243a6ba6 > > vfs: introduce "readlines" and "tryreadlines" > > > > This patch allows "readlines" and "tryreadlines" to take "mode" > > argument, because "subrepo" requires to read files not in "rb" > > (binary, default for vfs) but in "r" (text) mode in the succeeding > > patch. > > Is there a reason you think that's not a bug in subrepo? I also thought that cache files of subrepo storehash might have to be opened in binary mode, because I couldn't find any reasons that they are opened in text mode. But I chose the way to open them in text mode, because: - changing the mode to open them seems to be out of scope of vfs migration - opening them in text mode is easy to keep backward compatibility Of course, keeping backward compatibility for them may not be so important, because: - they are just cache (not permanent information) - they don't cause incorrect behavior (even though redundant queries may decrease performance) - switching new/old "hg" command frequently in the same working directory is rare case Do I have to change the mode to open storehash files ? and if so, do I have to keep backward compatibility with old 'hg' command or not ? ---------------------------------------------------------------------- [FUJIWARA Katsunori] foozy@lares.dti.ne.jp
Patch
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -135,6 +135,15 @@ class abstractvfs(object): raise return "" + def tryreadlines(self, path, mode='rb'): + '''gracefully return an empty array for missing files''' + try: + return self.readlines(path, mode=mode) + except IOError, inst: + if inst.errno != errno.ENOENT: + raise + return [] + def open(self, path, mode="r", text=False, atomictemp=False): self.open = self.__call__ return self.__call__(path, mode, text, atomictemp) @@ -146,6 +155,13 @@ class abstractvfs(object): finally: fp.close() + def readlines(self, path, mode='rb'): + fp = self(path, mode=mode) + try: + return fp.readlines() + finally: + fp.close() + def write(self, path, data): fp = self(path, 'wb') try: