Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions 8 Documentation/gitignore.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ PATTERN FORMAT
for readability.

- A line starting with # serves as a comment.
Put a backslash ("`\`") in front of the first hash for patterns
that begin with a hash.
Put a backslash ("`\`") in front of each hash for patterns
containing a hash.

- A # after a pattern will be treated as the start of a comment.
Put a backslash ("`\`") in front of each hash for patterns
containing a hash.

- Trailing spaces are ignored unless they are quoted with backslash
("`\`").
Expand Down
33 changes: 33 additions & 0 deletions 33 dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,38 @@ void clear_pattern_list(struct pattern_list *pl)
memset(pl, 0, sizeof(*pl));
}

static void trim_trailing_comments(char *buf)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is very similar to trim_trailing_spaces(). l don't think logic should be put at all costs in one single function, but it's worth thinking if they can be merged somehow.

{
char *p, *last_hash = NULL;
int escape_seq = 0;

for (p = buf; *p; p++)
{
if (!*p)
return;
switch (*p) {
case '#':
if (escape_seq)
{
escape_seq = 0;
p++;
break;
}
if (!last_hash)
last_hash = p;
break;
case '\\':
escape_seq = 1;
break;
default:
escape_seq = 0;
}
}

if (last_hash)
*last_hash = '\0';
}

static void trim_trailing_spaces(char *buf)
{
char *p, *last_space = NULL;
Expand Down Expand Up @@ -859,6 +891,7 @@ static int add_patterns_from_buffer(char *buf, size_t size,
if (buf[i] == '\n') {
if (entry != buf + i && entry[0] != '#') {
buf[i - (i && buf[i-1] == '\r')] = 0;
trim_trailing_comments(entry);
trim_trailing_spaces(entry);
add_pattern(entry, base, baselen, pl, lineno);
}
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.