| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a21a9f6 commit 61f3db7
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,23 +29,6 @@ def orig_head(self): | |||
| 29 | 29 | to contain the previous value of HEAD""" | |
| 30 | 30 | return SymbolicReference(self.repo, self._ORIG_HEAD_NAME) | |
| 31 | 31 | ||
| 32 | - def _set_reference(self, ref): | ||
| 33 | - """If someone changes the reference through us, we must manually update | ||
| 34 | - the ORIG_HEAD if we are detached. The underlying implementation can only | ||
| 35 | - handle un-detached heads as it has to check whether the current head | ||
| 36 | - is the checked-out one""" | ||
| 37 | - if self.is_detached: | ||
| 38 | - prev_commit = self.commit | ||
| 39 | - super(HEAD, self)._set_reference(ref) | ||
| 40 | - SymbolicReference.create(self.repo, self._ORIG_HEAD_NAME, prev_commit, force=True) | ||
| 41 | - else: | ||
| 42 | - super(HEAD, self)._set_reference(ref) | ||
| 43 | - # END handle detached mode | ||
| 44 | - | ||
| 45 | - # aliased reference | ||
| 46 | - reference = property(SymbolicReference._get_reference, _set_reference, doc="Returns the Reference we point to") | ||
| 47 | - ref = reference | ||
| 48 | - | ||
| 49 | 32 | def reset(self, commit='HEAD', index=True, working_tree = False, | |
| 50 | 33 | paths=None, **kwargs): | |
| 51 | 34 | """Reset our HEAD to the given commit optionally synchronizing | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | from git.util import ( | |
| 2 | 2 | join_path, | |
| 3 | 3 | Actor, | |
| 4 | + LockedFD, | ||
| 4 | 5 | ) | |
| 5 | 6 | ||
| 6 | 7 | from gitdb.util import ( | |
@@ -173,13 +174,16 @@ def iter_entries(cls, stream): | |||
| 173 | 174 | def to_file(self, filepath): | |
| 174 | 175 | """Write the contents of the reflog instance to a file at the given filepath. | |
| 175 | 176 | :param filepath: path to file, parent directories are assumed to exist""" | |
| 176 | - # TODO: Use locked fd | ||
| 177 | - fp = open(filepath, 'wb') | ||
| 177 | + lfd = LockedFD(filepath) | ||
| 178 | + fp = lfd.open(write=True, stream=True) | ||
| 178 | 179 | try: | |
| 179 | 180 | self._serialize(fp) | |
| 180 | - finally: | ||
| 181 | - fp.close() | ||
| 182 | - #END handle file streams | ||
| 181 | + lfd.commit() | ||
| 182 | + except: | ||
| 183 | + # on failure it rolls back automatically, but we make it clear | ||
| 184 | + lfd.rollback() | ||
| 185 | + raise | ||
| 186 | + #END handle change | ||
| 183 | 187 | ||
| 184 | 188 | def append_entry(self, oldbinsha, newbinsha, message, write=True): | |
| 185 | 189 | """Append a new log entry to the revlog, changing it in place. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,8 @@ | |||
| 13 | 13 | exists, | |
| 14 | 14 | isfile, | |
| 15 | 15 | rename, | |
| 16 | - hex_to_bin | ||
| 16 | + hex_to_bin, | ||
| 17 | + LockedFD | ||
| 17 | 18 | ) | |
| 18 | 19 | ||
| 19 | 20 | from log import RefLog | |
@@ -181,11 +182,13 @@ def _get_reference(self): | |||
| 181 | 182 | raise TypeError("%s is a detached symbolic reference as it points to %r" % (self, sha)) | |
| 182 | 183 | return self.from_path(self.repo, target_ref_path) | |
| 183 | 184 | ||
| 184 | - def _set_reference(self, ref): | ||
| 185 | + def _set_reference(self, ref, msg = None): | ||
| 185 | 186 | """Set ourselves to the given ref. It will stay a symbol if the ref is a Reference. | |
| 186 | 187 | Otherwise we try to get a commit from it using our interface. | |
| 187 | 188 | ||
| 188 | - Strings are allowed but will be checked to be sure we have a commit""" | ||
| 189 | + Strings are allowed but will be checked to be sure we have a commit | ||
| 190 | + :param msg: If set to a string, the message will be used in the reflog. | ||
| 191 | + Otherwise, a reflog entry is not written for the changed reference""" | ||
| 189 | 192 | write_value = None | |
| 190 | 193 | if isinstance(ref, SymbolicReference): | |
| 191 | 194 | write_value = "ref: %s" % ref.path | |
@@ -205,22 +208,6 @@ def _set_reference(self, ref): | |||
| 205 | 208 | # END end try string | |
| 206 | 209 | # END try commit attribute | |
| 207 | 210 | ||
| 208 | - # maintain the orig-head if we are currently checked-out | ||
| 209 | - head = HEAD(self.repo) | ||
| 210 | - try: | ||
| 211 | - if head.ref == self: | ||
| 212 | - try: | ||
| 213 | - # TODO: implement this atomically, if we fail below, orig_head is at an incorrect spot | ||
| 214 | - # Enforce the creation of ORIG_HEAD | ||
| 215 | - SymbolicReference.create(self.repo, head.orig_head().name, self.commit, force=True) | ||
| 216 | - except ValueError: | ||
| 217 | - pass | ||
| 218 | - #END exception handling | ||
| 219 | - # END if we are checked-out | ||
| 220 | - except TypeError: | ||
| 221 | - pass | ||
| 222 | - # END handle detached heads | ||
| 223 | - | ||
| 224 | 211 | # if we are writing a ref, use symbolic ref to get the reflog and more | |
| 225 | 212 | # checking | |
| 226 | 213 | # Otherwise we detach it and have to do it manually. Besides, this works | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -422,7 +422,6 @@ def mixed_iterator(): | |||
| 422 | 422 | # same index, no parents | |
| 423 | 423 | commit_message = "index without parents" | |
| 424 | 424 | commit_no_parents = index.commit(commit_message, parent_commits=list(), head=True) | |
| 425 | - assert SymbolicReference(rw_repo, 'ORIG_HEAD').commit == cur_commit | ||
| 426 | 425 | assert commit_no_parents.message == commit_message | |
| 427 | 426 | assert len(commit_no_parents.parents) == 0 | |
| 428 | 427 | assert cur_head.commit == commit_no_parents | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -95,35 +95,38 @@ def test_heads(self, rwrepo): | |||
| 95 | 95 | assert head.tracking_branch() is None | |
| 96 | 96 | # END for each head | |
| 97 | 97 | ||
| 98 | - # verify ORIG_HEAD gets set for detached heads | ||
| 99 | - head = rwrepo.head | ||
| 100 | - orig_head = head.orig_head() | ||
| 101 | - cur_head = head.ref | ||
| 102 | - cur_commit = cur_head.commit | ||
| 103 | - pcommit = cur_head.commit.parents[0].parents[0] | ||
| 104 | - head.ref = pcommit # detach head | ||
| 105 | - assert orig_head.commit == cur_commit | ||
| 106 | - | ||
| 107 | - # even if we set it through its reference - chaning the ref | ||
| 108 | - # will adjust the orig_head, which still points to cur_commit | ||
| 109 | - head.ref = cur_head | ||
| 110 | - assert orig_head.commit == pcommit | ||
| 111 | - assert head.commit == cur_commit == cur_head.commit | ||
| 112 | - | ||
| 113 | - cur_head.commit = pcommit | ||
| 114 | - assert head.commit == pcommit | ||
| 115 | - assert orig_head.commit == cur_commit | ||
| 116 | - | ||
| 117 | - # with automatic dereferencing | ||
| 118 | - head.commit = cur_commit | ||
| 119 | - assert orig_head.commit == pcommit | ||
| 120 | - | ||
| 121 | - # changing branches which are not checked out doesn't affect the ORIG_HEAD | ||
| 122 | - other_head = Head.create(rwrepo, 'mynewhead', pcommit) | ||
| 123 | - assert other_head.commit == pcommit | ||
| 124 | - assert orig_head.commit == pcommit | ||
| 125 | - other_head.commit = pcommit.parents[0] | ||
| 126 | - assert orig_head.commit == pcommit | ||
| 98 | + # verify REFLOG gets altered | ||
| 99 | + if False: | ||
| 100 | + head = rwrepo.head | ||
| 101 | + orig_head = head.orig_head() | ||
| 102 | + cur_head = head.ref | ||
| 103 | + cur_commit = cur_head.commit | ||
| 104 | + pcommit = cur_head.commit.parents[0].parents[0] | ||
| 105 | + head.ref = pcommit # detach head | ||
| 106 | + assert orig_head.commit == cur_commit | ||
| 107 | + | ||
| 108 | + # even if we set it through its reference - chaning the ref | ||
| 109 | + # will adjust the orig_head, which still points to cur_commit | ||
| 110 | + head.ref = cur_head | ||
| 111 | + assert orig_head.commit == pcommit | ||
| 112 | + assert head.commit == cur_commit == cur_head.commit | ||
| 113 | + | ||
| 114 | + cur_head.commit = pcommit | ||
| 115 | + assert head.commit == pcommit | ||
| 116 | + assert orig_head.commit == cur_commit | ||
| 117 | + | ||
| 118 | + # with automatic dereferencing | ||
| 119 | + head.commit = cur_commit | ||
| 120 | + assert orig_head.commit == pcommit | ||
| 121 | + | ||
| 122 | + # changing branches which are not checked out doesn't affect the ORIG_HEAD | ||
| 123 | + other_head = Head.create(rwrepo, 'mynewhead', pcommit) | ||
| 124 | + assert other_head.commit == pcommit | ||
| 125 | + assert orig_head.commit == pcommit | ||
| 126 | + other_head.commit = pcommit.parents[0] | ||
| 127 | + assert orig_head.commit == pcommit | ||
| 128 | + | ||
| 129 | + # TODO: Need changing a ref changes HEAD reflog as well if it pointed to it | ||
| 127 | 130 | ||
| 128 | 131 | ||
| 129 | 132 | def test_refs(self): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments