| 1 | # Copyright 2003 Dave Abrahams |
|---|
| 2 | # Copyright 2001, 2002 Vladimir Prus |
|---|
| 3 | # Distributed under the Boost Software License, Version 1.0. |
|---|
| 4 | # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 5 | |
|---|
| 6 | # This file is based in part on the content of svn_tree.py. |
|---|
| 7 | |
|---|
| 8 | import svn_tree; |
|---|
| 9 | |
|---|
| 10 | class Trees_difference: |
|---|
| 11 | |
|---|
| 12 | def __init__(self): |
|---|
| 13 | self.added_files = [] |
|---|
| 14 | self.removed_files = [] |
|---|
| 15 | self.modified_files = [] |
|---|
| 16 | self.touched_files = [] |
|---|
| 17 | |
|---|
| 18 | def append(self, other): |
|---|
| 19 | self.added_files.extend(other.added_files) |
|---|
| 20 | self.removed_files.extend(other.removed_files) |
|---|
| 21 | self.modified_files.extend(other.modified_files) |
|---|
| 22 | self.touched_files.extend(other.touched_files) |
|---|
| 23 | |
|---|
| 24 | def ignore_directories(self): |
|---|
| 25 | "Removes directories for list of found differences" |
|---|
| 26 | |
|---|
| 27 | def not_dir(x): |
|---|
| 28 | return x[-1] != "/" |
|---|
| 29 | self.added_files = filter(not_dir, self.added_files) |
|---|
| 30 | self.removed_files = filter(not_dir, self.removed_files) |
|---|
| 31 | self.modified_files = filter(not_dir, self.modified_files) |
|---|
| 32 | self.touched_files = filter(not_dir, self.touched_files) |
|---|
| 33 | |
|---|
| 34 | def pprint(self): |
|---|
| 35 | print "Added files :", self.added_files |
|---|
| 36 | print "Removed files :", self.removed_files |
|---|
| 37 | print "Modified files:", self.modified_files |
|---|
| 38 | print "Touched files :", self.touched_files |
|---|
| 39 | |
|---|
| 40 | def empty(self): |
|---|
| 41 | return (len(self.added_files) == 0 and len(self.removed_files) == 0)\ |
|---|
| 42 | and len(self.modified_files) == 0 and len(self.touched_files) == 0 |
|---|
| 43 | |
|---|
| 44 | def build_tree(dir): |
|---|
| 45 | return svn_tree.build_tree_from_wc(dir, load_props=0, ignore_svn=1) |
|---|
| 46 | |
|---|
| 47 | def trees_difference(a, b, current_name=""): |
|---|
| 48 | """Compare SVNTreeNodes A and B, and create Trees_difference class.""" |
|---|
| 49 | |
|---|
| 50 | assert a.name == b.name |
|---|
| 51 | |
|---|
| 52 | result = Trees_difference() |
|---|
| 53 | try: |
|---|
| 54 | # A and B are both files. |
|---|
| 55 | if ((a.children is None) and (b.children is None)): |
|---|
| 56 | assert a.name == b.name |
|---|
| 57 | if svn_tree.compare_file_nodes(a, b): |
|---|
| 58 | result.modified_files.append(current_name) |
|---|
| 59 | elif (a.mtime != b.mtime): |
|---|
| 60 | result.touched_files.append(current_name) |
|---|
| 61 | |
|---|
| 62 | # One is a file, one is a directory. |
|---|
| 63 | # this case is disabled because svn_tree doesn't distinguish |
|---|
| 64 | # empty directories from files, at least on Cygwin. |
|---|
| 65 | elif 0 and (((a.children is None) and (b.children is not None)) |
|---|
| 66 | or ((a.children is not None) and (b.children is None))): |
|---|
| 67 | a.pprint() |
|---|
| 68 | b.pprint() |
|---|
| 69 | raise svn_tree.SVNTypeMismatch |
|---|
| 70 | # They're both directories. |
|---|
| 71 | else: |
|---|
| 72 | # accounted_for holds childrens present in both trees |
|---|
| 73 | accounted_for = [] |
|---|
| 74 | for a_child in (a.children or []): |
|---|
| 75 | b_child = svn_tree.get_child(b, a_child.name) |
|---|
| 76 | if b_child: |
|---|
| 77 | accounted_for.append(b_child) |
|---|
| 78 | if current_name: |
|---|
| 79 | result.append(trees_difference(a_child, b_child, current_name + "/" + a_child.name)) |
|---|
| 80 | else: |
|---|
| 81 | result.append(trees_difference(a_child, b_child, a_child.name)) |
|---|
| 82 | else: |
|---|
| 83 | if current_name: |
|---|
| 84 | result.removed_files.append(current_name + "/" + a_child.name) |
|---|
| 85 | else: |
|---|
| 86 | result.removed_files.append(a_child.name) |
|---|
| 87 | for b_child in (b.children or []): |
|---|
| 88 | if (b_child not in accounted_for): |
|---|
| 89 | result.added_files.extend(traverse_tree(b_child, current_name)) |
|---|
| 90 | |
|---|
| 91 | except svn_tree.SVNTypeMismatch: |
|---|
| 92 | print 'Unequal Types: one Node is a file, the other is a directory' |
|---|
| 93 | raise svn_tree.SVNTreeUnequal |
|---|
| 94 | except svn_tree.SVNTreeIsNotDirectory: |
|---|
| 95 | print "Error: Foolish call to get_child." |
|---|
| 96 | sys.exit(1) |
|---|
| 97 | except IndexError: |
|---|
| 98 | print "Error: unequal number of children" |
|---|
| 99 | raise svn_tree.SVNTreeUnequal |
|---|
| 100 | return result |
|---|
| 101 | |
|---|
| 102 | def dump_tree(t): |
|---|
| 103 | svn_tree.dump_tree(t) |
|---|
| 104 | |
|---|
| 105 | def traverse_tree(t, parent_name=""): |
|---|
| 106 | """ Returns the list of all names in tree. """ |
|---|
| 107 | if parent_name: |
|---|
| 108 | full_node_name = parent_name + "/" + t.name |
|---|
| 109 | else: |
|---|
| 110 | full_node_name = t.name |
|---|
| 111 | |
|---|
| 112 | if (t.children is None): |
|---|
| 113 | result = [full_node_name] |
|---|
| 114 | else: |
|---|
| 115 | result = [full_node_name + "/"] |
|---|
| 116 | for i in t.children: |
|---|
| 117 | result.extend(traverse_tree(i, full_node_name)) |
|---|
| 118 | return result |
|---|