最快的方法是什么。

发布于 2025-01-19 08:04:07 字数 1398 浏览 4 评论 0 原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青巷忧颜 2025-01-26 08:04:07

正如您间接注意的那样,这些在语义上并不等同,因为如果/dir file ,它们的作用有所不同。但是,如果您以某种方式“知道” /dir 实际上 be 目录,/dir /dir/将是列出这些列表的“有效”方法,因为它们将省略打开和阅读目录。

/dir/是否有效或 /dir 取决于您的OS及其 readdir 实现:当git读取目录/(工作树的顶部)时,它获取名称组件。, .. < /code>, readme.txt (假设有这样的文件), abc (也许是文件,也许是目录,我们只是假设有一些名为<的东西代码> ABC ), dir (目录)等。 May 还获得有用的 d_type 字段: POSIX仅需要 d_name d_ino ,但是Linux和BSD具有 d_type 字段。操作系统将填充 d_type ,其中一个:

  • dt_unknown :我们没有告诉您任何东西
  • dt_dir :此实体用于目录
  • dt_reg :此实体适用于一个常规文件,
  • 此处未列出的各种其他可能性(另请参见 cache.h )。

如果可用,git将使用此值。如果 dt_dir ,git将知道 dir 是一个目录,并且不需要在确定/dir/实体是否匹配的路径。如果是 dt_unknown ,git将不知道哪种实体 dir 表示, will 需要调用 lstat 。但是,对于/dir 锚定的Gitignore条目,Git Care 哪种实体 dir 表示,因此绝对不需要呼叫 lstat 。但是,也许它不需要调用 lstat ,这样一无所获。

(应该/dir 名称a file ,并且您希望git存储该文件,或者在适当的情况下以无跟踪的方式投诉,您应该使用/dir /在这里,不必担心单个 lstat 系统调用的成本,即使它可以以数百微秒或低数量的毫秒而不是纳米秒为单位的微秒,甚至是毫秒 do 当然最终会加起来。)

As you note indirectly, these aren't semantically equivalent since they act differently if /dir is a file. However, if you somehow "know" that /dir will in fact be a directory, /dir and /dir/ would be the "efficient" ways to list these as they will omit opening-and-reading the directory.

Whether /dir/ is less efficient or just as efficient as /dir depends on your OS and its readdir implementation: when Git reads the directory / (the top of the working tree), it gets the name components ., .., README.txt (assuming there is such a file), abc (maybe a file, maybe a directory, we'll just assume there is something named abc), dir (a directory), and whatever else. It may also get a useful d_type field: POSIX only requires a d_name and d_ino, but Linux and the BSDs have a d_type field. The OS will fill in d_type with one of:

Git will use this value, if it's available. If it is DT_DIR, Git will know that dir is a directory and won't need to call lstat on the path when deciding whether the /dir/ entity matches. If it is DT_UNKNOWN, Git won't know what kind of entity dir represents and will need to call lstat. However, for the /dir anchored gitignore entry, Git doesn't care what kind of entity dir represents, so it definitely won't need to call lstat. But maybe it doesn't need to call lstat anyway, so that this gains nothing.

(Should /dir name a file and you want Git to store that file if it exists, or complain about it as untracked as appropriate, you should use /dir/ here and not worry about the cost of a single lstat system call, even though it may be measured in hundreds of microseconds, or even low-digit milliseconds, rather than nanoseconds. But milliseconds do add up eventually, of course.)

凡尘雨 2025-01-26 08:04:07

如果您想忽略文件夹,请使用:

/folderName =>忽略文件夹名称 ||根目录中的文件名

/folderName/ =>忽略根目录中的folderName

但是如果您folderName/ 忽略所有名为folderName 的文件夹。我猜这会花费更多时间,因为他从根目录向上递归遍历所有文件夹。

但在我看来这并不重要。 gitignore 对于程序来说并不重要,对程序的性能没有影响。

If you want ignore a folder use:

/folderName => ignore folderName || fileName from root directory

/folderName/ => ignore folderName from root directory

But if you folderName/ ignore all folders with the name folderName. I would guess that that tokes more time because he iterate recursive over all folders from root upwards.

but in my opinion it doesn't matter. gitignore is not important for the programme and has no influence on the performance of the programm.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文