Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
1f87fa35
Commit
1f87fa35
authored
Oct 09, 2012
by
nulltoken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reflog: fix bogus removal of reflog entries
parent
27e3c583
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
30 deletions
+21
-30
src/reflog.c
+6
-6
tests-clar/refs/reflog/drop.c
+15
-24
No files found.
src/reflog.c
View file @
1f87fa35
...
@@ -469,18 +469,18 @@ int git_reflog_drop(
...
@@ -469,18 +469,18 @@ int git_reflog_drop(
if
(
!
rewrite_previous_entry
)
if
(
!
rewrite_previous_entry
)
return
0
;
return
0
;
/* No need to rewrite anything when removing the
firs
t entry */
/* No need to rewrite anything when removing the
most recen
t entry */
if
(
idx
==
0
)
if
(
idx
==
entrycount
-
1
)
return
0
;
return
0
;
/* There are no more entries in the log */
/* There are no more entries in the log */
if
(
entrycount
==
1
)
if
(
entrycount
==
1
)
return
0
;
return
0
;
entry
=
(
git_reflog_entry
*
)
git_reflog_entry_byindex
(
reflog
,
idx
-
1
);
entry
=
(
git_reflog_entry
*
)
git_reflog_entry_byindex
(
reflog
,
idx
);
/* If the
la
st entry has just been removed... */
/* If the
olde
st entry has just been removed... */
if
(
idx
==
entrycount
-
1
)
{
if
(
idx
==
0
)
{
/* ...clear the oid_old member of the "new" last entry */
/* ...clear the oid_old member of the "new" last entry */
if
(
git_oid_fromstr
(
&
entry
->
oid_old
,
GIT_OID_HEX_ZERO
)
<
0
)
if
(
git_oid_fromstr
(
&
entry
->
oid_old
,
GIT_OID_HEX_ZERO
)
<
0
)
return
-
1
;
return
-
1
;
...
@@ -488,7 +488,7 @@ int git_reflog_drop(
...
@@ -488,7 +488,7 @@ int git_reflog_drop(
return
0
;
return
0
;
}
}
previous
=
(
git_reflog_entry
*
)
git_reflog_entry_byindex
(
reflog
,
idx
);
previous
=
(
git_reflog_entry
*
)
git_reflog_entry_byindex
(
reflog
,
idx
-
1
);
git_oid_cpy
(
&
entry
->
oid_old
,
&
previous
->
oid_cur
);
git_oid_cpy
(
&
entry
->
oid_old
,
&
previous
->
oid_cur
);
return
0
;
return
0
;
...
...
tests-clar/refs/reflog/drop.c
View file @
1f87fa35
...
@@ -43,57 +43,48 @@ void test_refs_reflog_drop__can_drop_an_entry(void)
...
@@ -43,57 +43,48 @@ void test_refs_reflog_drop__can_drop_an_entry(void)
void
test_refs_reflog_drop__can_drop_an_entry_and_rewrite_the_log_history
(
void
)
void
test_refs_reflog_drop__can_drop_an_entry_and_rewrite_the_log_history
(
void
)
{
{
const
git_reflog_entry
*
before_
previous
,
*
before_nex
t
;
const
git_reflog_entry
*
before_
curren
t
;
const
git_reflog_entry
*
after_
nex
t
;
const
git_reflog_entry
*
after_
curren
t
;
git_oid
before_
next_old
_oid
;
git_oid
before_
current_old_oid
,
before_current_cur
_oid
;
cl_assert
(
entrycount
>
4
);
cl_assert
(
entrycount
>
4
);
before_
previous
=
git_reflog_entry_byindex
(
g_reflog
,
3
);
before_
current
=
git_reflog_entry_byindex
(
g_reflog
,
2
);
before_next
=
git_reflog_entry_byindex
(
g_reflog
,
1
);
git_oid_cpy
(
&
before_current_old_oid
,
&
before_current
->
oid_old
);
git_oid_cpy
(
&
before_
next_old_oid
,
&
before_next
->
oid_old
);
git_oid_cpy
(
&
before_
current_cur_oid
,
&
before_current
->
oid_cur
);
cl_git_pass
(
git_reflog_drop
(
g_reflog
,
2
,
1
));
cl_git_pass
(
git_reflog_drop
(
g_reflog
,
2
,
1
));
cl_assert_equal_i
(
entrycount
-
1
,
git_reflog_entrycount
(
g_reflog
));
cl_assert_equal_i
(
entrycount
-
1
,
git_reflog_entrycount
(
g_reflog
));
after_
next
=
git_reflog_entry_byindex
(
g_reflog
,
1
);
after_
current
=
git_reflog_entry_byindex
(
g_reflog
,
2
);
cl_assert_equal_i
(
0
,
git_oid_cmp
(
&
before_next
->
oid_cur
,
&
after_next
->
oid_cur
));
cl_assert_equal_i
(
0
,
git_oid_cmp
(
&
before_current_old_oid
,
&
after_current
->
oid_old
));
cl_assert
(
git_oid_cmp
(
&
before_next_old_oid
,
&
after_next
->
oid_old
)
!=
0
);
cl_assert
(
0
!=
git_oid_cmp
(
&
before_current_cur_oid
,
&
after_current
->
oid_cur
));
cl_assert_equal_i
(
0
,
git_oid_cmp
(
&
before_previous
->
oid_cur
,
&
after_next
->
oid_old
));
}
}
void
test_refs_reflog_drop__can_drop_the_first_entry
(
void
)
void
test_refs_reflog_drop__can_drop_the_oldest_entry
(
void
)
{
cl_assert
(
entrycount
>
2
);
cl_git_pass
(
git_reflog_drop
(
g_reflog
,
0
,
0
));
cl_assert_equal_i
(
entrycount
-
1
,
git_reflog_entrycount
(
g_reflog
));
}
void
test_refs_reflog_drop__can_drop_the_last_entry
(
void
)
{
{
const
git_reflog_entry
*
entry
;
const
git_reflog_entry
*
entry
;
cl_assert
(
entrycount
>
2
);
cl_assert
(
entrycount
>
2
);
cl_git_pass
(
git_reflog_drop
(
g_reflog
,
entrycount
-
1
,
0
));
cl_git_pass
(
git_reflog_drop
(
g_reflog
,
0
,
0
));
cl_assert_equal_i
(
entrycount
-
1
,
git_reflog_entrycount
(
g_reflog
));
cl_assert_equal_i
(
entrycount
-
1
,
git_reflog_entrycount
(
g_reflog
));
entry
=
git_reflog_entry_byindex
(
g_reflog
,
entrycount
-
2
);
entry
=
git_reflog_entry_byindex
(
g_reflog
,
0
);
cl_assert
(
git_oid_streq
(
&
entry
->
oid_old
,
GIT_OID_HEX_ZERO
)
!=
0
);
cl_assert
(
git_oid_streq
(
&
entry
->
oid_old
,
GIT_OID_HEX_ZERO
)
!=
0
);
}
}
void
test_refs_reflog_drop__can_drop_the_
la
st_entry_and_rewrite_the_log_history
(
void
)
void
test_refs_reflog_drop__can_drop_the_
olde
st_entry_and_rewrite_the_log_history
(
void
)
{
{
const
git_reflog_entry
*
entry
;
const
git_reflog_entry
*
entry
;
cl_assert
(
entrycount
>
2
);
cl_assert
(
entrycount
>
2
);
cl_git_pass
(
git_reflog_drop
(
g_reflog
,
entrycount
-
1
,
1
));
cl_git_pass
(
git_reflog_drop
(
g_reflog
,
0
,
1
));
cl_assert_equal_i
(
entrycount
-
1
,
git_reflog_entrycount
(
g_reflog
));
cl_assert_equal_i
(
entrycount
-
1
,
git_reflog_entrycount
(
g_reflog
));
entry
=
git_reflog_entry_byindex
(
g_reflog
,
entrycount
-
2
);
entry
=
git_reflog_entry_byindex
(
g_reflog
,
0
);
cl_assert
(
git_oid_streq
(
&
entry
->
oid_old
,
GIT_OID_HEX_ZERO
)
==
0
);
cl_assert
(
git_oid_streq
(
&
entry
->
oid_old
,
GIT_OID_HEX_ZERO
)
==
0
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment