Get the state of a given path in source control.
- import bzrlib.workingtree
- tree, relpath = bzrlib.workingtree.WorkingTree.open_containing(path)
- except bzrlib.errors.NotBranchError:
+ print "called: __get_state__(%s)" % path
+ if os.path.isdir(path):
+ print "%s: skip directory" % path
+ return NOT_IN_TREE # ignore directories (for efficiency)
+ from mercurial import hg, repo, ui, cmdutil
+ dir, filename = os.path.split(path)
+ repo = hg.repository(u, path='')
# We aren't in a working tree
+ print "%s: not in repo" % dir
- # Ideally, we'd use tree.changes_from, but unfortunately this is
- # recusive for directories, so we calculate changes ourselves.
- if tree.is_control_filename(relpath):
+ files, matchfn, anypats = cmdutil.matchpats(repo, [filename])
+ modified, added, removed, deleted, unknown, ignored, clean = [
+ n for n in repo.status(files=files, list_clean=True)]
- file_id = tree.path2id(relpath)
- # This is an unknown file...
- # Get information about the path from the old tree
- old = tree.basis_tree()
- entry = old.inventory[file_id]
- except bzrlib.errors.NoSuchId:
- # This is an added entry...
- if entry.kind != "file":
- # TODO: For directories, we want to find out if
- # the contents of the directories have changed...
- old_size = entry.text_size
- old_sha1 = entry.text_sha1
- # Look in the new tree to see if has changed...
- if tree.get_file_size(file_id) != old_size or tree.get_file_sha1(file_id) != old_sha1:
- # This file has been modified
- # This file has unchanged.
+ print "%s: ADDED" % path
+ print "%s: MODIFIED" % path
+ print "%s: UNCHANGED" % path
+ print "%s: UNKNOWN" % path
def IsMemberOf(self, path, attrib):