Skip to content

Commit 19ef3dd

Browse files
HebaWalygitster
authored andcommitted
pathspec: move doc to pathspec.h
Move the documentation from Documentation/technical/api-setup.txt to pathspec.h as it's easier for the developers to find the usage information beside the code instead of looking for it in another doc file. Also documentation/technical/api-setup.txt is removed because the information it has is now redundant and it'll be hard to keep it up to date and synchronized with the documentation in the header file. Signed-off-by: Heba Waly <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 301d595 commit 19ef3dd

File tree

2 files changed

+34
-48
lines changed

2 files changed

+34
-48
lines changed

Documentation/technical/api-setup.txt

Lines changed: 0 additions & 47 deletions
This file was deleted.

pathspec.h

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ struct index_state;
2222

2323
#define PATHSPEC_ONESTAR 1 /* the pathspec pattern satisfies GFNM_ONESTAR */
2424

25+
/**
26+
* See glossary-context.txt for the syntax of pathspec.
27+
* In memory, a pathspec set is represented by "struct pathspec" and is
28+
* prepared by parse_pathspec().
29+
*/
2530
struct pathspec {
2631
int nr;
2732
unsigned int has_wildcard:1;
@@ -73,18 +78,46 @@ struct pathspec {
7378
*/
7479
#define PATHSPEC_LITERAL_PATH (1<<6)
7580

76-
/*
81+
/**
7782
* Given command line arguments and a prefix, convert the input to
7883
* pathspec. die() if any magic in magic_mask is used.
7984
*
8085
* Any arguments used are copied. It is safe for the caller to modify
8186
* or free 'prefix' and 'args' after calling this function.
87+
*
88+
* - magic_mask specifies what features that are NOT supported by the following
89+
* code. If a user attempts to use such a feature, parse_pathspec() can reject
90+
* it early.
91+
*
92+
* - flags specifies other things that the caller wants parse_pathspec to
93+
* perform.
94+
*
95+
* - prefix and args come from cmd_* functions
96+
*
97+
* parse_pathspec() helps catch unsupported features and reject them politely.
98+
* At a lower level, different pathspec-related functions may not support the
99+
* same set of features. Such pathspec-sensitive functions are guarded with
100+
* GUARD_PATHSPEC(), which will die in an unfriendly way when an unsupported
101+
* feature is requested.
102+
*
103+
* The command designers are supposed to make sure that GUARD_PATHSPEC() never
104+
* dies. They have to make sure all unsupported features are caught by
105+
* parse_pathspec(), not by GUARD_PATHSPEC. grepping GUARD_PATHSPEC() should
106+
* give the designers all pathspec-sensitive codepaths and what features they
107+
* support.
108+
*
109+
* A similar process is applied when a new pathspec magic is added. The designer
110+
* lifts the GUARD_PATHSPEC restriction in the functions that support the new
111+
* magic. At the same time (s)he has to make sure this new feature will be
112+
* caught at parse_pathspec() in commands that cannot handle the new magic in
113+
* some cases. grepping parse_pathspec() should help.
82114
*/
83115
void parse_pathspec(struct pathspec *pathspec,
84116
unsigned magic_mask,
85117
unsigned flags,
86118
const char *prefix,
87119
const char **args);
120+
88121
void copy_pathspec(struct pathspec *dst, const struct pathspec *src);
89122
void clear_pathspec(struct pathspec *);
90123

0 commit comments

Comments
 (0)