[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: svn commit: r18618 - trunk/contrib/client-side

From: Daniel Rall <dlr_at_collab.net>
Date: 2006-02-27 17:40:53 CET

On Fri, 24 Feb 2006, blair@tigris.org wrote:
...
> --- trunk/contrib/client-side/svnmerge.py (original)
> +++ trunk/contrib/client-side/svnmerge.py Fri Feb 24 17:49:01 2006
> @@ -435,7 +435,13 @@
>
> def is_wc(dir):
> """Check if a directory is a working copy."""
> - return os.path.isdir(dir) and os.path.isdir(os.path.join(dir, ".svn"))
> + if not os.path.isdir(dir):
> + return False

Blair, this initial check is unecessary, and results in an extra stat
when the parent directory is present:

  $ strace python -c 'import os; os.path.isdir("/etc") and os.path.isdir("/etc/hosts")' 2>&1 | grep etc | grep stat
  stat64("/etc", {st_mode=S_IFDIR|0755, st_size=12288, ...}) = 0
  stat64("/etc/hosts", {st_mode=S_IFREG|0644, st_size=191, ...}) = 0
  $ strace python -c 'import os; os.path.isdir("/etc/hosts")' 2>&1 | grep etc | grep stat
  stat64("/etc/hosts", {st_mode=S_IFREG|0644, st_size=191, ...}) = 0

> + if os.path.isdir(os.path.join(dir, ".svn")):
> + return True
> + if os.path.isdir(os.path.join(dir, "_svn")):
> + return True
> + return False
>
> _cache_svninfo = {}
> def get_svninfo(path):

An os.path.join() call is generally cheaper than that initial stat.
How about:

Index: svnmerge.py
===================================================================
--- svnmerge.py (revision 18629)
+++ svnmerge.py (working copy)
@@ -435,13 +435,8 @@
 
 def is_wc(dir):
     """Check if a directory is a working copy."""
- if not os.path.isdir(dir):
- return False
- if os.path.isdir(os.path.join(dir, ".svn")):
- return True
- if os.path.isdir(os.path.join(dir, "_svn")):
- return True
- return False
+ return os.path.isdir(os.path.join(dir, ".svn")) or \
+ os.path.isdir(os.path.join(dir, "_svn"))
 
 _cache_svninfo = {}
 def get_svninfo(path):

-- 
Daniel Rall

  • application/pgp-signature attachment: stored
Received on Mon Feb 27 19:55:50 2006

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.