Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit61f3db7

Browse files
committed
Removed ORIG_HEAD handling which was downright wrong. ORIG_HEAD gets only set during merge and rebase, and probably everything that changes the ref more drastically. Probably I have to reread that. What needs to be adjusted though is the reflog
1 parenta21a9f6 commit61f3db7

File tree

5 files changed

+47
-71
lines changed

5 files changed

+47
-71
lines changed

‎refs/head.py‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,6 @@ def orig_head(self):
2929
to contain the previous value of HEAD"""
3030
returnSymbolicReference(self.repo,self._ORIG_HEAD_NAME)
3131

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-
ifself.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-
4932
defreset(self,commit='HEAD',index=True,working_tree=False,
5033
paths=None,**kwargs):
5134
"""Reset our HEAD to the given commit optionally synchronizing

‎refs/log.py‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
fromgit.utilimport (
22
join_path,
33
Actor,
4+
LockedFD,
45
)
56

67
fromgitdb.utilimport (
@@ -173,13 +174,16 @@ def iter_entries(cls, stream):
173174
defto_file(self,filepath):
174175
"""Write the contents of the reflog instance to a file at the given filepath.
175176
: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)
178179
try:
179180
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
183187

184188
defappend_entry(self,oldbinsha,newbinsha,message,write=True):
185189
"""Append a new log entry to the revlog, changing it in place.

‎refs/symbolic.py‎

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
exists,
1414
isfile,
1515
rename,
16-
hex_to_bin
16+
hex_to_bin,
17+
LockedFD
1718
)
1819

1920
fromlogimportRefLog
@@ -181,11 +182,13 @@ def _get_reference(self):
181182
raiseTypeError("%s is a detached symbolic reference as it points to %r"% (self,sha))
182183
returnself.from_path(self.repo,target_ref_path)
183184

184-
def_set_reference(self,ref):
185+
def_set_reference(self,ref,msg=None):
185186
"""Set ourselves to the given ref. It will stay a symbol if the ref is a Reference.
186187
Otherwise we try to get a commit from it using our interface.
187188
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"""
189192
write_value=None
190193
ifisinstance(ref,SymbolicReference):
191194
write_value="ref: %s"%ref.path
@@ -205,22 +208,6 @@ def _set_reference(self, ref):
205208
# END end try string
206209
# END try commit attribute
207210

208-
# maintain the orig-head if we are currently checked-out
209-
head=HEAD(self.repo)
210-
try:
211-
ifhead.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-
exceptValueError:
217-
pass
218-
#END exception handling
219-
# END if we are checked-out
220-
exceptTypeError:
221-
pass
222-
# END handle detached heads
223-
224211
# if we are writing a ref, use symbolic ref to get the reflog and more
225212
# checking
226213
# Otherwise we detach it and have to do it manually. Besides, this works

‎test/test_index.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,6 @@ def mixed_iterator():
422422
# same index, no parents
423423
commit_message="index without parents"
424424
commit_no_parents=index.commit(commit_message,parent_commits=list(),head=True)
425-
assertSymbolicReference(rw_repo,'ORIG_HEAD').commit==cur_commit
426425
assertcommit_no_parents.message==commit_message
427426
assertlen(commit_no_parents.parents)==0
428427
assertcur_head.commit==commit_no_parents

‎test/test_refs.py‎

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -95,35 +95,38 @@ def test_heads(self, rwrepo):
9595
asserthead.tracking_branch()isNone
9696
# END for each head
9797

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-
assertorig_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-
assertorig_head.commit==pcommit
111-
asserthead.commit==cur_commit==cur_head.commit
112-
113-
cur_head.commit=pcommit
114-
asserthead.commit==pcommit
115-
assertorig_head.commit==cur_commit
116-
117-
# with automatic dereferencing
118-
head.commit=cur_commit
119-
assertorig_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-
assertother_head.commit==pcommit
124-
assertorig_head.commit==pcommit
125-
other_head.commit=pcommit.parents[0]
126-
assertorig_head.commit==pcommit
98+
# verify REFLOG gets altered
99+
ifFalse:
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+
assertorig_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+
assertorig_head.commit==pcommit
112+
asserthead.commit==cur_commit==cur_head.commit
113+
114+
cur_head.commit=pcommit
115+
asserthead.commit==pcommit
116+
assertorig_head.commit==cur_commit
117+
118+
# with automatic dereferencing
119+
head.commit=cur_commit
120+
assertorig_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+
assertother_head.commit==pcommit
125+
assertorig_head.commit==pcommit
126+
other_head.commit=pcommit.parents[0]
127+
assertorig_head.commit==pcommit
128+
129+
# TODO: Need changing a ref changes HEAD reflog as well if it pointed to it
127130

128131

129132
deftest_refs(self):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp