diff --git a/mercurial/encoding.py b/mercurial/encoding.py --- a/mercurial/encoding.py +++ b/mercurial/encoding.py @@ -16,7 +16,9 @@ try: # On darwin, getpreferredencoding ignores the locale environment and # always returns mac-roman. We override this if the environment is # not C (has been customized by the user). - locale.setlocale(locale.LC_CTYPE, '') + lc = locale.setlocale(locale.LC_CTYPE, '') + if lc == 'UTF-8': + locale.setlocale(locale.LC_CTYPE, 'en_US.UTF-8') encoding = locale.getlocale()[1] if not encoding: encoding = locale.getpreferredencoding() or 'ascii' diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -63,6 +63,10 @@ def extract(ui, fileobj): subject = msg['Subject'] user = msg['From'] + if not subject and not user: + # Not an email, restore parsed headers if any + subject = '\n'.join(': '.join(h) for h in msg.items()) + '\n' + gitsendmail = 'git-send-email' in msg.get('X-Mailer', '') # should try to parse msg['Date'] date = None diff --git a/mercurial/windows.py b/mercurial/windows.py --- a/mercurial/windows.py +++ b/mercurial/windows.py @@ -267,7 +267,7 @@ def _removedirs(name): head, tail = os.path.split(head) while head and tail: try: - if osutil.listdir(name): + if osutil.listdir(head): return os.rmdir(head) except: diff --git a/tests/test-import b/tests/test-import --- a/tests/test-import +++ b/tests/test-import @@ -345,3 +345,23 @@ hg init oddcreate cd oddcreate hg import --no-commit ../create.patch cat foo + +echo % 'first line mistaken for email headers (issue 1859)' +hg init emailconfusion +cd emailconfusion +cat > a.patch < issue1861/x +echo y > issue1861/b/c/y +hg ci -Am add +hg rm issue1861/b +hg ci -m remove +ls issue1861 diff --git a/tests/test-remove.out b/tests/test-remove.out --- a/tests/test-remove.out +++ b/tests/test-remove.out @@ -111,3 +111,8 @@ R test/foo ./foo ./test/foo 2 files updated, 0 files merged, 0 files removed, 0 files unresolved +test remove dropping empty trees (issue1861) +adding issue1861/b/c/y +adding issue1861/x +removing issue1861/b/c/y +x