Commit Diff


commit - a09378479c43596eacd072025af84ba0c10c479c
commit + 72151b04d0a9eb62823b0769601163f9ecf224d1
blob - 0aa6d642158881e6a8c75f98befbb326845f7325
blob + e3fbc8bfcbcd998c0514a54e52eca9a9e1feb03d
--- got/got.c
+++ got/got.c
@@ -322,7 +322,7 @@ cmd_checkout(int argc, char *argv[])
 	char *worktree_path = NULL;
 	const char *path_prefix = "";
 	char *commit_id_str = NULL;
-	int ch, same_path_prefix, x;
+	int ch, same_path_prefix;
 
 	while ((ch = getopt(argc, argv, "c:p:")) != -1) {
 		switch (ch) {
@@ -389,8 +389,7 @@ cmd_checkout(int argc, char *argv[])
 	} else
 		usage_checkout();
 
-	while (worktree_path[x = strlen(worktree_path) - 1] == '/')
-		worktree_path[x] = '\0';
+	got_path_strip_trailing_slashes(worktree_path);
 
 	error = got_repo_open(&repo, repo_path);
 	if (error != NULL)
blob - d79664694d4c2376976a212524c0b51cd08c16a2
blob + e4dc262d9f534be828275a226b7a4592b85d5a03
--- include/got_path.h
+++ include/got_path.h
@@ -92,3 +92,6 @@ const struct got_error *got_path_mkdir(const char *);
 
 /* dirname(3) with error handling and dynamically allocated result. */
 const struct got_error *got_path_dirname(char **, const char *);
+
+/* Strip trailing slashes from a path; path will be modified in-place. */
+void got_path_strip_trailing_slashes(char *);
blob - 253851ff74356045bae103ab830cc17e3c96fbb8
blob + 4c0f56363007cb794f3b12bdfadd5d1184d2e25a
--- lib/path.c
+++ lib/path.c
@@ -343,3 +343,12 @@ got_path_dirname(char **parent, const char *path)
 
 	return NULL;
 }
+
+void
+got_path_strip_trailing_slashes(char *path)
+{
+	int x;
+
+	while (path[x = strlen(path) - 1] == '/')
+		path[x] = '\0';
+}