From: Shawn Pearce <spearce@spearce.org>
To: Junio Hamano <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: [PATCH 3/5] Force writing ref if it doesn't exist.
Date: Fri, 19 May 2006 03:29:05 -0400 [thread overview]
Message-ID: <20060519072905.GD22257@spearce.org> (raw)
Normally we try to skip writing a ref if its value hasn't changed
but in the special case that the ref doesn't exist but the new
value is going to be 0{40} then force writing the ref anyway.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
refs.c | 4 +++-
refs.h | 1 +
2 files changed, 4 insertions(+), 1 deletions(-)
13f3c9a2b8959da1947e21c32e58d81d32a83f3e
diff --git a/refs.c b/refs.c
index 9d37a02..31cf276 100644
--- a/refs.c
+++ b/refs.c
@@ -288,6 +288,7 @@ static struct ref_lock* lock_ref_sha1_ba
const unsigned char *old_sha1, int mustexist)
{
struct ref_lock *lock;
+ struct stat st;
lock = xcalloc(1, sizeof(struct ref_lock));
lock->lock_fd = -1;
@@ -303,6 +304,7 @@ static struct ref_lock* lock_ref_sha1_ba
lock->ref_file = strdup(path);
lock->lock_file = strdup(mkpath("%s.lock", lock->ref_file));
lock->log_file = strdup(git_path("logs/%s", lock->ref_file + plen));
+ lock->force_write = !lstat(lock->ref_file, &st) || errno == ENOENT;
if (safe_create_leading_directories(lock->lock_file))
die("unable to create directory for %s", lock->lock_file);
@@ -405,7 +407,7 @@ int write_ref_sha1(struct ref_lock *lock
if (!lock)
return -1;
- if (!memcmp(lock->old_sha1, sha1, 20)) {
+ if (!lock->force_write && !memcmp(lock->old_sha1, sha1, 20)) {
unlock_ref(lock);
return 0;
}
diff --git a/refs.h b/refs.h
index 2c854de..6c946ea 100644
--- a/refs.h
+++ b/refs.h
@@ -7,6 +7,7 @@ struct ref_lock {
char *log_file;
unsigned char old_sha1[20];
int lock_fd;
+ int force_write;
};
/*
--
1.3.2.g7278
reply other threads:[~2006-05-19 7:29 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060519072905.GD22257@spearce.org \
--to=spearce@spearce.org \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).