fetchGit/fetchMercurial: Filter out directories with untracked files
This commit is contained in:
		
							parent
							
								
									4dee01da7c
								
							
						
					
					
						commit
						ee6ac38848
					
				
					 4 changed files with 28 additions and 14 deletions
				
			
		|  | @ -47,11 +47,15 @@ HgInfo exportMercurial(ref<Store> store, const std::string & uri, | ||||||
| 
 | 
 | ||||||
|             PathFilter filter = [&](const Path & p) -> bool { |             PathFilter filter = [&](const Path & p) -> bool { | ||||||
|                 assert(hasPrefix(p, uri)); |                 assert(hasPrefix(p, uri)); | ||||||
|                 auto st = lstat(p); |  | ||||||
|                 std::string file(p, uri.size() + 1); |                 std::string file(p, uri.size() + 1); | ||||||
|                 if (file == ".hg") return false; | 
 | ||||||
|                 // FIXME: filter out directories with no tracked files.
 |                 auto st = lstat(p); | ||||||
|                 if (S_ISDIR(st.st_mode)) return true; | 
 | ||||||
|  |                 if (S_ISDIR(st.st_mode)) { | ||||||
|  |                     auto i = files.lower_bound(file); | ||||||
|  |                     return i != files.end() && hasPrefix(*i, file); | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|                 return files.count(file); |                 return files.count(file); | ||||||
|             }; |             }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -44,11 +44,15 @@ GitInfo exportGit(ref<Store> store, const std::string & uri, | ||||||
| 
 | 
 | ||||||
|             PathFilter filter = [&](const Path & p) -> bool { |             PathFilter filter = [&](const Path & p) -> bool { | ||||||
|                 assert(hasPrefix(p, uri)); |                 assert(hasPrefix(p, uri)); | ||||||
|                 auto st = lstat(p); |  | ||||||
|                 std::string file(p, uri.size() + 1); |                 std::string file(p, uri.size() + 1); | ||||||
|                 if (file == ".git") return false; | 
 | ||||||
|                 // FIXME: filter out directories with no tracked files.
 |                 auto st = lstat(p); | ||||||
|                 if (S_ISDIR(st.st_mode)) return true; | 
 | ||||||
|  |                 if (S_ISDIR(st.st_mode)) { | ||||||
|  |                     auto i = files.lower_bound(file); | ||||||
|  |                     return i != files.end() && hasPrefix(*i, file); | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|                 return files.count(file); |                 return files.count(file); | ||||||
|             }; |             }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -57,15 +57,18 @@ path2=$(nix eval --raw "(builtins.fetchGit $repo).outPath") | ||||||
| [[ $path = $path2 ]] | [[ $path = $path2 ]] | ||||||
| 
 | 
 | ||||||
| # Using an unclean tree should yield the tracked but uncommitted changes. | # Using an unclean tree should yield the tracked but uncommitted changes. | ||||||
| echo foo > $repo/foo | mkdir $repo/dir1 $repo/dir2 | ||||||
|  | echo foo > $repo/dir1/foo | ||||||
| echo bar > $repo/bar | echo bar > $repo/bar | ||||||
| git -C $repo add foo | echo bar > $repo/dir2/bar | ||||||
|  | git -C $repo add dir1/foo | ||||||
| git -C $repo rm hello | git -C $repo rm hello | ||||||
| 
 | 
 | ||||||
| path2=$(nix eval --raw "(builtins.fetchGit $repo).outPath") | path2=$(nix eval --raw "(builtins.fetchGit $repo).outPath") | ||||||
| [ ! -e $path2/hello ] | [ ! -e $path2/hello ] | ||||||
| [ ! -e $path2/bar ] | [ ! -e $path2/bar ] | ||||||
| [[ $(cat $path2/foo) = foo ]] | [ ! -e $path2/dir2/bar ] | ||||||
|  | [[ $(cat $path2/dir1/foo) = foo ]] | ||||||
| 
 | 
 | ||||||
| [[ $(nix eval --raw "(builtins.fetchGit $repo).rev") = 0000000000000000000000000000000000000000 ]] | [[ $(nix eval --raw "(builtins.fetchGit $repo).rev") = 0000000000000000000000000000000000000000 ]] | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -58,15 +58,18 @@ path2=$(nix eval --raw "(builtins.fetchMercurial $repo).outPath") | ||||||
| [[ $path = $path2 ]] | [[ $path = $path2 ]] | ||||||
| 
 | 
 | ||||||
| # Using an unclean tree should yield the tracked but uncommitted changes. | # Using an unclean tree should yield the tracked but uncommitted changes. | ||||||
| echo foo > $repo/foo | mkdir $repo/dir1 $repo/dir2 | ||||||
|  | echo foo > $repo/dir1/foo | ||||||
| echo bar > $repo/bar | echo bar > $repo/bar | ||||||
| hg add --cwd $repo foo | echo bar > $repo/dir2/bar | ||||||
|  | hg add --cwd $repo dir1/foo | ||||||
| hg rm --cwd $repo hello | hg rm --cwd $repo hello | ||||||
| 
 | 
 | ||||||
| path2=$(nix eval --raw "(builtins.fetchMercurial $repo).outPath") | path2=$(nix eval --raw "(builtins.fetchMercurial $repo).outPath") | ||||||
| [ ! -e $path2/hello ] | [ ! -e $path2/hello ] | ||||||
| [ ! -e $path2/bar ] | [ ! -e $path2/bar ] | ||||||
| [[ $(cat $path2/foo) = foo ]] | [ ! -e $path2/dir2/bar ] | ||||||
|  | [[ $(cat $path2/dir1/foo) = foo ]] | ||||||
| 
 | 
 | ||||||
| [[ $(nix eval --raw "(builtins.fetchMercurial $repo).rev") = 0000000000000000000000000000000000000000 ]] | [[ $(nix eval --raw "(builtins.fetchMercurial $repo).rev") = 0000000000000000000000000000000000000000 ]] | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue