/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/treeshape.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-09-14 22:58:47 UTC
  • mfrom: (7104.3.4 brz-git-renames)
  • Revision ID: breezy.the.bot@gmail.com-20180914225847-0qnfeylaf94259b0
Some refactoring around get_canonical_inventory_paths.

* Drop the 'inventory' bit since it doesn't apply to non-inventory trees
* Move to working trees; canonicalization currently only matters there, where
  files can be stored on case-insensitive (VFAT) or normalizing filesystems
  (i.e. Mac OS X)
* Run tests against all working tree formats, including Git, not just InventoryTree ones

This fixes 'bzr mv' and 'bzr rename' for Git.

Merged from https://code.launchpad.net/~jelmer/brz/brz-git-renames/+merge/354952

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005, 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
30
30
import os
31
31
import stat
32
32
 
33
 
from bzrlib.trace import warning
34
 
from bzrlib.osutils import pathjoin
 
33
from ..trace import warning
 
34
from ..osutils import pathjoin
35
35
 
36
36
def build_tree_contents(template):
37
37
    """Reconstitute some files from a text description.
41
41
 
42
42
    The template is built relative to the Python process's current
43
43
    working directory.
 
44
 
 
45
    ('foo/',) will build a directory.
 
46
    ('foo', 'bar') will write 'bar' to 'foo'
 
47
    ('foo@', 'linktarget') will raise an error
44
48
    """
45
49
    for tt in template:
46
50
        name = tt[0]
47
51
        if name[-1] == '/':
48
52
            os.mkdir(name)
49
53
        elif name[-1] == '@':
50
 
            raise NotImplementedError('symlinks not handled yet')
 
54
            os.symlink(tt[1], tt[0][:-1])
51
55
        else:
52
 
            f = file(name, 'wb')
53
 
            try:
 
56
            with open(name, 'w' + ('b' if isinstance(tt[1], bytes) else '')) as f:
54
57
                f.write(tt[1])
55
 
            finally:
56
 
                f.close()
57
58
 
58
59
 
59
60
def capture_tree_contents(top):
71
72
            if stat.S_ISLNK(info.st_mode):
72
73
                yield (fullpath + '@', os.readlink(fullpath))
73
74
            elif stat.S_ISREG(info.st_mode):
74
 
                yield (fullpath, file(fullpath, 'rb').read())
 
75
                with open(fullpath, 'rb') as f:
 
76
                    file_bytes = f.read()
 
77
                yield (fullpath, file_bytes)
75
78
            else:
76
79
                warning("can't capture file %s with mode %#o",
77
80
                        fullpath, info.st_mode)