Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows and backslashes in paths #3012

Closed
eht16 opened this issue Mar 23, 2015 · 6 comments
Closed

Windows and backslashes in paths #3012

eht16 opened this issue Mar 23, 2015 · 6 comments

Comments

@eht16
Copy link

eht16 commented Mar 23, 2015

Using libgit2 0.22.1 on Windows, I noticed git_tree_entry_bypath() seems to require foward slashes as path seperator while git_repository_open_ext() accepts a path to the repository with backslashes happily.

I understand paths within a repository are internally handled with forward slashes only. But I'm wondering how to get around the issue.
Should libgit2 normalize the path it receives in git_tree_entry_bypath() or is it the at the caller to pass in relative path with forward slashes already? In case of the latter case, maybe the docs should mention this to make it more clear.

@ethomson
Copy link
Member

Should libgit2 normalize the path it receives in git_tree_entry_bypath() or is it the at the caller to pass in relative path with forward slashes already? In case of the latter case, maybe the docs should mention this to make it more clear.

As you point out - there are two separate concepts: filesystem paths can be specified in the manner that the local system accepts. (Windows accepts both forward and backslashes in Win32 calls, generally speaking.) Repository paths (in the index, trees, etc) are always represented in Git semantics and thus have forward slashes.

I can see how this might be confusing, and certainly documentation is very important. Would you be interested in helping to clarify this a bit?

@eht16
Copy link
Author

eht16 commented Mar 23, 2015

diff --git a/include/git2/tree.h b/include/git2/tree.h
index 550a448..c74cbdf 100644
--- a/include/git2/tree.h
+++ b/include/git2/tree.h
@@ -136,7 +136,7 @@ GIT_EXTERN(const git_tree_entry *) git_tree_entry_byid(
  *
  * @param out Pointer where to store the tree entry
  * @param root Previously loaded tree which is the root of the relative path
- * @param path Path to the contained entry
+ * @param path Path to the contained entry (repository path with forward slashes)
  * @return 0 on success; GIT_ENOTFOUND if the path does not exist
  */
 GIT_EXTERN(int) git_tree_entry_bypath(

maybe something like this.
I don't know the whole libgit2 API, so I cannot say which other functions might deserve such a hint as well.

@carlosmn
Copy link
Member

This is a library-wide thing, Git data structures use a slash as a path separator and it´s not specific to any particular function and it affects input as well as output.

This feels like something we'd want to make explicit as part of some general document like the README. We already have some of this in CONVENTIONS.md though those are mostly written for people who are writing library code rather than using it.

@linquize
Copy link
Contributor

If you pass \ to libgit2, NOT all functions are guaranteed to work properly.
So you need to normalize to '/' before passing to libgit2.

@ethomson
Copy link
Member

If there's a function that takes a local path and fails to accept \ as a delimiter n Windows, please file a bug.

@eht16
Copy link
Author

eht16 commented Mar 26, 2015

I agree CONVENTIONS.md might be targeted a bit too much to library developers, still it won't hurt to mention it.
But maybe the docs could need a general intro page mentioning general API usage hints as well as possible caveats.

Before you ask, I don't volunteer for this :). I really don't know libgit2 well enough to write such a page.

b4n added a commit to b4n/geany-plugins that referenced this issue May 26, 2015
Git uses its own path representation for files inside its tree, which
follows the UNIX path style (forward slashes).  So properly convert
internal paths from native to Git paths.

See libgit2/libgit2#3012

Part of Issue geany#214.
marcelogp pushed a commit to marcelogp/geany-plugins that referenced this issue Oct 26, 2015
Git uses its own path representation for files inside its tree, which
follows the UNIX path style (forward slashes).  So properly convert
internal paths from native to Git paths.

See libgit2/libgit2#3012

Part of Issue geany#214.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants