Merge branch 'bw/rebase-autostash-keep-current-branch'
[gitweb.git] / dir.c
diff --git a/dir.c b/dir.c
index b057bd3d95a27c4bb4bc5f38f391438bddf634e7..cab9c2a4588669f3aef3637ada377712998fa01a 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -701,7 +701,7 @@ static struct untracked_cache_dir *lookup_untracked(struct untracked_cache *uc,
        first = 0;
        last = dir->dirs_nr;
        while (last > first) {
-               int cmp, next = (last + first) >> 1;
+               int cmp, next = first + ((last - first) >> 1);
                d = dir->dirs[next];
                cmp = strncmp(name, d->name, len);
                if (!cmp && strlen(d->name) > len)
@@ -1072,19 +1072,28 @@ static struct path_pattern *last_matching_pattern_from_list(const char *pathname
 }
 
 /*
- * Scan the list and let the last match determine the fate.
- * Return 1 for exclude, 0 for include and -1 for undecided.
+ * Scan the list of patterns to determine if the ordered list
+ * of patterns matches on 'pathname'.
+ *
+ * Return 1 for a match, 0 for not matched and -1 for undecided.
  */
-int is_excluded_from_list(const char *pathname,
-                         int pathlen, const char *basename, int *dtype,
-                         struct pattern_list *pl, struct index_state *istate)
+enum pattern_match_result path_matches_pattern_list(
+                               const char *pathname, int pathlen,
+                               const char *basename, int *dtype,
+                               struct pattern_list *pl,
+                               struct index_state *istate)
 {
        struct path_pattern *pattern;
        pattern = last_matching_pattern_from_list(pathname, pathlen, basename,
                                                  dtype, pl, istate);
-       if (pattern)
-               return pattern->flags & PATTERN_FLAG_NEGATIVE ? 0 : 1;
-       return -1; /* undecided */
+       if (pattern) {
+               if (pattern->flags & PATTERN_FLAG_NEGATIVE)
+                       return NOT_MATCHED;
+               else
+                       return MATCHED;
+       }
+
+       return UNDECIDED;
 }
 
 static struct path_pattern *last_matching_pattern_from_lists(