Patchwork [1,of,3,stable] util.url: add an 'islocal' method

login
register
mail settings
Submitter Siddharth Agarwal
Date Feb. 3, 2014, 11:12 p.m.
Message ID <8ab8a85a22c2f5a0e23e.1391469131@dev998.prn1.facebook.com>
Download mbox | patch
Permalink /patch/3450/
State Accepted
Commit 0889585b44f12f6f54ae33d758b8c51c4f424ed7
Headers show

Comments

Siddharth Agarwal - Feb. 3, 2014, 11:12 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1391467661 28800
#      Mon Feb 03 14:47:41 2014 -0800
# Branch stable
# Node ID 8ab8a85a22c2f5a0e23e86f2041ef7d348fab857
# Parent  9139dedeffa6d54367fcf410d583d401e8fd1318
util.url: add an 'islocal' method

This returns True if the URL represents a path that can be opened locally,
without needing to go through the entire URL open mechanism.
Siddharth Agarwal - Feb. 3, 2014, 11:21 p.m.
On 02/03/2014 03:12 PM, Siddharth Agarwal wrote:
> # HG changeset patch
> # User Siddharth Agarwal <sid0@fb.com>
> # Date 1391467661 28800
> #      Mon Feb 03 14:47:41 2014 -0800
> # Branch stable
> # Node ID 8ab8a85a22c2f5a0e23e86f2041ef7d348fab857
> # Parent  9139dedeffa6d54367fcf410d583d401e8fd1318
> util.url: add an 'islocal' method
>
> This returns True if the URL represents a path that can be opened locally,
> without needing to go through the entire URL open mechanism.

Of course, this now raises the question whether url.open should do this 
detection. Is it ever desirable for url.open to not use posixfile directly?
Matt Mackall - Feb. 3, 2014, 11:24 p.m.
On Mon, 2014-02-03 at 15:21 -0800, Siddharth Agarwal wrote:
> On 02/03/2014 03:12 PM, Siddharth Agarwal wrote:
> > # HG changeset patch
> > # User Siddharth Agarwal <sid0@fb.com>
> > # Date 1391467661 28800
> > #      Mon Feb 03 14:47:41 2014 -0800
> > # Branch stable
> > # Node ID 8ab8a85a22c2f5a0e23e86f2041ef7d348fab857
> > # Parent  9139dedeffa6d54367fcf410d583d401e8fd1318
> > util.url: add an 'islocal' method
> >
> > This returns True if the URL represents a path that can be opened locally,
> > without needing to go through the entire URL open mechanism.
> 
> Of course, this now raises the question whether url.open should do this 
> detection. Is it ever desirable for url.open to not use posixfile directly?

Not that I know of.. sounds like a good follow-up.

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1875,6 +1875,11 @@ 
             return path
         return self._origpath
 
+    def islocal(self):
+        '''whether localpath will return something that posixfile can open'''
+        return (not self.scheme or self.scheme == 'file'
+                or self.scheme == 'bundle')
+
 def hasscheme(path):
     return bool(url(path).scheme)