]> arthur.barton.de Git - bup.git/commitdiff
Merge branch 'next' into 'master'
authorAvery Pennarun <apenwarr@gmail.com>
Sat, 8 Jan 2011 09:59:55 +0000 (01:59 -0800)
committerAvery Pennarun <apenwarr@gmail.com>
Sat, 8 Jan 2011 10:01:03 +0000 (02:01 -0800)
* 'next':
  Change server_mode=='dumb' to just a dumb_server_mode bool.
  Teach bup about URLs and non-ssh remotes
  Don't generate midx files in dumb server mode
  Add optional dumb-server mode
  git.CatPipe: set a buffer size on the subprocess to increase performance.
  Improve test pass condition
  Adds examples for strip, strip-prefix and graft to bup save's documentation
  Adds --graft option to bup save.

Conflicts:
lib/bup/t/thelpers.py

1  2 
lib/bup/helpers.py
lib/bup/t/thelpers.py

index 7c11a927ad2a776298c58abf6c39f2778eff4e2c,ae3b1cbd8064e9c927201e961f23c181397e3bad..a5b12e091259cb5fb5b75e5230578f96a1e74651
@@@ -438,13 -440,20 +440,21 @@@ def strip_base_path(path, base_paths)
      Iterates over all base_paths from long to short, to prevent that
      a too short base_path is removed.
      """
 +    normalized_path = os.path.realpath(path)
      sorted_base_paths = sorted(base_paths, key=len, reverse=True)
      for bp in sorted_base_paths:
 -        if path.startswith(realpath(bp)):
 -            return strip_path(bp, path)
 +        if normalized_path.startswith(os.path.realpath(bp)):
 +            return strip_path(bp, normalized_path)
      return path
  
 -    normalized_path = realpath(path)
+ def graft_path(graft_points, path):
++    normalized_path = os.path.realpath(path)
+     for graft_point in graft_points:
+         old_prefix, new_prefix = graft_point
+         if normalized_path.startswith(old_prefix):
+             return re.sub(r'^' + old_prefix, new_prefix, normalized_path)
+     return normalized_path
  
  # hashlib is only available in python 2.5 or higher, but the 'sha' module
  # produces a DeprecationWarning in python 2.6 or higher.  We want to support
index ebb80f8ec17af8c58fb363fff4fb90c0fe46cb9d,17f6bcdbab2bb5e8b88ea7ee4a08203db3390d8b..89cccdaebad7214472c319e6206eb6854b209385
@@@ -30,24 -29,25 +30,46 @@@ def test_strip_base_path()
      base_paths = ["/var", "/var/backup", "/var/backup/daily.0/localhost"]
      WVPASSEQ(strip_base_path(path, base_paths), '/etc')
  
 +@wvtest
 +def test_strip_symlinked_base_path():
 +    tmpdir = os.path.join(os.getcwd(),"test_strip_symlinked_base_path.tmp")
 +    symlink_src = os.path.join(tmpdir, "private", "var")
 +    symlink_dst = os.path.join(tmpdir, "var")
 +    path = os.path.join(symlink_dst, "a")
 +
 +    os.mkdir(tmpdir)
 +    os.mkdir(os.path.join(tmpdir, "private"))
 +    os.mkdir(symlink_src)
 +    os.symlink(symlink_src, symlink_dst)
 +
 +    result = strip_base_path(path, [symlink_dst])
 +
 +    os.remove(symlink_dst)
 +    os.rmdir(symlink_src)
 +    os.rmdir(os.path.join(tmpdir, "private"))
 +    os.rmdir(tmpdir)
 +
 +    WVPASSEQ(result, "/a")
 +
+ @wvtest
+ def test_graft_path():
+     middle_matching_old_path = "/user"
+     non_matching_old_path = "/usr"
+     matching_old_path = "/home"
+     matching_full_path = "/home/user"
+     new_path = "/opt"
+     all_graft_points = [(middle_matching_old_path, new_path),
+                         (non_matching_old_path, new_path),
+                         (matching_old_path, new_path)]
+     path = "/home/user/"
+     WVPASSEQ(graft_path([(middle_matching_old_path, new_path)], path),
+                         "/home/user")
+     WVPASSEQ(graft_path([(non_matching_old_path, new_path)], path),
+                         "/home/user")
+     WVPASSEQ(graft_path([(matching_old_path, new_path)], path), "/opt/user")
+     WVPASSEQ(graft_path(all_graft_points, path), "/opt/user")
+     WVPASSEQ(graft_path([(matching_full_path, new_path)], path),
+                         "/opt")