2 * This handles recursive filename detection with exclude
3 * files, index knowledge etc..
5 * Copyright (C) Linus Torvalds, 2005-2006
6 * Junio Hamano, 2005-2006
12 struct path_simplify
{
17 static int read_directory_recursive(struct dir_struct
*dir
, const char *path
, int len
,
18 int check_only
, const struct path_simplify
*simplify
);
19 static int get_dtype(struct dirent
*de
, const char *path
, int len
);
21 static int common_prefix(const char **pathspec
)
23 const char *path
, *slash
, *next
;
30 slash
= strrchr(path
, '/');
35 * The first 'prefix' characters of 'path' are common leading
36 * path components among the pathspecs we have seen so far,
37 * including the trailing slash.
39 prefix
= slash
- path
+ 1;
40 while ((next
= *++pathspec
) != NULL
) {
41 int len
, last_matching_slash
= -1;
42 for (len
= 0; len
< prefix
&& next
[len
] == path
[len
]; len
++)
44 last_matching_slash
= len
;
47 if (last_matching_slash
< 0)
49 prefix
= last_matching_slash
+ 1;
54 int fill_directory(struct dir_struct
*dir
, const char **pathspec
)
60 * Calculate common prefix for the pathspec, and
61 * use that to optimize the directory walk
63 len
= common_prefix(pathspec
);
67 path
= xmemdupz(*pathspec
, len
);
69 /* Read the directory and prune it */
70 read_directory(dir
, path
, len
, pathspec
);
75 * Does 'match' match the given name?
78 * (1) the 'match' string is leading directory of 'name', or
79 * (2) the 'match' string is a wildcard and matches 'name', or
80 * (3) the 'match' string is exactly the same as 'name'.
82 * and the return value tells which case it was.
84 * It returns 0 when there is no match.
86 static int match_one(const char *match
, const char *name
, int namelen
)
90 /* If the match was just the prefix, we matched */
92 return MATCHED_RECURSIVELY
;
95 unsigned char c1
= *match
;
96 unsigned char c2
= *name
;
97 if (c1
== '\0' || is_glob_special(c1
))
108 * If we don't match the matchstring exactly,
109 * we need to match by fnmatch
111 matchlen
= strlen(match
);
112 if (strncmp(match
, name
, matchlen
))
113 return !fnmatch(match
, name
, 0) ? MATCHED_FNMATCH
: 0;
115 if (namelen
== matchlen
)
116 return MATCHED_EXACTLY
;
117 if (match
[matchlen
-1] == '/' || name
[matchlen
] == '/')
118 return MATCHED_RECURSIVELY
;
123 * Given a name and a list of pathspecs, see if the name matches
124 * any of the pathspecs. The caller is also interested in seeing
125 * all pathspec matches some names it calls this function with
126 * (otherwise the user could have mistyped the unmatched pathspec),
127 * and a mark is left in seen[] array for pathspec element that
128 * actually matched anything.
130 int match_pathspec(const char **pathspec
, const char *name
, int namelen
,
131 int prefix
, char *seen
)
141 for (i
= 0; pathspec
[i
] != NULL
; i
++) {
143 const char *match
= pathspec
[i
] + prefix
;
144 if (seen
&& seen
[i
] == MATCHED_EXACTLY
)
146 how
= match_one(match
, name
, namelen
);
150 if (seen
&& seen
[i
] < how
)
157 static int no_wildcard(const char *string
)
159 return string
[strcspn(string
, "*?[{\\")] == '\0';
162 void add_exclude(const char *string
, const char *base
,
163 int baselen
, struct exclude_list
*which
)
170 if (*string
== '!') {
174 len
= strlen(string
);
175 if (len
&& string
[len
- 1] == '/') {
177 x
= xmalloc(sizeof(*x
) + len
);
179 memcpy(s
, string
, len
- 1);
183 flags
= EXC_FLAG_MUSTBEDIR
;
185 x
= xmalloc(sizeof(*x
));
188 x
->to_exclude
= to_exclude
;
189 x
->patternlen
= strlen(string
);
191 x
->baselen
= baselen
;
193 if (!strchr(string
, '/'))
194 x
->flags
|= EXC_FLAG_NODIR
;
195 if (no_wildcard(string
))
196 x
->flags
|= EXC_FLAG_NOWILDCARD
;
197 if (*string
== '*' && no_wildcard(string
+1))
198 x
->flags
|= EXC_FLAG_ENDSWITH
;
199 ALLOC_GROW(which
->excludes
, which
->nr
+ 1, which
->alloc
);
200 which
->excludes
[which
->nr
++] = x
;
203 static void *read_skip_worktree_file_from_index(const char *path
, size_t *size
)
207 enum object_type type
;
209 struct index_state
*istate
= &the_index
;
212 pos
= index_name_pos(istate
, path
, len
);
215 if (!ce_skip_worktree(istate
->cache
[pos
]))
217 data
= read_sha1_file(istate
->cache
[pos
]->sha1
, &type
, &sz
);
218 if (!data
|| type
!= OBJ_BLOB
) {
226 void free_excludes(struct exclude_list
*el
)
230 for (i
= 0; i
< el
->nr
; i
++)
231 free(el
->excludes
[i
]);
238 int add_excludes_from_file_to_list(const char *fname
,
242 struct exclude_list
*which
,
250 fd
= open(fname
, O_RDONLY
);
251 if (fd
< 0 || fstat(fd
, &st
) < 0) {
255 (buf
= read_skip_worktree_file_from_index(fname
, &size
)) == NULL
)
261 if (buf
[size
-1] != '\n') {
262 buf
= xrealloc(buf
, size
+1);
267 size
= xsize_t(st
.st_size
);
272 buf
= xmalloc(size
+1);
273 if (read_in_full(fd
, buf
, size
) != size
) {
285 for (i
= 0; i
< size
; i
++) {
286 if (buf
[i
] == '\n') {
287 if (entry
!= buf
+ i
&& entry
[0] != '#') {
288 buf
[i
- (i
&& buf
[i
-1] == '\r')] = 0;
289 add_exclude(entry
, base
, baselen
, which
);
297 void add_excludes_from_file(struct dir_struct
*dir
, const char *fname
)
299 if (add_excludes_from_file_to_list(fname
, "", 0, NULL
,
300 &dir
->exclude_list
[EXC_FILE
], 0) < 0)
301 die("cannot use %s as an exclude file", fname
);
304 static void prep_exclude(struct dir_struct
*dir
, const char *base
, int baselen
)
306 struct exclude_list
*el
;
307 struct exclude_stack
*stk
= NULL
;
310 if ((!dir
->exclude_per_dir
) ||
311 (baselen
+ strlen(dir
->exclude_per_dir
) >= PATH_MAX
))
312 return; /* too long a path -- ignore */
314 /* Pop the ones that are not the prefix of the path being checked. */
315 el
= &dir
->exclude_list
[EXC_DIRS
];
316 while ((stk
= dir
->exclude_stack
) != NULL
) {
317 if (stk
->baselen
<= baselen
&&
318 !strncmp(dir
->basebuf
, base
, stk
->baselen
))
320 dir
->exclude_stack
= stk
->prev
;
321 while (stk
->exclude_ix
< el
->nr
)
322 free(el
->excludes
[--el
->nr
]);
327 /* Read from the parent directories and push them down. */
328 current
= stk
? stk
->baselen
: -1;
329 while (current
< baselen
) {
330 struct exclude_stack
*stk
= xcalloc(1, sizeof(*stk
));
338 cp
= strchr(base
+ current
+ 1, '/');
340 die("oops in prep_exclude");
343 stk
->prev
= dir
->exclude_stack
;
344 stk
->baselen
= cp
- base
;
345 stk
->exclude_ix
= el
->nr
;
346 memcpy(dir
->basebuf
+ current
, base
+ current
,
347 stk
->baselen
- current
);
348 strcpy(dir
->basebuf
+ stk
->baselen
, dir
->exclude_per_dir
);
349 add_excludes_from_file_to_list(dir
->basebuf
,
350 dir
->basebuf
, stk
->baselen
,
351 &stk
->filebuf
, el
, 1);
352 dir
->exclude_stack
= stk
;
353 current
= stk
->baselen
;
355 dir
->basebuf
[baselen
] = '\0';
358 /* Scan the list and let the last match determine the fate.
359 * Return 1 for exclude, 0 for include and -1 for undecided.
361 int excluded_from_list(const char *pathname
,
362 int pathlen
, const char *basename
, int *dtype
,
363 struct exclude_list
*el
)
368 for (i
= el
->nr
- 1; 0 <= i
; i
--) {
369 struct exclude
*x
= el
->excludes
[i
];
370 const char *exclude
= x
->pattern
;
371 int to_exclude
= x
->to_exclude
;
373 if (x
->flags
& EXC_FLAG_MUSTBEDIR
) {
375 if (!prefixcmp(pathname
, exclude
) &&
376 pathname
[x
->patternlen
] == '/')
381 if (*dtype
== DT_UNKNOWN
)
382 *dtype
= get_dtype(NULL
, pathname
, pathlen
);
383 if (*dtype
!= DT_DIR
)
387 if (x
->flags
& EXC_FLAG_NODIR
) {
389 if (x
->flags
& EXC_FLAG_NOWILDCARD
) {
390 if (!strcmp(exclude
, basename
))
392 } else if (x
->flags
& EXC_FLAG_ENDSWITH
) {
393 if (x
->patternlen
- 1 <= pathlen
&&
394 !strcmp(exclude
+ 1, pathname
+ pathlen
- x
->patternlen
+ 1))
397 if (fnmatch(exclude
, basename
, 0) == 0)
402 /* match with FNM_PATHNAME:
403 * exclude has base (baselen long) implicitly
406 int baselen
= x
->baselen
;
410 if (pathlen
< baselen
||
411 (baselen
&& pathname
[baselen
-1] != '/') ||
412 strncmp(pathname
, x
->base
, baselen
))
415 if (x
->flags
& EXC_FLAG_NOWILDCARD
) {
416 if (!strcmp(exclude
, pathname
+ baselen
))
419 if (fnmatch(exclude
, pathname
+baselen
,
426 return -1; /* undecided */
429 int excluded(struct dir_struct
*dir
, const char *pathname
, int *dtype_p
)
431 int pathlen
= strlen(pathname
);
433 const char *basename
= strrchr(pathname
, '/');
434 basename
= (basename
) ? basename
+1 : pathname
;
436 prep_exclude(dir
, pathname
, basename
-pathname
);
437 for (st
= EXC_CMDL
; st
<= EXC_FILE
; st
++) {
438 switch (excluded_from_list(pathname
, pathlen
, basename
,
439 dtype_p
, &dir
->exclude_list
[st
])) {
449 static struct dir_entry
*dir_entry_new(const char *pathname
, int len
)
451 struct dir_entry
*ent
;
453 ent
= xmalloc(sizeof(*ent
) + len
+ 1);
455 memcpy(ent
->name
, pathname
, len
);
460 static struct dir_entry
*dir_add_name(struct dir_struct
*dir
, const char *pathname
, int len
)
462 if (cache_name_exists(pathname
, len
, ignore_case
))
465 ALLOC_GROW(dir
->entries
, dir
->nr
+1, dir
->alloc
);
466 return dir
->entries
[dir
->nr
++] = dir_entry_new(pathname
, len
);
469 struct dir_entry
*dir_add_ignored(struct dir_struct
*dir
, const char *pathname
, int len
)
471 if (!cache_name_is_other(pathname
, len
))
474 ALLOC_GROW(dir
->ignored
, dir
->ignored_nr
+1, dir
->ignored_alloc
);
475 return dir
->ignored
[dir
->ignored_nr
++] = dir_entry_new(pathname
, len
);
479 index_nonexistent
= 0,
485 * The index sorts alphabetically by entry name, which
486 * means that a gitlink sorts as '\0' at the end, while
487 * a directory (which is defined not as an entry, but as
488 * the files it contains) will sort with the '/' at the
491 static enum exist_status
directory_exists_in_index(const char *dirname
, int len
)
493 int pos
= cache_name_pos(dirname
, len
);
496 while (pos
< active_nr
) {
497 struct cache_entry
*ce
= active_cache
[pos
++];
498 unsigned char endchar
;
500 if (strncmp(ce
->name
, dirname
, len
))
502 endchar
= ce
->name
[len
];
506 return index_directory
;
507 if (!endchar
&& S_ISGITLINK(ce
->ce_mode
))
510 return index_nonexistent
;
514 * When we find a directory when traversing the filesystem, we
515 * have three distinct cases:
518 * - see it as a directory
521 * and which one we choose depends on a combination of existing
522 * git index contents and the flags passed into the directory
525 * Case 1: If we *already* have entries in the index under that
526 * directory name, we always recurse into the directory to see
529 * Case 2: If we *already* have that directory name as a gitlink,
530 * we always continue to see it as a gitlink, regardless of whether
531 * there is an actual git directory there or not (it might not
532 * be checked out as a subproject!)
534 * Case 3: if we didn't have it in the index previously, we
535 * have a few sub-cases:
537 * (a) if "show_other_directories" is true, we show it as
538 * just a directory, unless "hide_empty_directories" is
539 * also true and the directory is empty, in which case
540 * we just ignore it entirely.
541 * (b) if it looks like a git directory, and we don't have
542 * 'no_gitlinks' set we treat it as a gitlink, and show it
544 * (c) otherwise, we recurse into it.
546 enum directory_treatment
{
549 recurse_into_directory
552 static enum directory_treatment
treat_directory(struct dir_struct
*dir
,
553 const char *dirname
, int len
,
554 const struct path_simplify
*simplify
)
556 /* The "len-1" is to strip the final '/' */
557 switch (directory_exists_in_index(dirname
, len
-1)) {
558 case index_directory
:
559 return recurse_into_directory
;
562 if (dir
->flags
& DIR_SHOW_OTHER_DIRECTORIES
)
563 return ignore_directory
;
564 return show_directory
;
566 case index_nonexistent
:
567 if (dir
->flags
& DIR_SHOW_OTHER_DIRECTORIES
)
569 if (!(dir
->flags
& DIR_NO_GITLINKS
)) {
570 unsigned char sha1
[20];
571 if (resolve_gitlink_ref(dirname
, "HEAD", sha1
) == 0)
572 return show_directory
;
574 return recurse_into_directory
;
577 /* This is the "show_other_directories" case */
578 if (!(dir
->flags
& DIR_HIDE_EMPTY_DIRECTORIES
))
579 return show_directory
;
580 if (!read_directory_recursive(dir
, dirname
, len
, 1, simplify
))
581 return ignore_directory
;
582 return show_directory
;
586 * This is an inexact early pruning of any recursive directory
587 * reading - if the path cannot possibly be in the pathspec,
588 * return true, and we'll skip it early.
590 static int simplify_away(const char *path
, int pathlen
, const struct path_simplify
*simplify
)
594 const char *match
= simplify
->path
;
595 int len
= simplify
->len
;
601 if (!memcmp(path
, match
, len
))
611 * This function tells us whether an excluded path matches a
612 * list of "interesting" pathspecs. That is, whether a path matched
613 * by any of the pathspecs could possibly be ignored by excluding
614 * the specified path. This can happen if:
616 * 1. the path is mentioned explicitly in the pathspec
618 * 2. the path is a directory prefix of some element in the
621 static int exclude_matches_pathspec(const char *path
, int len
,
622 const struct path_simplify
*simplify
)
625 for (; simplify
->path
; simplify
++) {
626 if (len
== simplify
->len
627 && !memcmp(path
, simplify
->path
, len
))
629 if (len
< simplify
->len
630 && simplify
->path
[len
] == '/'
631 && !memcmp(path
, simplify
->path
, len
))
638 static int get_index_dtype(const char *path
, int len
)
641 struct cache_entry
*ce
;
643 ce
= cache_name_exists(path
, len
, 0);
645 if (!ce_uptodate(ce
))
647 if (S_ISGITLINK(ce
->ce_mode
))
650 * Nobody actually cares about the
651 * difference between DT_LNK and DT_REG
656 /* Try to look it up as a directory */
657 pos
= cache_name_pos(path
, len
);
661 while (pos
< active_nr
) {
662 ce
= active_cache
[pos
++];
663 if (strncmp(ce
->name
, path
, len
))
665 if (ce
->name
[len
] > '/')
667 if (ce
->name
[len
] < '/')
669 if (!ce_uptodate(ce
))
670 break; /* continue? */
676 static int get_dtype(struct dirent
*de
, const char *path
, int len
)
678 int dtype
= de
? DTYPE(de
) : DT_UNKNOWN
;
681 if (dtype
!= DT_UNKNOWN
)
683 dtype
= get_index_dtype(path
, len
);
684 if (dtype
!= DT_UNKNOWN
)
686 if (lstat(path
, &st
))
688 if (S_ISREG(st
.st_mode
))
690 if (S_ISDIR(st
.st_mode
))
692 if (S_ISLNK(st
.st_mode
))
697 enum path_treatment
{
703 static enum path_treatment
treat_one_path(struct dir_struct
*dir
,
704 char *path
, int *len
,
705 const struct path_simplify
*simplify
,
706 int dtype
, struct dirent
*de
)
708 int exclude
= excluded(dir
, path
, &dtype
);
709 if (exclude
&& (dir
->flags
& DIR_COLLECT_IGNORED
)
710 && exclude_matches_pathspec(path
, *len
, simplify
))
711 dir_add_ignored(dir
, path
, *len
);
714 * Excluded? If we don't explicitly want to show
715 * ignored files, ignore it
717 if (exclude
&& !(dir
->flags
& DIR_SHOW_IGNORED
))
720 if (dtype
== DT_UNKNOWN
)
721 dtype
= get_dtype(de
, path
, *len
);
724 * Do we want to see just the ignored files?
725 * We still need to recurse into directories,
726 * even if we don't ignore them, since the
727 * directory may contain files that we do..
729 if (!exclude
&& (dir
->flags
& DIR_SHOW_IGNORED
)) {
738 memcpy(path
+ *len
, "/", 2);
740 switch (treat_directory(dir
, path
, *len
, simplify
)) {
742 if (exclude
!= !!(dir
->flags
746 case recurse_into_directory
:
748 case ignore_directory
:
759 static enum path_treatment
treat_path(struct dir_struct
*dir
,
761 char *path
, int path_max
,
763 const struct path_simplify
*simplify
,
768 if (is_dot_or_dotdot(de
->d_name
) || !strcmp(de
->d_name
, ".git"))
770 *len
= strlen(de
->d_name
);
771 /* Ignore overly long pathnames! */
772 if (*len
+ baselen
+ 8 > path_max
)
774 memcpy(path
+ baselen
, de
->d_name
, *len
+ 1);
776 if (simplify_away(path
, *len
, simplify
))
780 return treat_one_path(dir
, path
, len
, simplify
, dtype
, de
);
784 * Read a directory tree. We currently ignore anything but
785 * directories, regular files and symlinks. That's because git
786 * doesn't handle them at all yet. Maybe that will change some
789 * Also, we ignore the name ".git" (even if it is not a directory).
790 * That likely will not change.
792 static int read_directory_recursive(struct dir_struct
*dir
,
793 const char *base
, int baselen
,
795 const struct path_simplify
*simplify
)
797 DIR *fdir
= opendir(*base
? base
: ".");
802 char path
[PATH_MAX
+ 1];
803 memcpy(path
, base
, baselen
);
805 while ((de
= readdir(fdir
)) != NULL
) {
807 switch (treat_path(dir
, de
, path
, sizeof(path
),
808 baselen
, simplify
, &len
)) {
810 contents
+= read_directory_recursive
811 (dir
, path
, len
, 0, simplify
);
822 dir_add_name(dir
, path
, len
);
831 static int cmp_name(const void *p1
, const void *p2
)
833 const struct dir_entry
*e1
= *(const struct dir_entry
**)p1
;
834 const struct dir_entry
*e2
= *(const struct dir_entry
**)p2
;
836 return cache_name_compare(e1
->name
, e1
->len
,
841 * Return the length of the "simple" part of a path match limiter.
843 static int simple_length(const char *match
)
848 unsigned char c
= *match
++;
850 if (c
== '\0' || is_glob_special(c
))
855 static struct path_simplify
*create_simplify(const char **pathspec
)
858 struct path_simplify
*simplify
= NULL
;
863 for (nr
= 0 ; ; nr
++) {
866 alloc
= alloc_nr(alloc
);
867 simplify
= xrealloc(simplify
, alloc
* sizeof(*simplify
));
872 simplify
[nr
].path
= match
;
873 simplify
[nr
].len
= simple_length(match
);
875 simplify
[nr
].path
= NULL
;
876 simplify
[nr
].len
= 0;
880 static void free_simplify(struct path_simplify
*simplify
)
885 static int treat_leading_path(struct dir_struct
*dir
,
886 const char *path
, int len
,
887 const struct path_simplify
*simplify
)
889 char pathbuf
[PATH_MAX
];
893 while (len
&& path
[len
- 1] == '/')
899 cp
= path
+ baselen
+ !!baselen
;
900 cp
= memchr(cp
, '/', path
+ len
- cp
);
905 memcpy(pathbuf
, path
, baselen
);
906 pathbuf
[baselen
] = '\0';
907 if (!is_directory(pathbuf
))
909 if (simplify_away(pathbuf
, baselen
, simplify
))
912 if (treat_one_path(dir
, pathbuf
, &blen
, simplify
,
913 DT_DIR
, NULL
) == path_ignored
)
914 return 0; /* do not recurse into it */
916 return 1; /* finished checking */
920 int read_directory(struct dir_struct
*dir
, const char *path
, int len
, const char **pathspec
)
922 struct path_simplify
*simplify
;
924 if (has_symlink_leading_path(path
, len
))
927 simplify
= create_simplify(pathspec
);
928 if (!len
|| treat_leading_path(dir
, path
, len
, simplify
))
929 read_directory_recursive(dir
, path
, len
, 0, simplify
);
930 free_simplify(simplify
);
931 qsort(dir
->entries
, dir
->nr
, sizeof(struct dir_entry
*), cmp_name
);
932 qsort(dir
->ignored
, dir
->ignored_nr
, sizeof(struct dir_entry
*), cmp_name
);
936 int file_exists(const char *f
)
939 return lstat(f
, &sb
) == 0;
943 * get_relative_cwd() gets the prefix of the current working directory
944 * relative to 'dir'. If we are not inside 'dir', it returns NULL.
946 * As a convenience, it also returns NULL if 'dir' is already NULL. The
947 * reason for this behaviour is that it is natural for functions returning
948 * directory names to return NULL to say "this directory does not exist"
949 * or "this directory is invalid". These cases are usually handled the
950 * same as if the cwd is not inside 'dir' at all, so get_relative_cwd()
951 * returns NULL for both of them.
953 * Most notably, get_relative_cwd(buffer, size, get_git_work_tree())
954 * unifies the handling of "outside work tree" with "no work tree at all".
956 char *get_relative_cwd(char *buffer
, int size
, const char *dir
)
962 if (!getcwd(buffer
, size
))
963 die_errno("can't find the current directory");
965 if (!is_absolute_path(dir
))
966 dir
= make_absolute_path(dir
);
968 while (*dir
&& *dir
== *cwd
) {
984 int is_inside_dir(const char *dir
)
986 char buffer
[PATH_MAX
];
987 return get_relative_cwd(buffer
, sizeof(buffer
), dir
) != NULL
;
990 int is_empty_dir(const char *path
)
992 DIR *dir
= opendir(path
);
999 while ((e
= readdir(dir
)) != NULL
)
1000 if (!is_dot_or_dotdot(e
->d_name
)) {
1009 int remove_dir_recursively(struct strbuf
*path
, int flag
)
1013 int ret
= 0, original_len
= path
->len
, len
;
1014 int only_empty
= (flag
& REMOVE_DIR_EMPTY_ONLY
);
1015 unsigned char submodule_head
[20];
1017 if ((flag
& REMOVE_DIR_KEEP_NESTED_GIT
) &&
1018 !resolve_gitlink_ref(path
->buf
, "HEAD", submodule_head
))
1019 /* Do not descend and nuke a nested git work tree. */
1022 dir
= opendir(path
->buf
);
1025 if (path
->buf
[original_len
- 1] != '/')
1026 strbuf_addch(path
, '/');
1029 while ((e
= readdir(dir
)) != NULL
) {
1031 if (is_dot_or_dotdot(e
->d_name
))
1034 strbuf_setlen(path
, len
);
1035 strbuf_addstr(path
, e
->d_name
);
1036 if (lstat(path
->buf
, &st
))
1038 else if (S_ISDIR(st
.st_mode
)) {
1039 if (!remove_dir_recursively(path
, only_empty
))
1040 continue; /* happy */
1041 } else if (!only_empty
&& !unlink(path
->buf
))
1042 continue; /* happy, too */
1044 /* path too long, stat fails, or non-directory still exists */
1050 strbuf_setlen(path
, original_len
);
1052 ret
= rmdir(path
->buf
);
1056 void setup_standard_excludes(struct dir_struct
*dir
)
1060 dir
->exclude_per_dir
= ".gitignore";
1061 path
= git_path("info/exclude");
1062 if (!access(path
, R_OK
))
1063 add_excludes_from_file(dir
, path
);
1064 if (excludes_file
&& !access(excludes_file
, R_OK
))
1065 add_excludes_from_file(dir
, excludes_file
);
1068 int remove_path(const char *name
)
1072 if (unlink(name
) && errno
!= ENOENT
)
1075 slash
= strrchr(name
, '/');
1077 char *dirs
= xstrdup(name
);
1078 slash
= dirs
+ (slash
- name
);
1081 } while (rmdir(dirs
) == 0 && (slash
= strrchr(dirs
, '/')));