You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Max Bowsher <ma...@ukf.net> on 2003/08/23 10:41:09 UTC

[PATCH] [cvs2svn] Code cleanup - eliminate duplicate code

* tools/cvs2svn/cvs2svn.py (RepositoryMirror.delete_path):
    Restructure "if" statement to eliminate duplicate code.

Index: cvs2svn.py
===================================================================
--- cvs2svn.py (revision 6839)
+++ cvs2svn.py (working copy)
@@ -798,26 +798,18 @@
     for parent_item in parent_chain:
       pkey = parent_item[1]
       pval = marshal.loads(self.nodes_db[pkey])
-      if prune:
-        if (new_key == None) and is_prunable(pval):
-          pruned_count = pruned_count + 1
-          pass
-          # Do nothing more.  All the action takes place when we hit a
-          # non-prunable parent.
-        else:
-          # We hit a non-prunable, so bubble up the new gospel.
-          pval[self.mutable_flag] = 1
-          if new_key == None:
-            del pval[prev_entry_name]
-          else:
-            pval[prev_entry_name] = new_key
-          new_key = gen_key()
+      if prune and (new_key == None) and is_prunable(pval):
+        pruned_count = pruned_count + 1
+        pass
+        # Do nothing more.  All the action takes place when we hit a
+        # non-prunable parent.
       else:
+        # We hit a non-prunable, or aren't pruning, so bubble up the new
gospel.
         pval[self.mutable_flag] = 1
-        if new_key:
+        if new_key == None:
+          del pval[prev_entry_name]
+        else:
           pval[prev_entry_name] = new_key
-        else:
-          del pval[prev_entry_name]
         new_key = gen_key()

       prev_entry_name = parent_item[0]


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] [cvs2svn] Code cleanup - eliminate duplicate code

Posted by Sander Roobol <ph...@wanadoo.nl>.
On Sat, Aug 23, 2003 at 11:41:09AM +0100, Max Bowsher wrote:
> * tools/cvs2svn/cvs2svn.py (RepositoryMirror.delete_path):
>     Restructure "if" statement to eliminate duplicate code.

I've filed this patch together with your other cvs2svn code cleanup
patch as issue #1500:
  http://subversion.tigris.org/issues/show_bug.cgi?id=1500

Sander
  

> 
> Index: cvs2svn.py
> ===================================================================
> --- cvs2svn.py (revision 6839)
> +++ cvs2svn.py (working copy)
> @@ -798,26 +798,18 @@
>      for parent_item in parent_chain:
>        pkey = parent_item[1]
>        pval = marshal.loads(self.nodes_db[pkey])
> -      if prune:
> -        if (new_key == None) and is_prunable(pval):
> -          pruned_count = pruned_count + 1
> -          pass
> -          # Do nothing more.  All the action takes place when we hit a
> -          # non-prunable parent.
> -        else:
> -          # We hit a non-prunable, so bubble up the new gospel.
> -          pval[self.mutable_flag] = 1
> -          if new_key == None:
> -            del pval[prev_entry_name]
> -          else:
> -            pval[prev_entry_name] = new_key
> -          new_key = gen_key()
> +      if prune and (new_key == None) and is_prunable(pval):
> +        pruned_count = pruned_count + 1
> +        pass
> +        # Do nothing more.  All the action takes place when we hit a
> +        # non-prunable parent.
>        else:
> +        # We hit a non-prunable, or aren't pruning, so bubble up the new
> gospel.
>          pval[self.mutable_flag] = 1
> -        if new_key:
> +        if new_key == None:
> +          del pval[prev_entry_name]
> +        else:
>            pval[prev_entry_name] = new_key
> -        else:
> -          del pval[prev_entry_name]
>          new_key = gen_key()
> 
>        prev_entry_name = parent_item[0]
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
> For additional commands, e-mail: dev-help@subversion.tigris.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] [cvs2svn] Code cleanup - eliminate duplicate code

Posted by Gareth McCaughan <ga...@pobox.com>.
On Tuesday 26 August 2003 12:26 pm, Michael Wood wrote:

> > > Shouldn't that be "if new_key is None:"?
> >
> > Does it make any difference?
>
> Well, in general, "==" is not the same as "is".
>
> > I don't think it does.
>
> You're probably right.

"is" is more idiomatic when comparing with None, and
marginally faster. "x is None" and "x == None" aren't
quite equivalent, because x may be an object of a
user-defined class that redefines the behaviour of ==.
It isn't possible to redefine the behaviour of "is".
(That's one reason why using "is" will be faster.)

-- 
Gareth McCaughan


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] [cvs2svn] Code cleanup - eliminate duplicate code

Posted by Michael Wood <mw...@its.uct.ac.za>.
On Mon, Aug 25, 2003 at 05:50:48PM +0100, Max Bowsher wrote:
> Michael Wood wrote:
> > On Sat, Aug 23, 2003 at 11:41:09AM +0100, Max Bowsher wrote:
> >> * tools/cvs2svn/cvs2svn.py (RepositoryMirror.delete_path):
> >>     Restructure "if" statement to eliminate duplicate code.
> >> 
> >> Index: cvs2svn.py
> >> ===================================================================
> >> [snip] -        if new_key:
> >> +        if new_key == None:
> > 
> > Shouldn't that be "if new_key is None:"?
> 
> Does it make any difference?

Well, in general, "==" is not the same as "is".

> I don't think it does.

You're probably right.

-- 
Michael Wood <mw...@its.uct.ac.za>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] [cvs2svn] Code cleanup - eliminate duplicate code

Posted by Max Bowsher <ma...@ukf.net>.
Michael Wood wrote:
> On Sat, Aug 23, 2003 at 11:41:09AM +0100, Max Bowsher wrote:
>> * tools/cvs2svn/cvs2svn.py (RepositoryMirror.delete_path):
>>     Restructure "if" statement to eliminate duplicate code.
>> 
>> Index: cvs2svn.py
>> ===================================================================
>> [snip] -        if new_key:
>> +        if new_key == None:
> 
> Shouldn't that be "if new_key is None:"?

Does it make any difference?

I don't think it does.

Max.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] [cvs2svn] Code cleanup - eliminate duplicate code

Posted by Michael Wood <mw...@its.uct.ac.za>.
On Sat, Aug 23, 2003 at 11:41:09AM +0100, Max Bowsher wrote:
> * tools/cvs2svn/cvs2svn.py (RepositoryMirror.delete_path):
>     Restructure "if" statement to eliminate duplicate code.
> 
> Index: cvs2svn.py
> ===================================================================
[snip]
> -        if new_key:
> +        if new_key == None:

Shouldn't that be "if new_key is None:"?

-- 
Michael Wood <mw...@its.uct.ac.za>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org