set base commit to invalid commit id when work tree is created
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
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;