Git 暂存文件遍历

@param {Array<string>} patterns 要搜寻的 glob 数组
@param {Array<string>} ignorePatterns 忽略的 glob 数组

@returns {Promise<object>} fileTree
486506
function stageFiles (patterns, ignorePatterns) {
  const baseDir = getBaseDir()

  // 如果 baseDir 根本不存在 sgf 会抛出异常
  if (!fs.existsSync(baseDir)) {
    return Promise.resolve([])
  }

  sgf.cwd = baseDir

  return new Promise(resolve => {
    sgf((err, result) => {
      if (err) {
        debug('staged-git-files error: %o', err)
        return resolve([])
      }

      const fileList = result
        .filter(item => item.status !== 'Deleted') // 过滤已删除的文件
        .filter(item => match(item.filename, patterns, ignorePatterns))
        .map(item => item.filename)

      resolve(fileList)
    })
  })
}
1234138
function pglob(pattern, options) {
  return new Promise((resolve, reject) => {
    glob(pattern, options, (error, files) => {
      if (error) {
        return reject(error)
      }
      resolve(files)
    })
  })
}
1261928
function walk(path, pattern, depth) {
  const files = fs.readdirSync(path);
  let fileList = [];

  files.forEach((name) => {
    const filePath = join(path, name);
    const stat = fs.statSync(filePath);
    if (stat.isFile() && pattern.test(filePath)) {
      fileList.push(filePath);
    } else if ((depth > 1 || depth === 0) && stat.isDirectory()) {
      const list = walk(filePath, pattern, depth && depth - 1);
      fileList = fileList.concat(list);
    }
  });

  return fileList;
}
1208202
function parsePattern(pattern) {
	var regexSpecialChars = /[\-\[\]\/\{\}\(\)\+\?\.\\\^\$\|]/g;
	// Treat consecutive wildcards as one (#12)
	var wildCardPattern = /\*+/g;
	var endOfLinePattern = /\\\$$/;

	pattern = normaliseEncoding(pattern)

	if (pattern.indexOf('*') < 0 && pattern.indexOf('$') < 0) {
		return pattern;
	}

	pattern = pattern
		.replace(regexSpecialChars, '\\$&')
		.replace(wildCardPattern, '(?:.*)')
		.replace(endOfLinePattern, '$');

	return new RegExp(pattern);
}
842564
func ReadPatterns(fs billy.Filesystem, path []string) (ps []Pattern, err error) {
	ps, _ = readIgnoreFile(fs, path, gitignoreFile)

	var fis []os.FileInfo
	fis, err = fs.ReadDir(fs.Join(path...))
	if err != nil {
		return
	}

	for _, fi := range fis {
		if fi.IsDir() && fi.Name() != gitDir {
			var subps []Pattern
			subps, err = ReadPatterns(fs, append(path, fi.Name()))
			if err != nil {
				return
			}

			if len(subps) > 0 {
				ps = append(ps, subps...)
			}
		}
	}

	return
}
781443
function( patterns, options ){

        options = options || {};

        var deferred = Q.defer(),
            updateHTMLFile = this.updateHTMLFile,
            results = {
                success: [],
                error: []
            };

        globby( patterns, options, function( err, files ){
            if( err ){
                deferred.reject( err );
                return;
            }

            files.reduce( function( previousUpdating, currentTargetFilePath ){
                return previousUpdating.then(
                    function( previousPath ){
                        if( previousPath ){
                            results.success.push( previousPath );
                        }
                        return updateHTMLFile( currentTargetFilePath );
                    }
                );
            }, Q() )
                .then(
                    function( lastPath ){
                        results.success.push( lastPath );
                        deferred.resolve( results );
                    },
                    function( e ){
                        deferred.reject( e );
                    }
                );
        } );

        return deferred.promise;
    }
410523
function any(/* patterns... */) {
        var patterns = [].slice.call(arguments, 0);
        var name = '(' + patterns.join(' | ') + ')';

        return new Pattern(name, function (str, pos) {
            var r, i;
            for (i = 0; i < patterns.length && !r; i++)
                r = patterns[i].exec(str, pos);
            return r;
        });
    }
1152885
async function walk(path, pattern, depth) {
  const files = await readdir(path);
  let fileList = [];

  for (const name of files) {
    const filePath = join(path, name);
    const fileStat = await stat(filePath);
    if (fileStat.isFile() && pattern.test(filePath)) {
      fileList.push(filePath);
    } else if ((depth > 1 || depth === 0) && fileStat.isDirectory()) {
      const list = await walk(filePath, pattern, depth && depth - 1);
      fileList = fileList.concat(list);
    }
  }

  return fileList;
}
1137999
function createRegExpForIgnorePatterns(normalizedOptions) {
    Object.keys(normalizedOptions).forEach(key => {
        const ignorePatternStr = normalizedOptions[key].ignorePattern;

        if (ignorePatternStr) {
            const regExp = RegExp(`^\\s*(?:${ignorePatternStr})`, "u");

            normalizedOptions[key].ignorePatternRegExp = regExp;
        }
    });
}
336636
private List<String> completionPattern(List<String> patterns) {
        List<String> result = new ArrayList<String>();
        for (String pattern : patterns) {
            StringBuffer stringBuffer = new StringBuffer();
            stringBuffer.append("^");
            stringBuffer.append(pattern);
            stringBuffer.append("$");
            result.add(stringBuffer.toString());
        }
        return result;
    }
952008
def findPatternsInFile(codes, patternFinder):
    
    tree = ast.parse(codes)
    patternFinder.visit(tree)
1100626
def ignore_patterns(*patterns):
    """"""
    import fnmatch
    def _ignore_patterns(path, names):
        ignored_names = []
        for pattern in patterns:
            ignored_names.extend(fnmatch.filter(names, pattern))
        return set(ignored_names)
    return _ignore_patterns
215844
public void applyPatterns(String[] patterns)
   {
      m_formats = new SimpleDateFormat[patterns.length];
      for (int index = 0; index < patterns.length; index++)
      {
         m_formats[index] = new SimpleDateFormat(patterns[index]);
      }
   }
313920
function getSourceFilesFromGlob(globPattern, ignoreGlobs) {
    return new Promise((fulfil, reject) => {
        glob(globPattern, { ignore: ignoreGlobs }, (err, files) => {
            if (err) {
                reject(err);
            } else {
                fulfil(files);
            }
        });
    });
}
1342776
def globChildren(self, pattern):
        
        import glob
        path = self.path[-1] == '/' and self.path + pattern or slash.join([self.path, pattern])
        return map(self.clonePath, glob.glob(path))
703664
function filteredFiles(folder, pattern) {
  var files = [];
    
  if (fs.existsSync(folder)){
    fs.readdirSync(folder).forEach(function(file) {
      if (file.match(pattern) != null)
        files.push(file);
    });
  }
  return files;
}
1028727
function matchPatternOrExact(patternStrings, candidate) {
        var patterns = [];
        for (var _i = 0, patternStrings_1 = patternStrings; _i < patternStrings_1.length; _i++) {
            var patternString = patternStrings_1[_i];
            var pattern = tryParsePattern(patternString);
            if (pattern) {
                patterns.push(pattern);
            }
            else if (patternString === candidate) {
                // pattern was matched as is - no need to search further
                return patternString;
            }
        }
        return findBestPatternMatch(patterns, function (_) { return _; }, candidate);
    }