{"thread":{"id":"4203","subject":"[PATCH 3/5] Force writing ref if it doesn't exist.","startedAt":"2006-05-19T07:29:05Z","lastAt":"2006-05-19T07:29:05Z","messageCount":1,"participants":["Shawn Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"20274","messageId":"20060519072905.GD22257@spearce.org","threadId":"4203","inReplyTo":null,"subject":"[PATCH 3/5] Force writing ref if it doesn't exist.","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-05-19T07:29:05Z","receivedAt":"2006-05-19T07:29:05Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Normally we try to skip writing a ref if its value hasn't changed\nbut in the special case that the ref doesn't exist but the new\nvalue is going to be 0{40} then force writing the ref anyway.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n\n---\n\n refs.c |    4 +++-\n refs.h |    1 +\n 2 files changed, 4 insertions(+), 1 deletions(-)\n\n13f3c9a2b8959da1947e21c32e58d81d32a83f3e\ndiff --git a/refs.c b/refs.c\nindex 9d37a02..31cf276 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -288,6 +288,7 @@ static struct ref_lock* lock_ref_sha1_ba\n \tconst unsigned char *old_sha1, int mustexist)\n {\n \tstruct ref_lock *lock;\n+\tstruct stat st;\n \n \tlock = xcalloc(1, sizeof(struct ref_lock));\n \tlock->lock_fd = -1;\n@@ -303,6 +304,7 @@ static struct ref_lock* lock_ref_sha1_ba\n \tlock->ref_file = strdup(path);\n \tlock->lock_file = strdup(mkpath(\"%s.lock\", lock->ref_file));\n \tlock->log_file = strdup(git_path(\"logs/%s\", lock->ref_file + plen));\n+\tlock->force_write = !lstat(lock->ref_file, &st) || errno == ENOENT;\n \n \tif (safe_create_leading_directories(lock->lock_file))\n \t\tdie(\"unable to create directory for %s\", lock->lock_file);\n@@ -405,7 +407,7 @@ int write_ref_sha1(struct ref_lock *lock\n \n \tif (!lock)\n \t\treturn -1;\n-\tif (!memcmp(lock->old_sha1, sha1, 20)) {\n+\tif (!lock->force_write && !memcmp(lock->old_sha1, sha1, 20)) {\n \t\tunlock_ref(lock);\n \t\treturn 0;\n \t}\ndiff --git a/refs.h b/refs.h\nindex 2c854de..6c946ea 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -7,6 +7,7 @@ struct ref_lock {\n \tchar *log_file;\n \tunsigned char old_sha1[20];\n \tint lock_fd;\n+\tint force_write;\n };\n \n /*\n-- \n1.3.2.g7278\n"}]}