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

Remove svn ignore code. #1024

Merged
merged 1 commit into from
Nov 27, 2016
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Ag is quite stable now. Most changes are new features, minor bug fixes, or perfo

ag test_blah ~/code/ 4.67s user 4.58s system 286% cpu 3.227 total

Ack and Ag found the same results, but Ag was 34x faster (3.2 seconds vs 110 seconds). My `~/code` directory is about 8GB. Thanks to git/hg/svn-ignore, Ag only searched 700MB of that.
Ack and Ag found the same results, but Ag was 34x faster (3.2 seconds vs 110 seconds). My `~/code` directory is about 8GB. Thanks to git/hg/ignore, Ag only searched 700MB of that.

There are also [graphs of performance across releases](http://geoff.greer.fm/ag/speed/).

Expand Down
11 changes: 5 additions & 6 deletions doc/ag.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ Recursively search for PATTERN in PATH. Like grep or ack, but faster.
binary and hidden files as well.

* `-U --skip-vcs-ignores`:
Ignore VCS ignore files (.gitignore, .hgignore, svn:ignore), but still
Ignore VCS ignore files (.gitignore, .hgignore), but still
use .ignore.

* `-v --invert-match`:
Expand Down Expand Up @@ -226,12 +226,11 @@ or `xhtml`. For a list of supported types, run `ag --list-file-types`.

By default, ag will ignore files whose names match patterns in .gitignore,
.hgignore, or .ignore. These files can be anywhere in the directories being
searched. Ag also ignores files matched by the svn:ignore property if `svn
--version` is 1.6 or older. Finally, ag looks in $HOME/.agignore for ignore
patterns. Binary files are ignored by default as well.
searched. Binary files are ignored by default as well. Finally, ag looks in
$HOME/.agignore for ignore patterns.

If you want to ignore .gitignore, .hgignore, and svn:ignore, but still take
.ignore into account, use `-U`.
If you want to ignore .gitignore and .hgignore, but still take .ignore into
account, use `-U`.

Use the `-t` option to search all text files; `-a` to search all files; and `-u`
to search all, including hidden files.
Expand Down
79 changes: 0 additions & 79 deletions src/ignore.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const char *ignore_pattern_files[] = {
".gitignore",
".git/info/exclude",
".hgignore",
".svn",
NULL
};

Expand Down Expand Up @@ -189,84 +188,6 @@ void load_ignore_patterns(ignores *ig, const char *path) {
fclose(fp);
}

void load_svn_ignore_patterns(ignores *ig, const char *path) {
FILE *fp = NULL;
char *dir_prop_base;
ag_asprintf(&dir_prop_base, "%s/%s", path, SVN_DIR_PROP_BASE);

fp = fopen(dir_prop_base, "r");
if (fp == NULL) {
log_debug("Skipping svn ignore file %s", dir_prop_base);
free(dir_prop_base);
return;
}

char *entry = NULL;
size_t entry_len = 0;
char *key = ag_malloc(32); /* Sane start for max key length. */
size_t key_len = 0;
size_t bytes_read = 0;
char *entry_line;
size_t line_len;
int matches;

while (fscanf(fp, "K %zu\n", &key_len) == 1) {
if (key_len >= INT_MAX) {
log_debug("Unable to parse svnignore file %s: key is absurdly long.", dir_prop_base);
goto cleanup;
}
key = ag_realloc(key, key_len + 1);
bytes_read = fread(key, 1, key_len, fp);
key[key_len] = '\0';
matches = fscanf(fp, "\nV %zu\n", &entry_len);
if (matches != 1) {
log_debug("Unable to parse svnignore file %s: fscanf() got %i matches, expected 1.", dir_prop_base, matches);
goto cleanup;
}

if (strncmp(SVN_PROP_IGNORE, key, bytes_read) != 0) {
log_debug("key is %s, not %s. skipping %u bytes", key, SVN_PROP_IGNORE, entry_len);
/* Not the key we care about. fseek and repeat */
int rv = fseek(fp, entry_len + 1, SEEK_CUR); /* +1 to account for newline. yes I know this is hacky */
if (rv == -1) {
log_debug("Skipping svnignore file %s: fseek() error.", dir_prop_base);
goto cleanup;
}
continue;
}
/* Aww yeah. Time to ignore stuff */
entry = ag_malloc(entry_len + 1);
bytes_read = fread(entry, 1, entry_len, fp);
entry[bytes_read] = '\0';
log_debug("entry: %s", entry);
break;
}
if (entry == NULL) {
goto cleanup;
}
char *patterns = entry;
size_t patterns_len = strlen(patterns);
while (*patterns != '\0' && patterns < (entry + bytes_read)) {
for (line_len = 0; line_len < patterns_len; line_len++) {
if (patterns[line_len] == '\n') {
break;
}
}
if (line_len > 0) {
entry_line = ag_strndup(patterns, line_len);
add_ignore_pattern(ig, entry_line);
free(entry_line);
}
patterns += line_len + 1;
patterns_len -= line_len + 1;
}
free(entry);
cleanup:
free(dir_prop_base);
free(key);
fclose(fp);
}

static int ackmate_dir_match(const char *dir_name) {
if (opts.ackmate_dir_filter == NULL) {
return 0;
Expand Down
5 changes: 0 additions & 5 deletions src/ignore.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
#include <dirent.h>
#include <sys/types.h>

#define SVN_DIR_PROP_BASE "dir-prop-base"
#define SVN_DIR ".svn"
#define SVN_PROP_IGNORE "svn:ignore"

struct ignores {
char **extensions; /* File extensions to ignore */
size_t extensions_len;
Expand Down Expand Up @@ -42,7 +38,6 @@ void cleanup_ignore(ignores *ig);
void add_ignore_pattern(ignores *ig, const char *pattern);

void load_ignore_patterns(ignores *ig, const char *path);
void load_svn_ignore_patterns(ignores *ig, const char *path);

int filename_filter(const char *path, const struct dirent *dir, void *baton);

Expand Down
2 changes: 1 addition & 1 deletion src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Search Options:\n\
-u --unrestricted Search all files (ignore .ignore, .gitignore, etc.;\n\
searches binary and hidden files as well)\n\
-U --skip-vcs-ignores Ignore VCS ignore files\n\
(.gitignore, .hgignore, .svnignore; still obey .ignore)\n\
(.gitignore, .hgignore; still obey .ignore)\n\
-v --invert-match\n\
-w --word-regexp Only match whole words\n\
-W --width NUM Truncate match lines after NUM characters\n\
Expand Down
6 changes: 1 addition & 5 deletions src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,11 +481,7 @@ void search_dir(ignores *ig, const char *base_path, const char *path, const int
for (i = 0; opts.skip_vcs_ignores ? (i <= 1) : (ignore_pattern_files[i] != NULL); i++) {
ignore_file = ignore_pattern_files[i];
ag_asprintf(&dir_full_path, "%s/%s", path, ignore_file);
if (strcmp(SVN_DIR, ignore_file) == 0) {
load_svn_ignore_patterns(ig, dir_full_path);
} else {
load_ignore_patterns(ig, dir_full_path);
}
load_ignore_patterns(ig, dir_full_path);
free(dir_full_path);
dir_full_path = NULL;
}
Expand Down