##// END OF EJS Templates
vcsserver: implement set head ref and optimize deletion of filenodes
super-admin -
r966:1ce1ca3f default
parent child Browse files
Show More
@@ -452,11 +452,22 b' class GitRemote(RemoteBase):'
452 # TODO: this is quite complex, check if that can be simplified
452 # TODO: this is quite complex, check if that can be simplified
453 @reraise_safe_exceptions
453 @reraise_safe_exceptions
454 def commit(self, wire, commit_data, branch, commit_tree, updated, removed):
454 def commit(self, wire, commit_data, branch, commit_tree, updated, removed):
455 # Defines the root tree
456 class _Root(object):
457 def __repr__(self):
458 return 'ROOT TREE'
459 ROOT = _Root()
460
455 repo = self._factory.repo(wire)
461 repo = self._factory.repo(wire)
456 object_store = repo.object_store
462 object_store = repo.object_store
457
463
458 # Create tree and populates it with blobs
464 # Create tree and populates it with blobs
459 commit_tree = commit_tree and repo[commit_tree] or objects.Tree()
465
466 if commit_tree and repo[commit_tree]:
467 git_commit = repo[commit_data['parents'][0]]
468 commit_tree = repo[git_commit.tree] # root tree
469 else:
470 commit_tree = objects.Tree()
460
471
461 for node in updated:
472 for node in updated:
462 # Compute subdirs if needed
473 # Compute subdirs if needed
@@ -515,21 +526,34 b' class GitRemote(RemoteBase):'
515
526
516 for node_path in removed:
527 for node_path in removed:
517 paths = node_path.split('/')
528 paths = node_path.split('/')
518 tree = commit_tree
529 tree = commit_tree # start with top-level
519 trees = [tree]
530 trees = [{'tree': tree, 'path': ROOT}]
520 # Traverse deep into the forest...
531 # Traverse deep into the forest...
532 # resolve final tree by iterating the path.
533 # e.g a/b/c.txt will get
534 # - root as tree then
535 # - 'a' as tree,
536 # - 'b' as tree,
537 # - stop at c as blob.
521 for path in paths:
538 for path in paths:
522 try:
539 try:
523 obj = repo[tree[path][1]]
540 obj = repo[tree[path][1]]
524 if isinstance(obj, objects.Tree):
541 if isinstance(obj, objects.Tree):
525 trees.append(obj)
542 trees.append({'tree': obj, 'path': path})
526 tree = obj
543 tree = obj
527 except KeyError:
544 except KeyError:
528 break
545 break
546 #PROBLEM:
547 """
548 We're not editing same reference tree object
549 """
529 # Cut down the blob and all rotten trees on the way back...
550 # Cut down the blob and all rotten trees on the way back...
530 for path, tree in reversed(zip(paths, trees)):
551 for path, tree_data in reversed(zip(paths, trees)):
531 del tree[path]
552 tree = tree_data['tree']
532 if tree:
553 tree.__delitem__(path)
554 # This operation edits the tree, we need to mark new commit back
555
556 if len(tree) > 0:
533 # This tree still has elements - don't remove it or any
557 # This tree still has elements - don't remove it or any
534 # of it's parents
558 # of it's parents
535 break
559 break
@@ -539,7 +563,7 b' class GitRemote(RemoteBase):'
539 # Create commit
563 # Create commit
540 commit = objects.Commit()
564 commit = objects.Commit()
541 commit.tree = commit_tree.id
565 commit.tree = commit_tree.id
542 for k, v in commit_data.iteritems():
566 for k, v in commit_data.items():
543 setattr(commit, k, v)
567 setattr(commit, k, v)
544 object_store.add_object(commit)
568 object_store.add_object(commit)
545
569
@@ -1203,13 +1227,6 b' class GitRemote(RemoteBase):'
1203 return install_git_hooks(path, bare, force_create=force)
1227 return install_git_hooks(path, bare, force_create=force)
1204
1228
1205 @reraise_safe_exceptions
1229 @reraise_safe_exceptions
1206 def set_head_ref(self, wire, head_name):
1207 log.debug('Setting refs/head to `%s`', head_name)
1208 cmd = ['symbolic-ref', 'HEAD', 'refs/heads/%s' % head_name]
1209 output, __ = self.run_git_command(wire, cmd)
1210 return [head_name] + output.splitlines()
1211
1212 @reraise_safe_exceptions
1213 def get_hooks_info(self, wire):
1230 def get_hooks_info(self, wire):
1214 from vcsserver.hook_utils import (
1231 from vcsserver.hook_utils import (
1215 get_git_pre_hook_version, get_git_post_hook_version)
1232 get_git_pre_hook_version, get_git_post_hook_version)
@@ -1221,6 +1238,13 b' class GitRemote(RemoteBase):'
1221 }
1238 }
1222
1239
1223 @reraise_safe_exceptions
1240 @reraise_safe_exceptions
1241 def set_head_ref(self, wire, head_name):
1242 log.debug('Setting refs/head to `%s`', head_name)
1243 cmd = ['symbolic-ref', 'HEAD', 'refs/heads/%s' % head_name]
1244 output, __ = self.run_git_command(wire, cmd)
1245 return [head_name] + output.splitlines()
1246
1247 @reraise_safe_exceptions
1224 def archive_repo(self, wire, archive_dest_path, kind, mtime, archive_at_path,
1248 def archive_repo(self, wire, archive_dest_path, kind, mtime, archive_at_path,
1225 archive_dir_name, commit_id):
1249 archive_dir_name, commit_id):
1226
1250
@@ -1017,6 +1017,10 b' class HgRemote(RemoteBase):'
1017 }
1017 }
1018
1018
1019 @reraise_safe_exceptions
1019 @reraise_safe_exceptions
1020 def set_head_ref(self, wire, head_name):
1021 pass
1022
1023 @reraise_safe_exceptions
1020 def archive_repo(self, wire, archive_dest_path, kind, mtime, archive_at_path,
1024 def archive_repo(self, wire, archive_dest_path, kind, mtime, archive_at_path,
1021 archive_dir_name, commit_id):
1025 archive_dir_name, commit_id):
1022
1026
@@ -537,6 +537,10 b' class SvnRemote(RemoteBase):'
537 }
537 }
538
538
539 @reraise_safe_exceptions
539 @reraise_safe_exceptions
540 def set_head_ref(self, wire, head_name):
541 pass
542
543 @reraise_safe_exceptions
540 def archive_repo(self, wire, archive_dest_path, kind, mtime, archive_at_path,
544 def archive_repo(self, wire, archive_dest_path, kind, mtime, archive_at_path,
541 archive_dir_name, commit_id):
545 archive_dir_name, commit_id):
542
546
General Comments 0
You need to be logged in to leave comments. Login now