Skip to content
This repository
Browse code

Kill trailing whitespace in ignore patterns.

  • Loading branch information...
commit df39348459622e1c362dcd0c275f3e7993d703ce 1 parent ddc9366
Geoff Greer authored

Showing 1 changed file with 11 additions and 2 deletions. Show diff stats Hide diff stats

  1. 13  src/ignore.c
13  src/ignore.c
... ...
@@ -1,3 +1,4 @@
  1
+#include <ctype.h>
1 2
 #include <dirent.h>
2 3
 #include <fnmatch.h>
3 4
 #include <stdio.h>
@@ -62,17 +63,25 @@ void cleanup_ignore(ignores *ig) {
62 63
 
63 64
 void add_ignore_pattern(ignores *ig, const char* pattern) {
64 65
     int i;
  66
+    int pattern_len;
65 67
 
66 68
     /* Strip off the leading ./ so that matches are more likely. */
67 69
     if (strncmp(pattern, "./", 2) == 0) {
68 70
         pattern += 2;
69 71
     }
70 72
 
  73
+    /* Kill trailing whitespace */
  74
+    for (pattern_len = strlen(pattern); pattern_len > 0; pattern--) {
  75
+        if (!isspace(pattern[i])) {
  76
+            break;
  77
+        }
  78
+    }
  79
+
71 80
     /* TODO: de-dupe these patterns */
72 81
     if (is_fnmatch(pattern)) {
73 82
         ig->regexes_len++;
74 83
         ig->regexes = ag_realloc(ig->regexes, ig->regexes_len * sizeof(char*));
75  
-        ig->regexes[ig->regexes_len - 1] = ag_strdup(pattern);
  84
+        ig->regexes[ig->regexes_len - 1] = ag_strndup(pattern, pattern_len);
76 85
         log_debug("added regex ignore pattern %s", pattern);
77 86
     } else {
78 87
         /* a balanced binary tree is best for performance, but I'm lazy */
@@ -84,7 +93,7 @@ void add_ignore_pattern(ignores *ig, const char* pattern) {
84 93
             }
85 94
             ig->names[i] = ig->names[i-1];
86 95
         }
87  
-        ig->names[i] = ag_strdup(pattern);
  96
+        ig->names[i] = ag_strndup(pattern, pattern_len);
88 97
         log_debug("added literal ignore pattern %s", pattern);
89 98
     }
90 99
 }

0 notes on commit df39348

Please sign in to comment.
Something went wrong with that request. Please try again.