]> arthur.barton.de Git - bup.git/commitdiff
Remove useless code in main.py around the -d option
authorGabriel Filion <lelutin@gmail.com>
Sat, 28 Jul 2012 04:54:12 +0000 (00:54 -0400)
committerRob Browning <rlb@defaultvalue.org>
Fri, 17 Aug 2012 18:42:59 +0000 (13:42 -0500)
While debugging another problem with BUP_DIR, I saw a part of the
code that looked kinda suspicious (not in itself, but in the context of
the file):

  115 subcmd_env = os.environ
  116 if dest_dir:
  117     subcmd_env.update({"BUP_DIR" : dest_dir})

the subcmd_env variable is never used in main.py. However, when I
removed that part, the -d option stopped working and bup used ~/.bup
instead: so it _is_ doing what we want it to.

The reason why it's working is that line 115 is actually not creating a
copy of the dict, but rather simply pointing to the same dict. so the
call to update() actually changes the environment for the main program,
which is actually quite alright (e.g. it supercedes the environment
variable and ensures that the path given to -d is inherited into
subprocesses)

Now the problem is that this code is very not obvious about what it
does. Plus, it's a couple of useless lines that we need to maintain.
Let's just remove any extraneous work and make the addition to the
environment triggered by the -d option as obvious and concise as
possible.

Signed-off-by: Gabriel Filion <lelutin@gmail.com>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
main.py

diff --git a/main.py b/main.py
index 5229b26273a1f4dcecafa518f9e87c65be7b6a10..67ad0119c393255e9d0771b0d6833fef6e88c7f6 100755 (executable)
--- a/main.py
+++ b/main.py
@@ -78,7 +78,6 @@ except getopt.GetoptError, ex:
     usage('error: %s' % ex.msg)
 
 help_requested = None
-dest_dir = None
 do_profile = False
 
 for opt in global_args:
@@ -92,7 +91,7 @@ for opt in global_args:
     elif opt[0] in ['--profile']:
         do_profile = True
     elif opt[0] in ['-d', '--bup-dir']:
-        dest_dir = opt[1]
+        os.environ['BUP_DIR'] = opt[1]
     else:
         usage('error: unexpected option "%s"' % opt[0])
 
@@ -112,10 +111,6 @@ subcmd_name = subcmd[0]
 if not subcmd_name:
     usage()
 
-subcmd_env = os.environ
-if dest_dir:
-    subcmd_env.update({"BUP_DIR" : dest_dir})
-
 def subpath(s):
     sp = os.path.join(exepath, 'bup-%s' % s)
     if not os.path.exists(sp):