Code Repositories xandikos / 1246408
Only create commit if contents actually changed. Jelmer Vernooń≥ 10 months ago
2 changed file(s) with 23 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
470470 b = Blob()
471471 b.chunked = data
472472 tree = self._get_current_tree()
473 old_tree_id = tree.id
473474 name_enc = name.encode(DEFAULT_ENCODING)
474475 tree[name_enc] = (0o644 | stat.S_IFREG, b.id)
475476 self.repo.object_store.add_objects([(tree, ''), (b, name_enc)])
476 self._commit_tree(tree.id, message.encode(DEFAULT_ENCODING),
477 author=author)
477 if tree.id != old_tree_id:
478 self._commit_tree(tree.id, message.encode(DEFAULT_ENCODING),
479 author=author)
478480 return b.id
479481
480482 def delete_one(self, name, message=None, author=None, etag=None):
565567 f.writelines(data)
566568 st = os.lstat(p)
567569 blob = Blob.from_string(b''.join(data))
568 self.repo.object_store.add_object(blob)
569 index[name.encode(DEFAULT_ENCODING)] = IndexEntry(
570 *index_entry_from_stat(st, blob.id, 0))
571 self._commit_tree(
572 index, message.encode(DEFAULT_ENCODING),
573 author=author)
570 encoded_name = name.encode(DEFAULT_ENCODING)
571 if encoded_name not in index or blob.id != index[encoded_name].sha:
572 self.repo.object_store.add_object(blob)
573 index[encoded_name] = IndexEntry(
574 *index_entry_from_stat(st, blob.id, 0))
575 self._commit_tree(
576 index, message.encode(DEFAULT_ENCODING),
577 author=author)
574578 return blob.id
575579
576580 def delete_one(self, name, message=None, author=None, etag=None):
292292 gc = self.create_store()
293293 self.assertEqual([], gc.subdirectories())
294294
295 def test_import_only_once(self):
296 gc = self.create_store()
297 (name1, etag1) = gc.import_one('foo.ics', 'text/calendar',
298 [EXAMPLE_VCALENDAR1])
299 (name2, etag2) = gc.import_one('foo.ics', 'text/calendar',
300 [EXAMPLE_VCALENDAR1])
301 self.assertEqual(name1, name2)
302 self.assertEqual(etag1, etag2)
303 walker = gc.repo.get_walker(include=[gc.repo.refs[gc.ref]])
304 self.assertEqual(1, len([w.commit for w in walker]))
305
295306
296307 class GitStoreTest(unittest.TestCase):
297308