Commit Diff


commit - ec22038e8d0a46e692c6093e0a35503f4af398d7
commit + c442a90d575144387b9e5e1c769ba935013bbc71
blob - 9513f3056f3375a16cb9ccca9ebf8a3dfe294dff
blob + 25d5b3b4111387762e2eadfea8235930b44f0bdc
--- lib/fileindex.c
+++ 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"
blob - d786edf4b5168f0bcc8ec952293302fd7b1fbece
blob + a8227e282bac5fa313746e559af0e6b4555deefe
--- lib/got_lib_worktree.h
+++ 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.
blob - 96c0dad04655c98b9dc28daf55f4f01b4cdabb30
blob + afdfaad9d4c767b121a5b9f0e740aac323254097
--- lib/repository.c
+++ 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"
blob - 8c1bd06e6065b0f858659d184c602a62ff561fa4
blob + 2b9d193bd6f80722eb129a3ebe3a9da1d93afc87
--- lib/worktree.c
+++ lib/worktree.c
@@ -315,12 +315,14 @@ open_worktree(struct got_worktree **worktree, const ch
 	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;
 
@@ -381,8 +383,17 @@ open_worktree(struct got_worktree **worktree, const ch
 
 	err = read_meta_file(&base_commit_id_str, path_got,
 	    GOT_WORKTREE_BASE_COMMIT);
+	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)
@@ -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);
blob - 82c5ca68b93d4bd4df9907d90eb3a32c1b5a12ed
blob + b33bfa37d5d2f770d3d199f2ed1a186aa12dd65e
--- regress/worktree/worktree_test.c
+++ 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"