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
110df893
Commit
110df893
authored
Nov 13, 2013
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refdb: add a `message` parameter for appending to the log
This is as yet unused.
parent
a6b50808
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
24 deletions
+46
-24
include/git2/sys/refdb_backend.h
+4
-2
src/refdb.c
+5
-4
src/refdb.h
+3
-2
src/refdb_fs.c
+32
-14
src/refs.c
+2
-2
No files found.
include/git2/sys/refdb_backend.h
View file @
110df893
...
@@ -93,11 +93,13 @@ struct git_refdb_backend {
...
@@ -93,11 +93,13 @@ struct git_refdb_backend {
* must provide this function.
* must provide this function.
*/
*/
int
(
*
write
)(
git_refdb_backend
*
backend
,
int
(
*
write
)(
git_refdb_backend
*
backend
,
const
git_reference
*
ref
,
int
force
);
const
git_reference
*
ref
,
int
force
,
const
char
*
message
);
int
(
*
rename
)(
int
(
*
rename
)(
git_reference
**
out
,
git_refdb_backend
*
backend
,
git_reference
**
out
,
git_refdb_backend
*
backend
,
const
char
*
old_name
,
const
char
*
new_name
,
int
force
);
const
char
*
old_name
,
const
char
*
new_name
,
int
force
,
const
char
*
message
);
/**
/**
* Deletes the given reference from the refdb. A refdb implementation
* Deletes the given reference from the refdb. A refdb implementation
...
...
src/refdb.c
View file @
110df893
...
@@ -167,14 +167,14 @@ void git_refdb_iterator_free(git_reference_iterator *iter)
...
@@ -167,14 +167,14 @@ void git_refdb_iterator_free(git_reference_iterator *iter)
iter
->
free
(
iter
);
iter
->
free
(
iter
);
}
}
int
git_refdb_write
(
git_refdb
*
db
,
git_reference
*
ref
,
int
force
)
int
git_refdb_write
(
git_refdb
*
db
,
git_reference
*
ref
,
int
force
,
const
char
*
message
)
{
{
assert
(
db
&&
db
->
backend
);
assert
(
db
&&
db
->
backend
);
GIT_REFCOUNT_INC
(
db
);
GIT_REFCOUNT_INC
(
db
);
ref
->
db
=
db
;
ref
->
db
=
db
;
return
db
->
backend
->
write
(
db
->
backend
,
ref
,
force
);
return
db
->
backend
->
write
(
db
->
backend
,
ref
,
force
,
message
);
}
}
int
git_refdb_rename
(
int
git_refdb_rename
(
...
@@ -182,12 +182,13 @@ int git_refdb_rename(
...
@@ -182,12 +182,13 @@ int git_refdb_rename(
git_refdb
*
db
,
git_refdb
*
db
,
const
char
*
old_name
,
const
char
*
old_name
,
const
char
*
new_name
,
const
char
*
new_name
,
int
force
)
int
force
,
const
char
*
message
)
{
{
int
error
;
int
error
;
assert
(
db
&&
db
->
backend
);
assert
(
db
&&
db
->
backend
);
error
=
db
->
backend
->
rename
(
out
,
db
->
backend
,
old_name
,
new_name
,
force
);
error
=
db
->
backend
->
rename
(
out
,
db
->
backend
,
old_name
,
new_name
,
force
,
message
);
if
(
error
<
0
)
if
(
error
<
0
)
return
error
;
return
error
;
...
...
src/refdb.h
View file @
110df893
...
@@ -33,14 +33,15 @@ int git_refdb_rename(
...
@@ -33,14 +33,15 @@ int git_refdb_rename(
git_refdb
*
db
,
git_refdb
*
db
,
const
char
*
old_name
,
const
char
*
old_name
,
const
char
*
new_name
,
const
char
*
new_name
,
int
force
);
int
force
,
const
char
*
message
);
int
git_refdb_iterator
(
git_reference_iterator
**
out
,
git_refdb
*
db
,
const
char
*
glob
);
int
git_refdb_iterator
(
git_reference_iterator
**
out
,
git_refdb
*
db
,
const
char
*
glob
);
int
git_refdb_iterator_next
(
git_reference
**
out
,
git_reference_iterator
*
iter
);
int
git_refdb_iterator_next
(
git_reference
**
out
,
git_reference_iterator
*
iter
);
int
git_refdb_iterator_next_name
(
const
char
**
out
,
git_reference_iterator
*
iter
);
int
git_refdb_iterator_next_name
(
const
char
**
out
,
git_reference_iterator
*
iter
);
void
git_refdb_iterator_free
(
git_reference_iterator
*
iter
);
void
git_refdb_iterator_free
(
git_reference_iterator
*
iter
);
int
git_refdb_write
(
git_refdb
*
refdb
,
git_reference
*
ref
,
int
force
);
int
git_refdb_write
(
git_refdb
*
refdb
,
git_reference
*
ref
,
int
force
,
const
char
*
message
);
int
git_refdb_delete
(
git_refdb
*
refdb
,
const
char
*
ref_name
);
int
git_refdb_delete
(
git_refdb
*
refdb
,
const
char
*
ref_name
);
int
git_refdb_reflog_read
(
git_reflog
**
out
,
git_refdb
*
db
,
const
char
*
name
);
int
git_refdb_reflog_read
(
git_reflog
**
out
,
git_refdb
*
db
,
const
char
*
name
);
...
...
src/refdb_fs.c
View file @
110df893
...
@@ -910,7 +910,8 @@ fail:
...
@@ -910,7 +910,8 @@ fail:
static
int
refdb_fs_backend__write
(
static
int
refdb_fs_backend__write
(
git_refdb_backend
*
_backend
,
git_refdb_backend
*
_backend
,
const
git_reference
*
ref
,
const
git_reference
*
ref
,
int
force
)
int
force
,
const
char
*
message
)
{
{
refdb_fs_backend
*
backend
=
(
refdb_fs_backend
*
)
_backend
;
refdb_fs_backend
*
backend
=
(
refdb_fs_backend
*
)
_backend
;
int
error
;
int
error
;
...
@@ -974,7 +975,8 @@ static int refdb_fs_backend__rename(
...
@@ -974,7 +975,8 @@ static int refdb_fs_backend__rename(
git_refdb_backend
*
_backend
,
git_refdb_backend
*
_backend
,
const
char
*
old_name
,
const
char
*
old_name
,
const
char
*
new_name
,
const
char
*
new_name
,
int
force
)
int
force
,
const
char
*
message
)
{
{
refdb_fs_backend
*
backend
=
(
refdb_fs_backend
*
)
_backend
;
refdb_fs_backend
*
backend
=
(
refdb_fs_backend
*
)
_backend
;
git_reference
*
old
,
*
new
;
git_reference
*
old
,
*
new
;
...
@@ -1264,6 +1266,32 @@ static int serialize_reflog_entry(
...
@@ -1264,6 +1266,32 @@ static int serialize_reflog_entry(
return
git_buf_oom
(
buf
);
return
git_buf_oom
(
buf
);
}
}
static
int
lock_reflog
(
git_filebuf
*
file
,
refdb_fs_backend
*
backend
,
const
char
*
refname
)
{
git_repository
*
repo
;
git_buf
log_path
=
GIT_BUF_INIT
;
int
error
;
repo
=
backend
->
repo
;
if
(
retrieve_reflog_path
(
&
log_path
,
repo
,
refname
)
<
0
)
return
-
1
;
if
(
!
git_path_isfile
(
git_buf_cstr
(
&
log_path
)))
{
giterr_set
(
GITERR_INVALID
,
"Log file for reference '%s' doesn't exist."
,
refname
);
error
=
-
1
;
goto
cleanup
;
}
error
=
git_filebuf_open
(
file
,
git_buf_cstr
(
&
log_path
),
0
,
GIT_REFLOG_FILE_MODE
);
cleanup
:
git_buf_free
(
&
log_path
);
return
error
;
}
static
int
refdb_reflog_fs__write
(
git_refdb_backend
*
_backend
,
git_reflog
*
reflog
)
static
int
refdb_reflog_fs__write
(
git_refdb_backend
*
_backend
,
git_reflog
*
reflog
)
{
{
int
error
=
-
1
;
int
error
=
-
1
;
...
@@ -1271,7 +1299,6 @@ static int refdb_reflog_fs__write(git_refdb_backend *_backend, git_reflog *reflo
...
@@ -1271,7 +1299,6 @@ static int refdb_reflog_fs__write(git_refdb_backend *_backend, git_reflog *reflo
git_reflog_entry
*
entry
;
git_reflog_entry
*
entry
;
git_repository
*
repo
;
git_repository
*
repo
;
refdb_fs_backend
*
backend
;
refdb_fs_backend
*
backend
;
git_buf
log_path
=
GIT_BUF_INIT
;
git_buf
log
=
GIT_BUF_INIT
;
git_buf
log
=
GIT_BUF_INIT
;
git_filebuf
fbuf
=
GIT_FILEBUF_INIT
;
git_filebuf
fbuf
=
GIT_FILEBUF_INIT
;
...
@@ -1280,18 +1307,9 @@ static int refdb_reflog_fs__write(git_refdb_backend *_backend, git_reflog *reflo
...
@@ -1280,18 +1307,9 @@ static int refdb_reflog_fs__write(git_refdb_backend *_backend, git_reflog *reflo
backend
=
(
refdb_fs_backend
*
)
_backend
;
backend
=
(
refdb_fs_backend
*
)
_backend
;
repo
=
backend
->
repo
;
repo
=
backend
->
repo
;
if
(
retrieve_reflog_path
(
&
log_path
,
repo
,
reflog
->
ref_name
)
<
0
)
if
(
(
error
=
lock_reflog
(
&
fbuf
,
backend
,
reflog
->
ref_name
)
)
<
0
)
return
-
1
;
return
-
1
;
if
(
!
git_path_isfile
(
git_buf_cstr
(
&
log_path
)))
{
giterr_set
(
GITERR_INVALID
,
"Log file for reference '%s' doesn't exist."
,
reflog
->
ref_name
);
goto
cleanup
;
}
if
((
error
=
git_filebuf_open
(
&
fbuf
,
git_buf_cstr
(
&
log_path
),
0
,
GIT_REFLOG_FILE_MODE
))
<
0
)
goto
cleanup
;
git_vector_foreach
(
&
reflog
->
entries
,
i
,
entry
)
{
git_vector_foreach
(
&
reflog
->
entries
,
i
,
entry
)
{
if
(
serialize_reflog_entry
(
&
log
,
&
(
entry
->
oid_old
),
&
(
entry
->
oid_cur
),
entry
->
committer
,
entry
->
msg
)
<
0
)
if
(
serialize_reflog_entry
(
&
log
,
&
(
entry
->
oid_old
),
&
(
entry
->
oid_cur
),
entry
->
committer
,
entry
->
msg
)
<
0
)
goto
cleanup
;
goto
cleanup
;
...
@@ -1308,7 +1326,7 @@ cleanup:
...
@@ -1308,7 +1326,7 @@ cleanup:
success
:
success
:
git_buf_free
(
&
log
);
git_buf_free
(
&
log
);
git_buf_free
(
&
log_path
);
return
error
;
return
error
;
}
}
...
...
src/refs.c
View file @
110df893
...
@@ -396,7 +396,7 @@ static int reference__create(
...
@@ -396,7 +396,7 @@ static int reference__create(
GITERR_CHECK_ALLOC
(
ref
);
GITERR_CHECK_ALLOC
(
ref
);
if
((
error
=
git_refdb_write
(
refdb
,
ref
,
force
))
<
0
)
{
if
((
error
=
git_refdb_write
(
refdb
,
ref
,
force
,
log_message
))
<
0
)
{
git_reference_free
(
ref
);
git_reference_free
(
ref
);
return
error
;
return
error
;
}
}
...
@@ -579,7 +579,7 @@ int git_reference_rename(
...
@@ -579,7 +579,7 @@ int git_reference_rename(
should_head_be_updated
=
(
error
>
0
);
should_head_be_updated
=
(
error
>
0
);
if
((
error
=
git_refdb_rename
(
out
,
ref
->
db
,
ref
->
name
,
new_name
,
force
))
<
0
)
if
((
error
=
git_refdb_rename
(
out
,
ref
->
db
,
ref
->
name
,
new_name
,
force
,
NULL
))
<
0
)
return
error
;
return
error
;
/* Update HEAD it was poiting to the reference being renamed. */
/* Update HEAD it was poiting to the reference being renamed. */
...
...
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