Skip to content

Commit f010b66

Browse files
authored
Merge pull request libgit2#4849 from libgit2/cmn/expose-gitfile-check
path: export the dotgit-checking functions
2 parents 5be63f6 + 05e54e0 commit f010b66

File tree

2 files changed

+66
-38
lines changed

2 files changed

+66
-38
lines changed

include/git2/sys/path.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (C) the libgit2 contributors. All rights reserved.
3+
*
4+
* This file is part of libgit2, distributed under the GNU GPL v2 with
5+
* a Linking Exception. For full terms see the included COPYING file.
6+
*/
7+
8+
#ifndef INCLUDE_sys_git_path_h__
9+
#define INCLUDE_sys_git_path_h__
10+
11+
#include "git2/common.h"
12+
13+
GIT_BEGIN_DECL
14+
15+
/**
16+
* The kinds of git-specific files we know about.
17+
*
18+
* The order needs to stay the same to not break the `gitfiles`
19+
* array in path.c
20+
*/
21+
typedef enum {
22+
/** Check for the .gitignore file */
23+
GIT_PATH_GITFILE_GITIGNORE,
24+
/** Check for the .gitmodules file */
25+
GIT_PATH_GITFILE_GITMODULES,
26+
/** Check for the .gitattributes file */
27+
GIT_PATH_GITFILE_GITATTRIBUTES
28+
} git_path_gitfile;
29+
30+
/**
31+
* The kinds of checks to perform according to which filesystem we are trying to
32+
* protect.
33+
*/
34+
typedef enum {
35+
/** Do both NTFS- and HFS-specific checks */
36+
GIT_PATH_FS_GENERIC,
37+
/** Do NTFS-specific checks only */
38+
GIT_PATH_FS_NTFS,
39+
/** Do HFS-specific checks only */
40+
GIT_PATH_FS_HFS
41+
} git_path_fs;
42+
43+
/**
44+
* Check whether a path component corresponds to a .git$SUFFIX
45+
* file.
46+
*
47+
* As some filesystems do special things to filenames when
48+
* writing files to disk, you cannot always do a plain string
49+
* comparison to verify whether a file name matches an expected
50+
* path or not. This function can do the comparison for you,
51+
* depending on the filesystem you're on.
52+
*
53+
* @param path the path component to check
54+
* @param pathlen the length of `path` that is to be checked
55+
* @param gitfile which file to check against
56+
* @param fs which filesystem-specific checks to use
57+
* @return 0 in case the file does not match, a positive value if
58+
* it does; -1 in case of an error
59+
*/
60+
GIT_EXTERN(int) git_path_is_gitfile(const char *path, size_t pathlen, git_path_gitfile gitfile, git_path_fs fs);
61+
62+
GIT_END_DECL
63+
64+
#endif /* INCLUDE_sys_git_path */

src/path.h

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include "buffer.h"
1414
#include "vector.h"
1515

16+
#include "git2/sys/path.h"
17+
1618
/**
1719
* Path manipulation utils
1820
*
@@ -645,42 +647,4 @@ extern bool git_path_isvalid(
645647
*/
646648
int git_path_normalize_slashes(git_buf *out, const char *path);
647649

648-
/*
649-
* The order needs to stay the same to not break the `gitfiles`
650-
* array in path.c
651-
*/
652-
typedef enum {
653-
GIT_PATH_GITFILE_GITIGNORE,
654-
GIT_PATH_GITFILE_GITMODULES,
655-
GIT_PATH_GITFILE_GITATTRIBUTES
656-
} git_path_gitfile;
657-
658-
typedef enum {
659-
/* Do both NTFS- and HFS-specific checks */
660-
GIT_PATH_FS_GENERIC,
661-
/* Do NTFS-specific checks only */
662-
GIT_PATH_FS_NTFS,
663-
/* Do HFS-specific checks only */
664-
GIT_PATH_FS_HFS
665-
} git_path_fs;
666-
667-
/**
668-
* Check whether a path component corresponds to a .git$SUFFIX
669-
* file.
670-
*
671-
* As some filesystems do special things to filenames when
672-
* writing files to disk, you cannot always do a plain string
673-
* comparison to verify whether a file name matches an expected
674-
* path or not. This function can do the comparison for you,
675-
* depending on the filesystem you're on.
676-
*
677-
* @param path the path component to check
678-
* @param pathlen the length of `path` that is to be checked
679-
* @param gitfile which file to check against
680-
* @param fs which filesystem-specific checks to use
681-
* @return 0 in case the file does not match, a positive value if
682-
* it does; -1 in case of an error
683-
*/
684-
extern int git_path_is_gitfile(const char *path, size_t pathlen, git_path_gitfile gitfile, git_path_fs fs);
685-
686650
#endif

0 commit comments

Comments
 (0)