refs: add REF_FORCE_CREATE_REFLOG flag
Add a flag to allow forcing the creation of a reflog even if the ref name and core.logAllRefUpdates setting would not ordinarily cause ref creation. In a moment, we will use this to add options to git tag and git update-ref to force reflog creation. Signed-off-by: David Turner <dturner@twopensource.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
afcb2e7a3b
commit
0f2a71d992
34
refs.c
34
refs.c
@ -62,6 +62,11 @@ static unsigned char refname_disposition[256] = {
|
||||
*/
|
||||
#define REF_NEEDS_COMMIT 0x20
|
||||
|
||||
/*
|
||||
* 0x40 is REF_FORCE_CREATE_REFLOG, so skip it if you're adding a
|
||||
* value to ref_update::flags
|
||||
*/
|
||||
|
||||
/*
|
||||
* Try to read one refname component from the front of refname.
|
||||
* Return the length of the component found, or -1 if the component is
|
||||
@ -2914,7 +2919,7 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
|
||||
const unsigned char *sha1, struct strbuf *err);
|
||||
static int commit_ref_update(struct ref_lock *lock,
|
||||
const unsigned char *sha1, const char *logmsg,
|
||||
struct strbuf *err);
|
||||
int flags, struct strbuf *err);
|
||||
|
||||
int rename_ref(const char *oldrefname, const char *newrefname, const char *logmsg)
|
||||
{
|
||||
@ -2976,7 +2981,7 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
|
||||
hashcpy(lock->old_oid.hash, orig_sha1);
|
||||
|
||||
if (write_ref_to_lockfile(lock, orig_sha1, &err) ||
|
||||
commit_ref_update(lock, orig_sha1, logmsg, &err)) {
|
||||
commit_ref_update(lock, orig_sha1, logmsg, 0, &err)) {
|
||||
error("unable to write current sha1 into %s: %s", newrefname, err.buf);
|
||||
strbuf_release(&err);
|
||||
goto rollback;
|
||||
@ -2995,7 +3000,7 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
|
||||
flag = log_all_ref_updates;
|
||||
log_all_ref_updates = 0;
|
||||
if (write_ref_to_lockfile(lock, orig_sha1, &err) ||
|
||||
commit_ref_update(lock, orig_sha1, NULL, &err)) {
|
||||
commit_ref_update(lock, orig_sha1, NULL, 0, &err)) {
|
||||
error("unable to write current sha1 into %s: %s", oldrefname, err.buf);
|
||||
strbuf_release(&err);
|
||||
}
|
||||
@ -3152,7 +3157,8 @@ static int log_ref_write_fd(int fd, const unsigned char *old_sha1,
|
||||
|
||||
static int log_ref_write_1(const char *refname, const unsigned char *old_sha1,
|
||||
const unsigned char *new_sha1, const char *msg,
|
||||
struct strbuf *sb_log_file, struct strbuf *err)
|
||||
struct strbuf *sb_log_file, int flags,
|
||||
struct strbuf *err)
|
||||
{
|
||||
int logfd, result, oflags = O_APPEND | O_WRONLY;
|
||||
char *log_file;
|
||||
@ -3160,7 +3166,7 @@ static int log_ref_write_1(const char *refname, const unsigned char *old_sha1,
|
||||
if (log_all_ref_updates < 0)
|
||||
log_all_ref_updates = !is_bare_repository();
|
||||
|
||||
result = log_ref_setup(refname, sb_log_file, err, 0);
|
||||
result = log_ref_setup(refname, sb_log_file, err, flags & REF_FORCE_CREATE_REFLOG);
|
||||
|
||||
if (result)
|
||||
return result;
|
||||
@ -3189,10 +3195,11 @@ static int log_ref_write_1(const char *refname, const unsigned char *old_sha1,
|
||||
|
||||
static int log_ref_write(const char *refname, const unsigned char *old_sha1,
|
||||
const unsigned char *new_sha1, const char *msg,
|
||||
struct strbuf *err)
|
||||
int flags, struct strbuf *err)
|
||||
{
|
||||
struct strbuf sb = STRBUF_INIT;
|
||||
int ret = log_ref_write_1(refname, old_sha1, new_sha1, msg, &sb, err);
|
||||
int ret = log_ref_write_1(refname, old_sha1, new_sha1, msg, &sb, flags,
|
||||
err);
|
||||
strbuf_release(&sb);
|
||||
return ret;
|
||||
}
|
||||
@ -3246,12 +3253,12 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
|
||||
*/
|
||||
static int commit_ref_update(struct ref_lock *lock,
|
||||
const unsigned char *sha1, const char *logmsg,
|
||||
struct strbuf *err)
|
||||
int flags, struct strbuf *err)
|
||||
{
|
||||
clear_loose_ref_cache(&ref_cache);
|
||||
if (log_ref_write(lock->ref_name, lock->old_oid.hash, sha1, logmsg, err) < 0 ||
|
||||
if (log_ref_write(lock->ref_name, lock->old_oid.hash, sha1, logmsg, flags, err) < 0 ||
|
||||
(strcmp(lock->ref_name, lock->orig_ref_name) &&
|
||||
log_ref_write(lock->orig_ref_name, lock->old_oid.hash, sha1, logmsg, err) < 0)) {
|
||||
log_ref_write(lock->orig_ref_name, lock->old_oid.hash, sha1, logmsg, flags, err) < 0)) {
|
||||
char *old_msg = strbuf_detach(err, NULL);
|
||||
strbuf_addf(err, "Cannot update the ref '%s': %s",
|
||||
lock->ref_name, old_msg);
|
||||
@ -3281,7 +3288,7 @@ static int commit_ref_update(struct ref_lock *lock,
|
||||
!strcmp(head_ref, lock->ref_name)) {
|
||||
struct strbuf log_err = STRBUF_INIT;
|
||||
if (log_ref_write("HEAD", lock->old_oid.hash, sha1,
|
||||
logmsg, &log_err)) {
|
||||
logmsg, 0, &log_err)) {
|
||||
error("%s", log_err.buf);
|
||||
strbuf_release(&log_err);
|
||||
}
|
||||
@ -3355,7 +3362,7 @@ int create_symref(const char *ref_target, const char *refs_heads_master,
|
||||
done:
|
||||
#endif
|
||||
if (logmsg && !read_ref(refs_heads_master, new_sha1) &&
|
||||
log_ref_write(ref_target, old_sha1, new_sha1, logmsg, &err)) {
|
||||
log_ref_write(ref_target, old_sha1, new_sha1, logmsg, 0, &err)) {
|
||||
error("%s", err.buf);
|
||||
strbuf_release(&err);
|
||||
}
|
||||
@ -4032,7 +4039,8 @@ int ref_transaction_commit(struct ref_transaction *transaction,
|
||||
|
||||
if (update->flags & REF_NEEDS_COMMIT) {
|
||||
if (commit_ref_update(update->lock,
|
||||
update->new_sha1, update->msg, err)) {
|
||||
update->new_sha1, update->msg,
|
||||
update->flags, err)) {
|
||||
/* freed by commit_ref_update(): */
|
||||
update->lock = NULL;
|
||||
ret = TRANSACTION_GENERIC_ERROR;
|
||||
|
Loading…
Reference in New Issue
Block a user