Mercurial > hgsubversion
comparison hg_delta_editor.py @ 147:22162380c4b9
Improve branch closing in the case of a single-rev replacement of one branch
with another. Includes a test case.
| author | Augie Fackler <durin42@gmail.com> |
|---|---|
| date | Sat, 20 Dec 2008 19:04:59 -0600 |
| parents | 4da9f20aef01 |
| children | 6fa97cfbf62f |
comparison
equal
deleted
inserted
replaced
| 146:4da9f20aef01 | 147:22162380c4b9 |
|---|---|
| 359 continue | 359 continue |
| 360 p, b = self._path_and_branch_for_path(f) | 360 p, b = self._path_and_branch_for_path(f) |
| 361 if b not in branch_batches: | 361 if b not in branch_batches: |
| 362 branch_batches[b] = [] | 362 branch_batches[b] = [] |
| 363 branch_batches[b].append((p, f)) | 363 branch_batches[b].append((p, f)) |
| 364 # close any branches that need it | |
| 365 closed_revs = set() | |
| 366 for branch in self.branches_to_delete: | |
| 367 closed = revlog.nullid | |
| 368 if 'closed-branches' in self.repo.branchtags(): | |
| 369 closed = self.repo['closed-branches'].node() | |
| 370 branchedits = sorted(filter(lambda x: x[0][1] == branch and x[0][0] < rev.revnum, | |
| 371 self.revmap.iteritems()), reverse=True) | |
| 372 if len(branchedits) < 1: | |
| 373 # can't close a branch that never existed | |
| 374 continue | |
| 375 ha = branchedits[0][1] | |
| 376 closed_revs.add(ha) | |
| 377 # self.get_parent_revision(rev.revnum, branch) | |
| 378 parentctx = self.repo.changectx(ha) | |
| 379 parents = (ha, closed) | |
| 380 def del_all_files(*args): | |
| 381 raise IOError | |
| 382 files = parentctx.manifest().keys() | |
| 383 current_ctx = context.memctx(self.repo, | |
| 384 parents, | |
| 385 rev.message or ' ', | |
| 386 files, | |
| 387 del_all_files, | |
| 388 '%s%s' % (rev.author, | |
| 389 self.author_host), | |
| 390 date, | |
| 391 {'branch': 'closed-branches'}) | |
| 392 new_hash = self.repo.commitctx(current_ctx) | |
| 393 self.ui.status('Marked branch %s as closed.\n' % (branch or | |
| 394 'default')) | |
| 364 for branch, files in branch_batches.iteritems(): | 395 for branch, files in branch_batches.iteritems(): |
| 365 if branch in self.commit_branches_empty and files: | 396 if branch in self.commit_branches_empty and files: |
| 366 del self.commit_branches_empty[branch] | 397 del self.commit_branches_empty[branch] |
| 367 extra = {} | 398 extra = {} |
| 368 files = dict(files) | 399 files = dict(files) |
| 369 | 400 |
| 370 parents = (self.get_parent_revision(rev.revnum, branch), | 401 parents = (self.get_parent_revision(rev.revnum, branch), |
| 371 revlog.nullid) | 402 revlog.nullid) |
| 403 if parents[0] in closed_revs and branch in self.branches_to_delete: | |
| 404 continue | |
| 372 if branch is not None: | 405 if branch is not None: |
| 373 if (branch not in self.branches | 406 if (branch not in self.branches |
| 374 and branch not in self.repo.branchtags()): | 407 and branch not in self.repo.branchtags()): |
| 375 continue | 408 continue |
| 376 extra['branch'] = branch | 409 extra['branch'] = branch |
| 377 if (branch in self.branches_to_delete): | |
| 378 continue | |
| 379 parent_ctx = self.repo.changectx(parents[0]) | 410 parent_ctx = self.repo.changectx(parents[0]) |
| 380 def filectxfn(repo, memctx, path): | 411 def filectxfn(repo, memctx, path): |
| 381 current_file = files[path] | 412 current_file = files[path] |
| 382 if current_file in self.deleted_files: | 413 if current_file in self.deleted_files: |
| 383 raise IOError() | 414 raise IOError() |
| 408 self.ui.status('committed as %s on branch %s\n' % | 439 self.ui.status('committed as %s on branch %s\n' % |
| 409 (node.hex(new_hash), (branch or 'default'))) | 440 (node.hex(new_hash), (branch or 'default'))) |
| 410 if (rev.revnum, branch) not in self.revmap: | 441 if (rev.revnum, branch) not in self.revmap: |
| 411 self.add_to_revmap(rev.revnum, branch, new_hash) | 442 self.add_to_revmap(rev.revnum, branch, new_hash) |
| 412 # now we handle branches that need to be committed without any files | 443 # now we handle branches that need to be committed without any files |
| 413 for branch in self.branches_to_delete: | |
| 414 closed = revlog.nullid | |
| 415 if 'closed-branches' in self.repo.branchtags(): | |
| 416 closed = self.repo['closed-branches'].node() | |
| 417 ha = self.get_parent_revision(rev.revnum, branch) | |
| 418 parentctx = self.repo.changectx(ha) | |
| 419 if parentctx.children(): | |
| 420 continue | |
| 421 parents = (ha, closed) | |
| 422 def del_all_files(*args): | |
| 423 raise IOError | |
| 424 files = parentctx.manifest().keys() | |
| 425 current_ctx = context.memctx(self.repo, | |
| 426 parents, | |
| 427 rev.message or ' ', | |
| 428 files, | |
| 429 del_all_files, | |
| 430 '%s%s' % (rev.author, | |
| 431 self.author_host), | |
| 432 date, | |
| 433 {'branch': 'closed-branches'}) | |
| 434 new_hash = self.repo.commitctx(current_ctx) | |
| 435 self.ui.status('Marked branch %s as closed.\n' % (branch or 'default')) | |
| 436 for branch in self.commit_branches_empty: | 444 for branch in self.commit_branches_empty: |
| 437 ha = self.get_parent_revision(rev.revnum, branch) | 445 ha = self.get_parent_revision(rev.revnum, branch) |
| 438 if ha == node.nullid: | 446 if ha == node.nullid: |
| 439 continue | 447 continue |
| 440 parent_ctx = self.repo.changectx(ha) | 448 parent_ctx = self.repo.changectx(ha) |
