def _initialize(self): """Iterate over git-ls-tree and create GitTreeItems.""" status, output = git.ls_tree('--full-tree', '-r', '-t', '-z', self.ref, with_status=True, with_stderr=True) if status != 0: cola.notifier().broadcast(signals.log_cmd, status, output) return if not output: return for line in core.decode(output[:-1]).split('\0'): # .....6 ...4 ......................................40 # 040000 tree c127cde9a0c644a3a8fef449a244f47d5272dfa6 relative # 100644 blob 139e42bf4acaa4927ec9be1ec55a252b97d3f1e2 relative/path objtype = line[7] relpath = line[6 + 1 + 4 + 1 + 40 + 1:] if objtype == 't': parent = self.dir_entries[utils.dirname(relpath)] self.add_directory(parent, relpath) elif objtype == 'b': self.add_file(relpath)
def add_file(self, path, insert=False): """Add a file to the model.""" dirname = utils.dirname(path) if dirname in self._dir_entries: parent = self._dir_entries[dirname] else: parent = self._create_dir_entry(dirname, self._dir_entries) self._dir_entries[dirname] = parent self._add_file(parent, path, insert=insert)
def add_file(self, path, insert=False): """Add a file to the model.""" dirname = utils.dirname(path) if dirname in self._direntries: parent = self._direntries[dirname] else: parent = self._create_dir_entry(dirname, self._direntries) self._direntries[dirname] = parent self._add_file(parent, path, insert=insert)
def add_file(self, path): """Add a file to the model.""" dirname = utils.dirname(path) dir_entries = self.dir_entries try: parent = dir_entries[dirname] except KeyError: parent = dir_entries[dirname] = self.create_dir_entry(dirname) row_items = self.create_row(path, False) parent.appendRow(row_items)
def _initialize(self): """Iterate over git-ls-tree and create GitTreeItems.""" status, output = git.ls_tree('--full-tree', '-r', '-t', '-z', self.ref, with_status=True, with_stderr=True) if status != 0: cola.notifier().broadcast(signals.log_cmd, status, output) return for line in output.rstrip('\0').split('\0'): # .....6 ...4 ......................................40 # 040000 tree c127cde9a0c644a3a8fef449a244f47d5272dfa6 relative # 100644 blob 139e42bf4acaa4927ec9be1ec55a252b97d3f1e2 relative/path objtype = line[7] relpath = line[6 + 1 + 4 + 1 + 40 + 1:] if objtype == 't': parent = self.dir_entries[utils.dirname(relpath)] self.add_directory(parent, relpath) elif objtype == 'b': self.add_file(relpath)
def _initialize(self): """Iterate over git-ls-tree and create GitTreeItems.""" status, out, err = git.ls_tree("--full-tree", "-r", "-t", "-z", self.ref) if status != 0: Interaction.log_status(status, out, err) return if not out: return for line in out[:-1].split("\0"): # .....6 ...4 ......................................40 # 040000 tree c127cde9a0c644a3a8fef449a244f47d5272dfa6 relative # 100644 blob 139e42bf4acaa4927ec9be1ec55a252b97d3f1e2 relative/path objtype = line[7] relpath = line[6 + 1 + 4 + 1 + 40 + 1 :] if objtype == "t": parent = self.dir_entries[utils.dirname(relpath)] self.add_directory(parent, relpath) elif objtype == "b": self.add_file(relpath)
def _initialize(self): """Iterate over git-ls-tree and create GitTreeItems.""" status, out, err = git.ls_tree('--full-tree', '-r', '-t', '-z', self.ref) if status != 0: Interaction.log_status(status, out, err) return if not out: return for line in out[:-1].split('\0'): # .....6 ...4 ......................................40 # 040000 tree c127cde9a0c644a3a8fef449a244f47d5272dfa6 relative # 100644 blob 139e42bf4acaa4927ec9be1ec55a252b97d3f1e2 relative/path objtype = line[7] relpath = line[6 + 1 + 4 + 1 + 40 + 1:] if objtype == 't': parent = self.dir_entries[utils.dirname(relpath)] self.add_directory(parent, relpath) elif objtype == 'b': self.add_file(relpath)
def test_dirname(self): """Test the utils.dirname function.""" self.assertEqual(utils.dirname('bar'), '') self.assertEqual(utils.dirname('/bar'), '') self.assertEqual(utils.dirname('//bar'), '') self.assertEqual(utils.dirname('///bar'), '') self.assertEqual(utils.dirname('foo/bar'), 'foo') self.assertEqual(utils.dirname('foo//bar'), 'foo') self.assertEqual(utils.dirname('foo /bar'), 'foo ') self.assertEqual(utils.dirname('/foo//bar'), '/foo') self.assertEqual(utils.dirname('/foo /bar'), '/foo ') self.assertEqual(utils.dirname('//foo//bar'), '/foo') self.assertEqual(utils.dirname('///foo///bar'), '/foo')
def test_dirname(self): """Test the utils.dirname function.""" self.assertEqual(utils.dirname("bar"), "") self.assertEqual(utils.dirname("/bar"), "") self.assertEqual(utils.dirname("//bar"), "") self.assertEqual(utils.dirname("///bar"), "") self.assertEqual(utils.dirname("foo/bar"), "foo") self.assertEqual(utils.dirname("foo//bar"), "foo") self.assertEqual(utils.dirname("foo /bar"), "foo ") self.assertEqual(utils.dirname("/foo//bar"), "/foo") self.assertEqual(utils.dirname("/foo /bar"), "/foo ") self.assertEqual(utils.dirname("//foo//bar"), "/foo") self.assertEqual(utils.dirname("///foo///bar"), "/foo")
def test_dirname(): """Test the utils.dirname function.""" assert utils.dirname('bar') == '' assert utils.dirname('/bar') == '' assert utils.dirname('//bar') == '' assert utils.dirname('///bar') == '' assert utils.dirname('foo/bar') == 'foo' assert utils.dirname('foo//bar') == 'foo' assert utils.dirname('foo /bar') == 'foo ' assert utils.dirname('/foo//bar') == '/foo' assert utils.dirname('/foo /bar') == '/foo ' assert utils.dirname('//foo//bar') == '/foo' assert utils.dirname('///foo///bar') == '/foo'