Sync with upstream
[svnrdump.git] / svntest / tree.py
blob1dda611710b054610479c5c3681e3b56ff337406
2 # tree.py: tools for comparing directory trees
4 # Subversion is a tool for revision control.
5 # See http://subversion.tigris.org for more information.
7 # ====================================================================
8 # Licensed to the Apache Software Foundation (ASF) under one
9 # or more contributor license agreements. See the NOTICE file
10 # distributed with this work for additional information
11 # regarding copyright ownership. The ASF licenses this file
12 # to you under the Apache License, Version 2.0 (the
13 # "License"); you may not use this file except in compliance
14 # with the License. You may obtain a copy of the License at
16 # http://www.apache.org/licenses/LICENSE-2.0
18 # Unless required by applicable law or agreed to in writing,
19 # software distributed under the License is distributed on an
20 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 # KIND, either express or implied. See the License for the
22 # specific language governing permissions and limitations
23 # under the License.
24 ######################################################################
26 import re
27 import os
28 import sys
29 if sys.version_info[0] >= 3:
30 # Python >=3.0
31 from io import StringIO
32 else:
33 # Python <3.0
34 from StringIO import StringIO
35 from xml.dom.minidom import parseString
36 import base64
38 import svntest
40 # Tree Exceptions.
42 # All tree exceptions should inherit from SVNTreeError
43 class SVNTreeError(svntest.Failure):
44 "Exception raised if you screw up in the tree module."
45 pass
47 class SVNTreeUnequal(SVNTreeError):
48 "Exception raised if two trees are unequal."
49 pass
51 class SVNTypeMismatch(SVNTreeError):
52 "Exception raised if one node is file and other is dir"
53 pass
55 #========================================================================
57 # ===> Overview of our Datastructures <===
59 # The general idea here is that many, many things can be represented by
60 # a tree structure:
62 # - a working copy's structure and contents
63 # - the output of 'svn status'
64 # - the output of 'svn checkout/update'
65 # - the output of 'svn commit'
67 # The idea is that a test function creates a "expected" tree of some
68 # kind, and is then able to compare it to an "actual" tree that comes
69 # from running the Subversion client. This is what makes a test
70 # automated; if an actual and expected tree match exactly, then the test
71 # has passed. (See compare_trees() below.)
73 # The SVNTreeNode class is the fundamental data type used to build tree
74 # structures. The class contains a method for "dropping" a new node
75 # into an ever-growing tree structure. (See also create_from_path()).
77 # We have four parsers in this file for the four use cases listed above:
78 # each parser examines some kind of input and returns a tree of
79 # SVNTreeNode objects. (See build_tree_from_checkout(),
80 # build_tree_from_commit(), build_tree_from_status(), and
81 # build_tree_from_wc()). These trees are the "actual" trees that result
82 # from running the Subversion client.
84 # Also necessary, of course, is a convenient way for a test to create an
85 # "expected" tree. The test *could* manually construct and link a bunch
86 # of SVNTreeNodes, certainly. But instead, all the tests are using the
87 # build_generic_tree() routine instead.
89 # build_generic_tree() takes a specially-formatted list of lists as
90 # input, and returns a tree of SVNTreeNodes. The list of lists has this
91 # structure:
93 # [ ['/full/path/to/item', 'text contents', {prop-hash}, {att-hash}],
94 # [...],
95 # [...],
96 # ... ]
98 # You can see that each item in the list essentially defines an
99 # SVNTreeNode. build_generic_tree() instantiates a SVNTreeNode for each
100 # item, and then drops it into a tree by parsing each item's full path.
102 # So a typical test routine spends most of its time preparing lists of
103 # this format and sending them to build_generic_tree(), rather than
104 # building the "expected" trees directly.
106 # ### Note: in the future, we'd like to remove this extra layer of
107 # ### abstraction. We'd like the SVNTreeNode class to be more
108 # ### directly programmer-friendly, providing a number of accessor
109 # ### routines, so that tests can construct trees directly.
111 # The first three fields of each list-item are self-explanatory. It's
112 # the fourth field, the "attribute" hash, that needs some explanation.
113 # The att-hash is used to place extra information about the node itself,
114 # depending on the parsing context:
116 # - in the 'svn co/up' use-case, each line of output starts with two
117 # characters from the set of (A, D, G, U, C, _) or 'Restored'. The
118 # status code is stored in a attribute named 'status'. In the case
119 # of a restored file, the word 'Restored' is stored in an attribute
120 # named 'verb'.
122 # - in the 'svn ci/im' use-case, each line of output starts with one
123 # of the words (Adding, Deleting, Sending). This verb is stored in
124 # an attribute named 'verb'.
126 # - in the 'svn status' use-case (which is always run with the -v
127 # (--verbose) flag), each line of output contains a working revision
128 # number and a two-letter status code similar to the 'svn co/up'
129 # case. This information is stored in attributes named 'wc_rev'
130 # and 'status'. The repository revision is also printed, but it
131 # is ignored.
133 # - in the working-copy use-case, the att-hash is ignored.
136 # Finally, one last explanation: the file 'actions.py' contain a number
137 # of helper routines named 'run_and_verify_FOO'. These routines take
138 # one or more "expected" trees as input, then run some svn subcommand,
139 # then push the output through an appropriate parser to derive an
140 # "actual" tree. Then it runs compare_trees() and raises an exception
141 # on failure. This is why most tests typically end with a call to
142 # run_and_verify_FOO().
146 #========================================================================
148 # A node in a tree.
150 # If CHILDREN is None, then the node is a file. Otherwise, CHILDREN
151 # is a list of the nodes making up that directory's children.
153 # NAME is simply the name of the file or directory. CONTENTS is a
154 # string that contains the file's contents (if a file), PROPS are
155 # properties attached to files or dirs, and ATTS is a dictionary of
156 # other metadata attached to the node.
158 class SVNTreeNode:
160 def __init__(self, name, children=None, contents=None, props={}, atts={}):
161 self.name = name
162 self.children = children
163 self.contents = contents
164 self.props = props
165 self.atts = atts
166 self.path = name
168 # TODO: Check to make sure contents and children are mutually exclusive
170 def add_child(self, newchild):
171 child_already_exists = 0
172 if self.children is None: # if you're a file,
173 self.children = [] # become an empty dir.
174 else:
175 for a in self.children:
176 if a.name == newchild.name:
177 child_already_exists = 1
178 break
180 if child_already_exists:
181 if newchild.children is None:
182 # this is the 'end' of the chain, so copy any content here.
183 a.contents = newchild.contents
184 a.props = newchild.props
185 a.atts = newchild.atts
186 a.path = os.path.join(self.path, newchild.name)
187 else:
188 # try to add dangling children to your matching node
189 for i in newchild.children:
190 a.add_child(i)
191 else:
192 self.children.append(newchild)
193 newchild.path = os.path.join(self.path, newchild.name)
196 def pprint(self, stream = sys.stdout):
197 "Pretty-print the meta data for this node to STREAM."
198 stream.write(" * Node name: %s\n" % self.name)
199 stream.write(" Path: %s\n" % self.path)
200 mime_type = self.props.get("svn:mime-type")
201 if not mime_type or mime_type.startswith("text/"):
202 if self.children is not None:
203 stream.write(" Contents: N/A (node is a directory)\n")
204 else:
205 stream.write(" Contents: %s\n" % self.contents)
206 else:
207 stream.write(" Contents: %d bytes (binary)\n" % len(self.contents))
208 stream.write(" Properties: %s\n" % self.props)
209 stream.write(" Attributes: %s\n" % self.atts)
210 ### FIXME: I'd like to be able to tell the difference between
211 ### self.children is None (file) and self.children == [] (empty
212 ### directory), but it seems that most places that construct
213 ### SVNTreeNode objects don't even try to do that. --xbc
215 ### See issue #1611 about this problem. -kfogel
216 if self.children is not None:
217 stream.write(" Children: %s\n" % len(self.children))
218 else:
219 stream.write(" Children: None (node is probably a file)\n")
220 stream.flush()
222 def get_printable_path(self):
223 """Remove some occurrences of root_node_name = "__SVN_ROOT_NODE",
224 it is in the way when matching for a subtree, and looks bad."""
225 path = self.path
226 if path.startswith(root_node_name + os.sep):
227 path = path[len(root_node_name + os.sep):]
228 return path
230 def print_script(self, stream = sys.stdout, subtree = "", prepend="\n ",
231 drop_empties = True):
232 """Python-script-print the meta data for this node to STREAM.
233 Print only those nodes whose path string starts with the string SUBTREE,
234 and print only the part of the path string that remains after SUBTREE.
235 PREPEND is a string prepended to each node printout (does the line
236 feed if desired, don't include a comma in PREPEND).
237 If DROP_EMPTIES is true, all dir nodes that have no data set in them
238 (no props, no atts) and that have children (so they are included
239 implicitly anyway) are not printed.
240 Return 1 if this node was printed, 0 otherwise (added up by
241 dump_tree_script())"""
243 # figure out if this node would be obsolete to print.
244 if drop_empties and len(self.props) < 1 and len(self.atts) < 1 and \
245 self.contents is None and self.children is not None:
246 return 0
248 path = self.get_printable_path()
250 # remove the subtree path, skip this node if necessary.
251 if path.startswith(subtree):
252 path = path[len(subtree):]
253 else:
254 return 0
256 if path.startswith(os.sep):
257 path = path[1:]
259 line = prepend
260 line += "%-20s: Item(" % ("'%s'" % path.replace(os.sep, '/'))
261 comma = False
263 mime_type = self.props.get("svn:mime-type")
264 if not mime_type or mime_type.startswith("text/"):
265 if self.contents is not None:
266 # Escape some characters for nicer script and readability.
267 # (This is error output. I guess speed is no consideration here.)
268 line += "contents=\"%s\"" % (self.contents
269 .replace('\n','\\n')
270 .replace('"','\\"')
271 .replace('\r','\\r')
272 .replace('\t','\\t'))
273 comma = True
274 else:
275 line += 'content is binary data'
276 comma = True
278 if self.props:
279 if comma:
280 line += ", "
281 line += "props={"
282 comma = False
284 for name in self.props:
285 if comma:
286 line += ", "
287 line += "'%s':'%s'" % (name, self.props[name])
288 comma = True
290 line += "}"
291 comma = True
293 for name in self.atts:
294 if comma:
295 line += ", "
296 line += "%s='%s'" % (name, self.atts[name])
297 comma = True
299 line += "),"
300 stream.write("%s" % line)
301 stream.flush()
302 return 1
305 def __str__(self):
306 s = StringIO()
307 self.pprint(s)
308 return s.getvalue()
311 def __cmp__(self, other):
312 """Define a simple ordering of two nodes without regard to their full
313 path (i.e. position in the tree). This can be used for sorting the
314 children within a directory."""
315 return cmp(self.name, other.name)
317 def as_state(self, prefix=None):
318 """Return an svntest.wc.State instance that is equivalent to this tree."""
319 root = self
320 if self.path == root_node_name:
321 assert prefix is None
322 wc_dir = ''
323 while True:
324 if root is not self: # don't prepend ROOT_NODE_NAME
325 wc_dir = os.path.join(wc_dir, root.name)
326 if root.contents or root.props or root.atts:
327 break
328 if not root.children or len(root.children) != 1:
329 break
330 root = root.children[0]
331 state = svntest.wc.State(wc_dir, { })
332 if root.contents or root.props or root.atts:
333 state.add({'': root.as_item()})
334 prefix = wc_dir
335 else:
336 assert prefix is not None
338 path = self.path
339 if path.startswith(root_node_name):
340 path = path[len(root_node_name)+1:]
341 # prefix should only be set on a recursion, which means a child,
342 # which means this path better not be the same as the prefix.
343 assert path != prefix, 'not processing a child of the root'
344 l = len(prefix)
345 if l > 0:
346 assert path[:l] == prefix, \
347 '"%s" is not a prefix of "%s"' % (prefix, path)
348 # return the portion after the separator
349 path = path[l+1:].replace(os.sep, '/')
351 state = svntest.wc.State('', {
352 path: self.as_item()
355 if root.children:
356 for child in root.children:
357 state.add_state('', child.as_state(prefix))
359 return state
361 def as_item(self):
362 return svntest.wc.StateItem(self.contents,
363 self.props,
364 self.atts.get('status'),
365 self.atts.get('verb'),
366 self.atts.get('wc_rev'),
367 self.atts.get('locked'),
368 self.atts.get('copied'),
369 self.atts.get('switched'),
370 self.atts.get('writelocked'),
371 self.atts.get('treeconflict'))
373 def recurse(self, function):
374 results = []
375 results += [ function(self) ]
376 if self.children:
377 for child in self.children:
378 results += child.recurse(function)
379 return results
381 def find_node(self, path):
382 if self.get_printable_path() == path:
383 return self
384 if self.children:
385 for child in self.children:
386 result = child.find_node(path)
387 if result:
388 return result
389 return None
391 # reserved name of the root of the tree
392 root_node_name = "__SVN_ROOT_NODE"
395 # helper func
396 def add_elements_as_path(top_node, element_list):
397 """Add the elements in ELEMENT_LIST as if they were a single path
398 below TOP_NODE."""
400 # The idea of this function is to take a list like so:
401 # ['A', 'B', 'C'] and a top node, say 'Z', and generate a tree
402 # like this:
404 # Z -> A -> B -> C
406 # where 1 -> 2 means 2 is a child of 1.
409 prev_node = top_node
410 for i in element_list:
411 new_node = SVNTreeNode(i, None)
412 prev_node.add_child(new_node)
413 prev_node = new_node
416 # Helper for compare_trees
417 def compare_file_nodes(a, b):
418 """Compare two nodes, A (actual) and B (expected). Compare their names,
419 contents, properties and attributes, ignoring children. Return 0 if the
420 same, 1 otherwise."""
421 if a.name != b.name:
422 return 1
423 if a.contents != b.contents:
424 return 1
425 if a.props != b.props:
426 return 1
427 if a.atts != b.atts:
428 return 1
429 return 0
432 # Internal utility used by most build_tree_from_foo() routines.
434 # (Take the output and .add_child() it to a root node.)
436 def create_from_path(path, contents=None, props={}, atts={}):
437 """Create and return a linked list of treenodes, given a PATH
438 representing a single entry into that tree. CONTENTS and PROPS are
439 optional arguments that will be deposited in the tail node."""
441 # get a list of all the names in the path
442 # each of these will be a child of the former
443 if os.sep != "/":
444 path = path.replace(os.sep, "/")
445 elements = path.split("/")
446 if len(elements) == 0:
447 ### we should raise a less generic error here. which?
448 raise SVNTreeError
450 root_node = None
452 # if this is Windows: if the path contains a drive name (X:), make it
453 # the root node.
454 if os.name == 'nt':
455 m = re.match("([a-zA-Z]:)(.+)", elements[0])
456 if m:
457 root_node = SVNTreeNode(m.group(1), None)
458 elements[0] = m.group(2)
459 add_elements_as_path(root_node, elements[0:])
461 if not root_node:
462 root_node = SVNTreeNode(elements[0], None)
463 add_elements_as_path(root_node, elements[1:])
465 # deposit contents in the very last node.
466 node = root_node
467 while True:
468 if node.children is None:
469 node.contents = contents
470 node.props = props
471 node.atts = atts
472 break
473 node = node.children[0]
475 return root_node
478 eol_re = re.compile(r'(\r\n|\r)')
480 # helper for build_tree_from_wc()
481 def get_props(paths):
482 """Return a hash of hashes of props for PATHS, using the svn client. Convert
483 each embedded end-of-line to a single LF character."""
485 # It's not kosher to look inside .svn/ and try to read the internal
486 # property storage format. Instead, we use 'svn proplist'. After
487 # all, this is the only way the user can retrieve them, so we're
488 # respecting the black-box paradigm.
490 files = {}
491 exit_code, output, errput = svntest.main.run_svn(1,
492 "proplist",
493 "--verbose",
494 "--xml",
495 *paths)
497 output = (line for line in output if not line.startswith('DBG:'))
498 dom = parseString(''.join(output))
499 target_nodes = dom.getElementsByTagName('target')
500 for target_node in target_nodes:
501 filename = target_node.attributes['path'].nodeValue
502 file_props = {}
503 for property_node in target_node.getElementsByTagName('property'):
504 name = property_node.attributes['name'].nodeValue
505 if property_node.hasChildNodes():
506 text_node = property_node.firstChild
507 value = text_node.nodeValue
508 else:
509 value = ''
510 try:
511 encoding = property_node.attributes['encoding'].nodeValue
512 if encoding == 'base64':
513 value = base64.b64decode(value)
514 else:
515 raise Exception("Unknown encoding '%s' for file '%s' property '%s'"
516 % (encoding, filename, name,))
517 except KeyError:
518 pass
519 # If the property value contained a CR, or if under Windows an
520 # "svn:*" property contains a newline, then the XML output
521 # contains a CR character XML-encoded as '&#13;'. The XML
522 # parser converts it back into a CR character. So again convert
523 # all end-of-line variants into a single LF:
524 value = eol_re.sub('\n', value)
525 file_props[name] = value
526 files[filename] = file_props
528 dom.unlink()
529 return files
532 ### ridiculous function. callers should do this one line themselves.
533 def get_text(path):
534 "Return a string with the textual contents of a file at PATH."
536 # sanity check
537 if not os.path.isfile(path):
538 return None
540 return open(path, 'r').read()
543 def get_child(node, name):
544 """If SVNTreeNode NODE contains a child named NAME, return child;
545 else, return None. If SVNTreeNode is not a directory, exit completely."""
546 if node.children == None:
547 print("Error: Foolish call to get_child.")
548 sys.exit(1)
549 for n in node.children:
550 if name == n.name:
551 return n
552 return None
555 # Helper for compare_trees
556 def default_singleton_handler(node, description):
557 """Print SVNTreeNode NODE's name, describing it with the string
558 DESCRIPTION, then raise SVNTreeUnequal."""
559 print("Couldn't find node '%s' in %s tree" % (node.name, description))
560 node.pprint()
561 raise SVNTreeUnequal
563 # A test helper function implementing the singleton_handler_a API.
564 def detect_conflict_files(node, extra_files):
565 """NODE has been discovered, an extra file on disk. Verify that it
566 matches one of the regular expressions in the EXTRA_FILES list. If
567 it matches, remove the match from the list. If it doesn't match,
568 raise an exception."""
570 for pattern in extra_files:
571 mo = re.match(pattern, node.name)
572 if mo:
573 extra_files.pop(extra_files.index(pattern)) # delete pattern from list
574 break
575 else:
576 msg = "Encountered unexpected disk path '" + node.name + "'"
577 print(msg)
578 node.pprint()
579 raise SVNTreeUnequal(msg)
581 ###########################################################################
582 ###########################################################################
583 # EXPORTED ROUTINES ARE BELOW
586 # Main tree comparison routine!
588 def compare_trees(label,
589 a, b,
590 singleton_handler_a = None,
591 a_baton = None,
592 singleton_handler_b = None,
593 b_baton = None):
594 """Compare SVNTreeNodes A (actual) and B (expected), expressing
595 differences using FUNC_A and FUNC_B. FUNC_A and FUNC_B are
596 functions of two arguments (a SVNTreeNode and a context baton), and
597 may raise exception SVNTreeUnequal, in which case they use the
598 string LABEL to describe the error (their return value is ignored).
599 LABEL is typically "output", "disk", "status", or some other word
600 that labels the trees being compared.
602 If A and B are both files, then return if their contents,
603 properties, and names are all the same; else raise a SVNTreeUnequal.
604 If A is a file and B is a directory, raise a SVNTreeUnequal; same
605 vice-versa. If both are directories, then for each entry that
606 exists in both, call compare_trees on the two entries; otherwise, if
607 the entry exists only in A, invoke FUNC_A on it, and likewise for
608 B with FUNC_B."""
610 def display_nodes(a, b):
611 'Display two nodes, expected and actual.'
612 print("=============================================================")
613 print("Expected '%s' and actual '%s' in %s tree are different!"
614 % (b.name, a.name, label))
615 print("=============================================================")
616 print("EXPECTED NODE TO BE:")
617 print("=============================================================")
618 b.pprint()
619 print("=============================================================")
620 print("ACTUAL NODE FOUND:")
621 print("=============================================================")
622 a.pprint()
624 # Setup singleton handlers
625 if singleton_handler_a is None:
626 singleton_handler_a = default_singleton_handler
627 a_baton = "expected " + label
628 if singleton_handler_b is None:
629 singleton_handler_b = default_singleton_handler
630 b_baton = "actual " + label
632 try:
633 # A and B are both files.
634 if (a.children is None) and (b.children is None):
635 if compare_file_nodes(a, b):
636 display_nodes(a, b)
637 raise SVNTreeUnequal
638 # One is a file, one is a directory.
639 elif (((a.children is None) and (b.children is not None))
640 or ((a.children is not None) and (b.children is None))):
641 display_nodes(a, b)
642 raise SVNTypeMismatch
643 # They're both directories.
644 else:
645 # First, compare the directories' two hashes.
646 if (a.props != b.props) or (a.atts != b.atts):
647 display_nodes(a, b)
648 raise SVNTreeUnequal
650 accounted_for = []
651 # For each child of A, check and see if it's in B. If so, run
652 # compare_trees on the two children and add b's child to
653 # accounted_for. If not, run FUNC_A on the child. Next, for each
654 # child of B, check and see if it's in accounted_for. If it is,
655 # do nothing. If not, run FUNC_B on it.
656 for a_child in a.children:
657 b_child = get_child(b, a_child.name)
658 if b_child:
659 accounted_for.append(b_child)
660 compare_trees(label, a_child, b_child,
661 singleton_handler_a, a_baton,
662 singleton_handler_b, b_baton)
663 else:
664 singleton_handler_a(a_child, a_baton)
665 for b_child in b.children:
666 if b_child not in accounted_for:
667 singleton_handler_b(b_child, b_baton)
668 except SVNTypeMismatch:
669 print('Unequal Types: one Node is a file, the other is a directory')
670 raise SVNTreeUnequal
671 except IndexError:
672 print("Error: unequal number of children")
673 raise SVNTreeUnequal
674 except SVNTreeUnequal:
675 if a.name != root_node_name:
676 print("Unequal at node %s" % a.name)
677 raise
681 # Visually show a tree's structure
683 def dump_tree(n,indent=""):
684 """Print out a nice representation of the structure of the tree in
685 the SVNTreeNode N. Prefix each line with the string INDENT."""
687 # Code partially stolen from Dave Beazley
688 tmp_children = sorted(n.children or [])
690 if n.name == root_node_name:
691 print("%s%s" % (indent, "ROOT"))
692 else:
693 print("%s%s" % (indent, n.name))
695 indent = indent.replace("-", " ")
696 indent = indent.replace("+", " ")
697 for i in range(len(tmp_children)):
698 c = tmp_children[i]
699 if i == len(tmp_children)-1:
700 dump_tree(c,indent + " +-- ")
701 else:
702 dump_tree(c,indent + " |-- ")
705 def dump_tree_script__crawler(n, subtree="", stream=sys.stdout):
706 "Helper for dump_tree_script. See that comment."
707 count = 0
709 # skip printing the root node.
710 if n.name != root_node_name:
711 count += n.print_script(stream, subtree)
713 for child in n.children or []:
714 count += dump_tree_script__crawler(child, subtree, stream)
716 return count
719 def dump_tree_script(n, subtree="", stream=sys.stdout, wc_varname='wc_dir'):
720 """Print out a python script representation of the structure of the tree
721 in the SVNTreeNode N. Print only those nodes whose path string starts
722 with the string SUBTREE, and print only the part of the path string
723 that remains after SUBTREE.
724 The result is printed to STREAM.
725 The WC_VARNAME is inserted in the svntest.wc.State(wc_dir,{}) call
726 that is printed out (this is used by factory.py)."""
728 stream.write("svntest.wc.State(" + wc_varname + ", {")
729 count = dump_tree_script__crawler(n, subtree, stream)
730 if count > 0:
731 stream.write('\n')
732 stream.write("})")
735 ###################################################################
736 ###################################################################
737 # PARSERS that return trees made of SVNTreeNodes....
740 ###################################################################
741 # Build an "expected" static tree from a list of lists
744 # Create a list of lists, of the form:
746 # [ [path, contents, props, atts], ... ]
748 # and run it through this parser. PATH is a string, a path to the
749 # object. CONTENTS is either a string or None, and PROPS and ATTS are
750 # populated dictionaries or {}. Each CONTENTS/PROPS/ATTS will be
751 # attached to the basename-node of the associated PATH.
753 def build_generic_tree(nodelist):
754 "Given a list of lists of a specific format, return a tree."
756 root = SVNTreeNode(root_node_name)
758 for list in nodelist:
759 new_branch = create_from_path(list[0], list[1], list[2], list[3])
760 root.add_child(new_branch)
762 return root
765 ####################################################################
766 # Build trees from different kinds of subcommand output.
769 # Parse co/up output into a tree.
771 # Tree nodes will contain no contents, a 'status' att, and a
772 # 'treeconflict' att.
774 def build_tree_from_checkout(lines, include_skipped=True):
775 "Return a tree derived by parsing the output LINES from 'co' or 'up'."
777 return svntest.wc.State.from_checkout(lines, include_skipped).old_tree()
780 # Parse ci/im output into a tree.
782 # Tree nodes will contain no contents, and only one 'verb' att.
784 def build_tree_from_commit(lines):
785 "Return a tree derived by parsing the output LINES from 'ci' or 'im'."
787 return svntest.wc.State.from_commit(lines).old_tree()
790 # Parse status output into a tree.
792 # Tree nodes will contain no contents, and these atts:
794 # 'status', 'wc_rev',
795 # ... and possibly 'locked', 'copied', 'switched',
796 # 'writelocked' and 'treeconflict',
797 # IFF columns non-empty.
800 def build_tree_from_status(lines):
801 "Return a tree derived by parsing the output LINES from 'st -vuq'."
803 return svntest.wc.State.from_status(lines).old_tree()
806 # Parse merge "skipped" output
808 def build_tree_from_skipped(lines):
810 return svntest.wc.State.from_skipped(lines).old_tree()
813 def build_tree_from_diff_summarize(lines):
814 "Build a tree from output of diff --summarize"
816 return svntest.wc.State.from_summarize(lines).old_tree()
819 ####################################################################
820 # Build trees by looking at the working copy
823 # The reason the 'load_props' flag is off by default is because it
824 # creates a drastic slowdown -- we spawn a new 'svn proplist'
825 # process for every file and dir in the working copy!
828 def build_tree_from_wc(wc_path, load_props=0, ignore_svn=1):
829 """Takes WC_PATH as the path to a working copy. Walks the tree below
830 that path, and creates the tree based on the actual found
831 files. If IGNORE_SVN is true, then exclude SVN admin dirs from the tree.
832 If LOAD_PROPS is true, the props will be added to the tree."""
834 return svntest.wc.State.from_wc(wc_path, load_props, ignore_svn).old_tree()