Skip to content

Commit

Permalink
shelve: ignore ._ hidden files created by MacOS
Browse files Browse the repository at this point in the history
Summary: Currently, 'hg sl' template is calling 'shelved()' revset function to add '(shelved)' label, and it crashes if there are '._*' binary files created by MacOS. This diff ignores the '._*' files.

Reviewed By: quark-zju

Differential Revision: D42647182

fbshipit-source-id: 9ff8b67e85c55bf2ea24af774f1b638798e71f4c
  • Loading branch information
zzl0 authored and facebook-github-bot committed Jan 20, 2023
1 parent 3d04ffd commit cea7748
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
22 changes: 14 additions & 8 deletions eden/scm/edenscm/ext/shelve.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,16 +558,22 @@ def _iswctxonnewbranch(repo):
return repo[None].branch() != repo["."].branch()


def _listshelvefileinfos(repo, shelvedir):
"""Return a list of (filename, type) pair"""
# ignore the hidden attribute files created by MacOS,
# they will be deleted automatically when the main file
# is deleted. https://fburl.com/7hc21dkc
return [
fileinfo
for fileinfo in repo.localvfs.readdir(shelvedir)
if not fileinfo[0].startswith("._")
]


def cleanupcmd(ui, repo) -> None:
"""subcommand that deletes all shelves"""

with repo.wlock():
for (name, _type) in repo.localvfs.readdir(shelvedir):
# ignore the hidden attribute files created by MacOS,
# they will be deleted automatically when the main file
# is deleted. https://fburl.com/7hc21dkc
if name.startswith("._"):
continue
for (name, _type) in _listshelvefileinfos(repo, shelvedir):
suffix = name.rsplit(".", 1)[-1]
if suffix in shelvefileextensions:
shelvedfile(repo, name).movetobackup()
Expand Down Expand Up @@ -601,7 +607,7 @@ def deletecmd(ui, repo, pats) -> None:
def listshelves(repo):
"""return all shelves in repo as list of (time, filename)"""
try:
names = repo.localvfs.readdir(shelvedir)
names = _listshelvefileinfos(repo, shelvedir)
except OSError as err:
if err.errno != errno.ENOENT:
raise
Expand Down
4 changes: 2 additions & 2 deletions eden/scm/tests/test-shelve-hidden-file.t
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ Use wrong format ._* files to mimic the binary files created by MacOS:
$ echo 'wrong format' >> .hg/shelved/._default.oshelve
$ echo 'wrong format' >> .hg/shelved/._default.patch

$ hg log -r 'shelved()' 2>&1 | head -n 1
** * has crashed: (glob)
$ hg log -r 'shelved()' -T '{desc}'
shelve changes to: c (no-eol)

0 comments on commit cea7748

Please sign in to comment.