read UUID back from work tree meta data
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
diff --git a/lib/fileindex.c b/lib/fileindex.c
index 9513f30..25d5b3b 100644
--- a/lib/fileindex.c
+++ b/lib/fileindex.c
@@ -25,6 +25,7 @@
#include <sha1.h>
#include <endian.h>
#include <limits.h>
+#include <uuid.h>
#include "got_error.h"
#include "got_object.h"
diff --git a/lib/got_lib_worktree.h b/lib/got_lib_worktree.h
index d786edf..a8227e2 100644
--- a/lib/got_lib_worktree.h
+++ b/lib/got_lib_worktree.h
@@ -20,6 +20,7 @@ struct got_worktree {
char *path_prefix;
struct got_object_id *base_commit_id;
struct got_reference *head_ref;
+ uuid_t uuid;
/*
* File descriptor for the lock file, open while a work tree is open.
diff --git a/lib/repository.c b/lib/repository.c
index 96c0dad..afdfaad 100644
--- a/lib/repository.c
+++ b/lib/repository.c
@@ -33,6 +33,7 @@
#include <libgen.h>
#include <stdint.h>
#include <imsg.h>
+#include <uuid.h>
#include "got_error.h"
#include "got_reference.h"
diff --git a/lib/worktree.c b/lib/worktree.c
index 8c1bd06..2b9d193 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -315,12 +315,14 @@ open_worktree(struct got_worktree **worktree, const char *path)
const struct got_error *err = NULL;
char *path_got;
char *formatstr = NULL;
+ char *uuidstr = NULL;
char *path_lock = NULL;
char *base_commit_id_str = NULL;
char *head_ref_str = NULL;
int version, fd = -1;
const char *errstr;
struct got_repository *repo = NULL;
+ uint32_t uuid_status;
*worktree = NULL;
@@ -384,6 +386,15 @@ open_worktree(struct got_worktree **worktree, const char *path)
if (err)
goto done;
+ err = read_meta_file(&uuidstr, path_got, GOT_WORKTREE_UUID);
+ if (err)
+ goto done;
+ uuid_from_string(uuidstr, &(*worktree)->uuid, &uuid_status);
+ if (uuid_status != uuid_s_ok) {
+ err = got_error_uuid(uuid_status);
+ goto done;
+ }
+
err = got_repo_open(&repo, (*worktree)->repo_path);
if (err)
goto done;
@@ -405,6 +416,7 @@ done:
free(path_lock);
free(head_ref_str);
free(base_commit_id_str);
+ free(uuidstr);
if (err) {
if (fd != -1)
close(fd);
diff --git a/regress/worktree/worktree_test.c b/regress/worktree/worktree_test.c
index 82c5ca6..b33bfa3 100644
--- a/regress/worktree/worktree_test.c
+++ b/regress/worktree/worktree_test.c
@@ -28,6 +28,7 @@
#include <util.h>
#include <err.h>
#include <unistd.h>
+#include <uuid.h>
#include "got_error.h"
#include "got_object.h"