| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -58,6 +58,7 @@ Index | |||
| 58 | 58 | is much slower. The thing is that properly writing a tree from an index involves | |
| 59 | 59 | creating several tree objects, so in the end it might be slower. | |
| 60 | 60 | Hmm, probably its okay to use the command unless we go c(++) | |
| 61 | + * Implement diff so that temporary indices can be used as well ( using file swapping ) | ||
| 61 | 62 | * Proper merge handling with index and working copy | |
| 62 | 63 | * Checkout individual blobs using the index and git-checkout. Blobs can already | |
| 63 | 64 | be written using their stream_data method. | |
@@ -74,6 +75,8 @@ Refs | |||
| 74 | 75 | TagReference.create(repo, name | |
| 75 | 76 | * Ability to rename references and tags | |
| 76 | 77 | * Ability to remove references and tags | |
| 78 | + * Ability to checkout a reference - | ||
| 79 | + * Check whether we are the active reference HEAD.commit == self.commit | ||
| 77 | 80 | ||
| 78 | 81 | Remote | |
| 79 | 82 | ------ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -146,6 +146,22 @@ def from_blob(cls, blob): | |||
| 146 | 146 | return IndexEntry((time, time, 0, 0, blob.mode, 0, 0, blob.size, blob.id, 0, blob.path)) | |
| 147 | 147 | ||
| 148 | 148 | ||
| 149 | + def default_index(func): | ||
| 150 | + """ | ||
| 151 | + Decorator assuring the wrapped method may only run if we are the default | ||
| 152 | + repository index. This is as we rely on git commands that operate | ||
| 153 | + on that index only. | ||
| 154 | + """ | ||
| 155 | + def check_default_index(self, *args, **kwargs): | ||
| 156 | + if self._file_path != self._index_path(): | ||
| 157 | + raise AssertionError( "Cannot call %r on indices that do not represent the default git index" % func.__name__ ) | ||
| 158 | + return func(self, *args, **kwargs) | ||
| 159 | + # END wrpaper method | ||
| 160 | + | ||
| 161 | + check_default_index.__name__ = func.__name__ | ||
| 162 | + return check_default_index | ||
| 163 | + | ||
| 164 | + | ||
| 149 | 165 | class IndexFile(LazyMixin, diff.Diffable): | |
| 150 | 166 | """ | |
| 151 | 167 | Implements an Index that can be manipulated using a native implementation in | |
@@ -487,6 +503,22 @@ def resolve_blobs(self, iter_blobs): | |||
| 487 | 503 | # END for each blob | |
| 488 | 504 | ||
| 489 | 505 | return self | |
| 506 | + | ||
| 507 | + def update(self): | ||
| 508 | + """ | ||
| 509 | + Reread the contents of our index file, discarding all cached information | ||
| 510 | + we might have. | ||
| 511 | + | ||
| 512 | + Note: | ||
| 513 | + This is a possibly dangerious operations as it will discard your changes | ||
| 514 | + to index.endtries | ||
| 515 | + | ||
| 516 | + Returns | ||
| 517 | + self | ||
| 518 | + """ | ||
| 519 | + del(self.entries) | ||
| 520 | + self.entries | ||
| 521 | + return self | ||
| 490 | 522 | ||
| 491 | 523 | def write_tree(self): | |
| 492 | 524 | """ | |
@@ -512,6 +544,88 @@ def _process_diff_args(self, args): | |||
| 512 | 544 | # END remove self | |
| 513 | 545 | return args | |
| 514 | 546 | ||
| 547 | + @default_index | ||
| 548 | + def add(self, items, **kwargs): | ||
| 549 | + """ | ||
| 550 | + Add files from the working copy, specific blobs or IndexEntries | ||
| 551 | + to the index. | ||
| 552 | + | ||
| 553 | + TODO: Its important to specify a way to add symlinks directly, even | ||
| 554 | + on systems that do not support it, like ... erm ... windows. | ||
| 555 | + | ||
| 556 | + ``**kwargs`` | ||
| 557 | + Additional keyword arguments to be passed to git-update-index | ||
| 558 | + | ||
| 559 | + Returns | ||
| 560 | + List(IndexEntries) representing the entries just added | ||
| 561 | + """ | ||
| 562 | + raise NotImplementedError("todo") | ||
| 563 | + | ||
| 564 | + @default_index | ||
| 565 | + def remove(self, items, affect_working_tree=False, **kwargs): | ||
| 566 | + """ | ||
| 567 | + Remove the given file_paths or blobs from the index and optionally from | ||
| 568 | + the working tree as well. | ||
| 569 | + | ||
| 570 | + ``items`` | ||
| 571 | + TODO | ||
| 572 | + | ||
| 573 | + ``affect_working_tree`` | ||
| 574 | + If True, the entry will also be removed from the working tree, physically | ||
| 575 | + removing the respective file. This may fail if there are uncommited changes | ||
| 576 | + in it. | ||
| 577 | + | ||
| 578 | + ``**kwargs`` | ||
| 579 | + Additional keyword arguments to be passed to git-update-index | ||
| 580 | + | ||
| 581 | + Returns | ||
| 582 | + self | ||
| 583 | + """ | ||
| 584 | + raise NotImplementedError("todo") | ||
| 585 | + return self | ||
| 586 | + | ||
| 587 | + @default_index | ||
| 588 | + def commit(self, message=None, parent_commits=None, **kwargs): | ||
| 589 | + """ | ||
| 590 | + Commit the current index, creating a commit object. | ||
| 591 | + | ||
| 592 | + ``message`` | ||
| 593 | + Commit message | ||
| 594 | + | ||
| 595 | + ``parent_commits`` | ||
| 596 | + Optional Commit objects to use as parents for the new commit. | ||
| 597 | + If None or empty, the current head commit will be the parent of the | ||
| 598 | + new commit object | ||
| 599 | + | ||
| 600 | + ``**kwargs`` | ||
| 601 | + Additional keyword arguments passed to git-commit | ||
| 602 | + | ||
| 603 | + Returns | ||
| 604 | + Commit object representing the new commit | ||
| 605 | + """ | ||
| 606 | + raise NotImplementedError("todo") | ||
| 607 | + | ||
| 608 | + @default_index | ||
| 609 | + def reset(self, commit='HEAD', working_tree=False, **kwargs): | ||
| 610 | + """ | ||
| 611 | + Reset the index to reflect the tree at the given commit. This will not | ||
| 612 | + adjust our HEAD reference as opposed to HEAD.reset. | ||
| 613 | + | ||
| 614 | + ``commit`` | ||
| 615 | + Revision, Reference or Commit specifying the commit we should represent. | ||
| 616 | + If you want to specify a tree only, use IndexFile.from_tree and overwrite | ||
| 617 | + the default index. | ||
| 618 | + | ||
| 619 | + ``working_tree`` | ||
| 620 | + If True, the files in the working tree will reflect the changed index. | ||
| 621 | + If False, the working tree will not be touched | ||
| 622 | + | ||
| 623 | + ``**kwargs`` | ||
| 624 | + Additional keyword arguments passed to git-reset | ||
| 625 | + """ | ||
| 626 | + raise NotImplementedError("todo") | ||
| 627 | + | ||
| 628 | + @default_index | ||
| 515 | 629 | def diff(self, other=diff.Diffable.Index, paths=None, create_patch=False, **kwargs): | |
| 516 | 630 | """ | |
| 517 | 631 | Diff this index against the working copy or a Tree or Commit object | |
@@ -523,10 +637,6 @@ def diff(self, other=diff.Diffable.Index, paths=None, create_patch=False, **kwar | |||
| 523 | 637 | Will only work with indices that represent the default git index as | |
| 524 | 638 | they have not been initialized with a stream. | |
| 525 | 639 | """ | |
| 526 | - # perhaps we shouldn't diff these at all, or we swap them in place first | ||
| 527 | - if self._file_path != self._index_path(): | ||
| 528 | - raise AssertionError( "Cannot diff custom indices as they do not represent the default git index" ) | ||
| 529 | - | ||
| 530 | 640 | # index against index is always empty | |
| 531 | 641 | if other is self.Index: | |
| 532 | 642 | return diff.DiffIndex() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -322,7 +322,8 @@ def reset(self, commit='HEAD', index=True, working_tree = False, | |||
| 322 | 322 | paths=None, **kwargs): | |
| 323 | 323 | """ | |
| 324 | 324 | Reset our HEAD to the given commit optionally synchronizing | |
| 325 | - the index and working tree. | ||
| 325 | + the index and working tree. The reference we refer to will be set to | ||
| 326 | + commit as well. | ||
| 326 | 327 | ||
| 327 | 328 | ``commit`` | |
| 328 | 329 | Commit object, Reference Object or string identifying a revision we | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,6 +26,11 @@ def test_index_file_base(self): | |||
| 26 | 26 | val = getattr(entry, attr) | |
| 27 | 27 | # END for each method | |
| 28 | 28 | ||
| 29 | + # test update | ||
| 30 | + entries = index.entries | ||
| 31 | + assert isinstance(index.update(), IndexFile) | ||
| 32 | + assert entries is not index.entries | ||
| 33 | + | ||
| 29 | 34 | # test stage | |
| 30 | 35 | index_merge = IndexFile(self.rorepo, fixture_path("index_merge")) | |
| 31 | 36 | assert len(index_merge.entries) == 106 | |
@@ -140,3 +145,11 @@ def test_index_file_diffing(self, rw_repo): | |||
| 140 | 145 | ||
| 141 | 146 | # against something unusual | |
| 142 | 147 | self.failUnlessRaises(ValueError, index.diff, int) | |
| 148 | + | ||
| 149 | + self.fail( "Test IndexFile.reset" ) | ||
| 150 | + | ||
| 151 | + @with_rw_repo('0.1.6') | ||
| 152 | + def test_index_mutation(self, rw_repo): | ||
| 153 | + # add / remove / commit / Working Tree Handling | ||
| 154 | + self.fail( "add, remove, commit, working tree handling" ) | ||
| 155 | + | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments