Commit 65e3b818196debd0e5c6cc7c1f3182ee2d253fe2

Stefan Sperling 2018-03-11T12:52:02

set base commit to invalid commit id when work tree is created

diff --git a/lib/got_sha1_priv.h b/lib/got_sha1_priv.h
index df56c0d..d207ee3 100644
--- a/lib/got_sha1_priv.h
+++ b/lib/got_sha1_priv.h
@@ -14,5 +14,7 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#define GOT_SHA1_STRING_ZERO "0000000000000000000000000000000000000000"
+
 int got_parse_sha1_digest(uint8_t *, const char *);
 char *got_sha1_digest_to_str(const uint8_t *, char *, size_t);
diff --git a/lib/got_worktree_priv.h b/lib/got_worktree_priv.h
index 206bddf..bc1edd3 100644
--- a/lib/got_worktree_priv.h
+++ b/lib/got_worktree_priv.h
@@ -42,3 +42,4 @@ struct got_worktree {
 #define GOT_WORKTREE_FORMAT		"format"
 
 #define GOT_WORKTREE_FORMAT_VERSION	1
+#define GOT_WORKTREE_INVALID_COMMIT_ID	GOT_SHA1_STRING_ZERO
diff --git a/lib/worktree.c b/lib/worktree.c
index a84d489..eb722ed 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -31,6 +31,7 @@
 
 #include "got_worktree_priv.h"
 #include "got_path_priv.h"
+#include "got_sha1_priv.h"
 
 static const struct got_error *
 create_meta_file(const char *path_got, const char *name, const char *content)
@@ -174,8 +175,9 @@ got_worktree_init(const char *path, struct got_reference *head_ref,
 	if (err)
 		goto done;
 
-	/* Set base commit to empty. */
-	err = create_meta_file(path_got, GOT_WORKTREE_BASE_COMMIT, NULL);
+	/* Save an invalid base commit hash. */
+	err = create_meta_file(path_got, GOT_WORKTREE_BASE_COMMIT,
+		GOT_WORKTREE_INVALID_COMMIT_ID);
 	if (err)
 		goto done;