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
0174794a
Commit
0174794a
authored
Aug 21, 2013
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reflog: bring _append and _drop back to the frontend
These functions act purely on the reflog data structure.
parent
d274deea
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
129 deletions
+86
-129
include/git2/sys/refdb_backend.h
+0
-12
src/refdb_fs.c
+0
-103
src/reflog.c
+86
-14
No files found.
include/git2/sys/refdb_backend.h
View file @
0174794a
...
...
@@ -131,23 +131,11 @@ struct git_refdb_backend {
int
(
*
reflog_write
)(
git_refdb_backend
*
backend
,
git_reflog
*
reflog
);
/**
* Append an entry to the given reflog
*/
int
(
*
reflog_append
)(
git_refdb_backend
*
backend
,
git_reflog
*
reflog
,
const
git_oid
*
new_oid
,
const
git_signature
*
committer
,
const
char
*
msg
);
/**
* Rename a reflog
*/
int
(
*
reflog_rename
)(
git_refdb_backend
*
_backend
,
const
char
*
old_name
,
const
char
*
new_name
);
/**
* Drop an entry from the reflog
*/
int
(
*
reflog_drop
)(
git_refdb_backend
*
_backend
,
git_reflog
*
reflog
,
size_t
idx
,
int
rewrite_previous_entry
);
/**
* Remove a reflog.
*/
int
(
*
reflog_delete
)(
git_refdb_backend
*
backend
,
const
char
*
name
);
...
...
src/refdb_fs.c
View file @
0174794a
...
...
@@ -1308,56 +1308,6 @@ success:
return
error
;
}
static
int
refdb_reflog_fs__append
(
git_refdb_backend
*
_backend
,
git_reflog
*
reflog
,
const
git_oid
*
new_oid
,
const
git_signature
*
committer
,
const
char
*
msg
)
{
git_reflog_entry
*
entry
;
const
git_reflog_entry
*
previous
;
const
char
*
newline
;
assert
(
_backend
&&
reflog
&&
new_oid
&&
committer
);
entry
=
git__calloc
(
1
,
sizeof
(
git_reflog_entry
));
GITERR_CHECK_ALLOC
(
entry
);
if
((
entry
->
committer
=
git_signature_dup
(
committer
))
==
NULL
)
goto
cleanup
;
if
(
msg
!=
NULL
)
{
if
((
entry
->
msg
=
git__strdup
(
msg
))
==
NULL
)
goto
cleanup
;
newline
=
strchr
(
msg
,
'\n'
);
if
(
newline
)
{
if
(
newline
[
1
]
!=
'\0'
)
{
giterr_set
(
GITERR_INVALID
,
"Reflog message cannot contain newline"
);
goto
cleanup
;
}
entry
->
msg
[
newline
-
msg
]
=
'\0'
;
}
}
previous
=
git_reflog_entry_byindex
(
reflog
,
0
);
if
(
previous
==
NULL
)
git_oid_fromstr
(
&
entry
->
oid_old
,
GIT_OID_HEX_ZERO
);
else
git_oid_cpy
(
&
entry
->
oid_old
,
&
previous
->
oid_cur
);
git_oid_cpy
(
&
entry
->
oid_cur
,
new_oid
);
if
(
git_vector_insert
(
&
reflog
->
entries
,
entry
)
<
0
)
goto
cleanup
;
return
0
;
cleanup
:
git_reflog_entry__free
(
entry
);
return
-
1
;
}
static
int
refdb_reflog_fs__rename
(
git_refdb_backend
*
_backend
,
const
char
*
old_name
,
const
char
*
new_name
)
{
int
error
=
0
,
fd
;
...
...
@@ -1434,57 +1384,6 @@ cleanup:
return
error
;
}
static
int
refdb_reflog_fs__drop
(
git_refdb_backend
*
_backend
,
git_reflog
*
reflog
,
size_t
idx
,
int
rewrite_previous_entry
)
{
size_t
entrycount
;
git_reflog_entry
*
entry
,
*
previous
;
assert
(
_backend
&&
reflog
);
entrycount
=
git_reflog_entrycount
(
reflog
);
entry
=
(
git_reflog_entry
*
)
git_reflog_entry_byindex
(
reflog
,
idx
);
if
(
entry
==
NULL
)
{
giterr_set
(
GITERR_REFERENCE
,
"No reflog entry at index "
PRIuZ
,
idx
);
return
GIT_ENOTFOUND
;
}
git_reflog_entry__free
(
entry
);
if
(
git_vector_remove
(
&
reflog
->
entries
,
reflog_inverse_index
(
idx
,
entrycount
))
<
0
)
return
-
1
;
if
(
!
rewrite_previous_entry
)
return
0
;
/* No need to rewrite anything when removing the most recent entry */
if
(
idx
==
0
)
return
0
;
/* Have the latest entry just been dropped? */
if
(
entrycount
==
1
)
return
0
;
entry
=
(
git_reflog_entry
*
)
git_reflog_entry_byindex
(
reflog
,
idx
-
1
);
/* If the oldest entry has just been removed... */
if
(
idx
==
entrycount
-
1
)
{
/* ...clear the oid_old member of the "new" oldest entry */
if
(
git_oid_fromstr
(
&
entry
->
oid_old
,
GIT_OID_HEX_ZERO
)
<
0
)
return
-
1
;
return
0
;
}
previous
=
(
git_reflog_entry
*
)
git_reflog_entry_byindex
(
reflog
,
idx
);
git_oid_cpy
(
&
entry
->
oid_old
,
&
previous
->
oid_cur
);
return
0
;
}
static
int
refdb_reflog_fs__delete
(
git_refdb_backend
*
_backend
,
const
char
*
name
)
{
int
error
;
...
...
@@ -1544,9 +1443,7 @@ int git_refdb_backend_fs(
backend
->
parent
.
free
=
&
refdb_fs_backend__free
;
backend
->
parent
.
reflog_read
=
&
refdb_reflog_fs__read
;
backend
->
parent
.
reflog_write
=
&
refdb_reflog_fs__write
;
backend
->
parent
.
reflog_append
=
&
refdb_reflog_fs__append
;
backend
->
parent
.
reflog_rename
=
&
refdb_reflog_fs__rename
;
backend
->
parent
.
reflog_drop
=
&
refdb_reflog_fs__drop
;
backend
->
parent
.
reflog_delete
=
&
refdb_reflog_fs__delete
;
*
backend_out
=
(
git_refdb_backend
*
)
backend
;
...
...
src/reflog.c
View file @
0174794a
...
...
@@ -71,16 +71,53 @@ int git_reflog_write(git_reflog *reflog)
return
db
->
backend
->
reflog_write
(
db
->
backend
,
reflog
);
}
int
git_reflog_append
(
git_reflog
*
reflog
,
const
git_oid
*
new_oid
,
const
git_signature
*
committer
,
const
char
*
msg
)
int
git_reflog_append
(
git_reflog
*
reflog
,
const
git_oid
*
new_oid
,
const
git_signature
*
committer
,
const
char
*
msg
)
{
git_refdb
*
db
;
git_reflog_entry
*
entry
;
const
git_reflog_entry
*
previous
;
const
char
*
newline
;
assert
(
reflog
&&
reflog
->
db
&&
new_oid
&&
committer
);
assert
(
reflog
&&
new_oid
&&
committer
);
db
=
reflog
->
db
;
entry
=
git__calloc
(
1
,
sizeof
(
git_reflog_entry
));
GITERR_CHECK_ALLOC
(
entry
);
if
((
entry
->
committer
=
git_signature_dup
(
committer
))
==
NULL
)
goto
cleanup
;
return
db
->
backend
->
reflog_append
(
db
->
backend
,
reflog
,
new_oid
,
committer
,
msg
);
if
(
msg
!=
NULL
)
{
if
((
entry
->
msg
=
git__strdup
(
msg
))
==
NULL
)
goto
cleanup
;
newline
=
strchr
(
msg
,
'\n'
);
if
(
newline
)
{
if
(
newline
[
1
]
!=
'\0'
)
{
giterr_set
(
GITERR_INVALID
,
"Reflog message cannot contain newline"
);
goto
cleanup
;
}
entry
->
msg
[
newline
-
msg
]
=
'\0'
;
}
}
previous
=
git_reflog_entry_byindex
(
reflog
,
0
);
if
(
previous
==
NULL
)
git_oid_fromstr
(
&
entry
->
oid_old
,
GIT_OID_HEX_ZERO
);
else
git_oid_cpy
(
&
entry
->
oid_old
,
&
previous
->
oid_cur
);
git_oid_cpy
(
&
entry
->
oid_cur
,
new_oid
);
if
(
git_vector_insert
(
&
reflog
->
entries
,
entry
)
<
0
)
goto
cleanup
;
return
0
;
cleanup:
git_reflog_entry__free
(
entry
);
return
-
1
;
}
int
git_reflog_rename
(
git_repository
*
repo
,
const
char
*
old_name
,
const
char
*
new_name
)
...
...
@@ -146,17 +183,52 @@ const char * git_reflog_entry_message(const git_reflog_entry *entry)
return
entry
->
msg
;
}
int
git_reflog_drop
(
git_reflog
*
reflog
,
size_t
idx
,
int
rewrite_previous_entry
)
int
git_reflog_drop
(
git_reflog
*
reflog
,
size_t
idx
,
int
rewrite_previous_entry
)
{
git_refdb
*
db
;
size_t
entrycount
;
git_reflog_entry
*
entry
,
*
previous
;
assert
(
reflog
&&
reflog
->
db
);
entrycount
=
git_reflog_entrycount
(
reflog
);
db
=
reflog
->
db
;
return
db
->
backend
->
reflog_drop
(
db
->
backend
,
reflog
,
idx
,
rewrite_previous_entry
);
entry
=
(
git_reflog_entry
*
)
git_reflog_entry_byindex
(
reflog
,
idx
);
if
(
entry
==
NULL
)
{
giterr_set
(
GITERR_REFERENCE
,
"No reflog entry at index "
PRIuZ
,
idx
);
return
GIT_ENOTFOUND
;
}
git_reflog_entry__free
(
entry
);
if
(
git_vector_remove
(
&
reflog
->
entries
,
reflog_inverse_index
(
idx
,
entrycount
))
<
0
)
return
-
1
;
if
(
!
rewrite_previous_entry
)
return
0
;
/* No need to rewrite anything when removing the most recent entry */
if
(
idx
==
0
)
return
0
;
/* Have the latest entry just been dropped? */
if
(
entrycount
==
1
)
return
0
;
entry
=
(
git_reflog_entry
*
)
git_reflog_entry_byindex
(
reflog
,
idx
-
1
);
/* If the oldest entry has just been removed... */
if
(
idx
==
entrycount
-
1
)
{
/* ...clear the oid_old member of the "new" oldest entry */
if
(
git_oid_fromstr
(
&
entry
->
oid_old
,
GIT_OID_HEX_ZERO
)
<
0
)
return
-
1
;
return
0
;
}
previous
=
(
git_reflog_entry
*
)
git_reflog_entry_byindex
(
reflog
,
idx
);
git_oid_cpy
(
&
entry
->
oid_old
,
&
previous
->
oid_cur
);
return
0
;
}
int
git_reflog_append_to
(
git_repository
*
repo
,
const
char
*
name
,
const
git_oid
*
id
,
...
...
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