Commit adf7d0940e13e71982cbf3f65adead6428fd2aca

Edward Thomson 2018-03-04T12:17:06

Merge pull request #4559 from jacquesg/worktree-const Worktree lock reason should be const

diff --git a/include/git2/worktree.h b/include/git2/worktree.h
index d3fa88e..a2a5d44 100644
--- a/include/git2/worktree.h
+++ b/include/git2/worktree.h
@@ -123,7 +123,7 @@ GIT_EXTERN(int) git_worktree_add(git_worktree **out, git_repository *repo,
  * @param reason Reason why the working tree is being locked
  * @return 0 on success, non-zero otherwise
  */
-GIT_EXTERN(int) git_worktree_lock(git_worktree *wt, char *reason);
+GIT_EXTERN(int) git_worktree_lock(git_worktree *wt, const char *reason);
 
 /**
  * Unlock a locked worktree
diff --git a/src/worktree.c b/src/worktree.c
index 5a814a2..4b18db7 100644
--- a/src/worktree.c
+++ b/src/worktree.c
@@ -383,7 +383,7 @@ out:
 	return err;
 }
 
-int git_worktree_lock(git_worktree *wt, char *creason)
+int git_worktree_lock(git_worktree *wt, const char *reason)
 {
 	git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
 	int err;
@@ -396,8 +396,8 @@ int git_worktree_lock(git_worktree *wt, char *creason)
 	if ((err = git_buf_joinpath(&path, wt->gitdir_path, "locked")) < 0)
 		goto out;
 
-	if (creason)
-		git_buf_attach_notowned(&buf, creason, strlen(creason));
+	if (reason)
+		git_buf_attach_notowned(&buf, reason, strlen(reason));
 
 	if ((err = git_futils_writebuffer(&buf, path.ptr, O_CREAT|O_EXCL|O_WRONLY, 0644)) < 0)
 		goto out;