main: add mercurial.main as an entry point

Summary:
The old mercurial.dispatch entry point works, except it breaks
extensions wrapping `dispatch.*` (ex. `dispatch.runcommand`).

That is because things happen in this order:
- Buck's python wrapper imports `mercurial.dispatch` as mod1.
- hgdemandimport is enabled.
- An extension imports `mercurial.dispatch` and it got mod2.
- mod2 != mod1. So any changes to mod2 won't be used.

Using a separate module (`mercurial.main`) as the entry point
solves the problem.

Reviewed By: DurhamG

Differential Revision: D6879873

fbshipit-source-id: 9779edac64bbeb53dd98dfab1b21575c3a60af01
This commit is contained in:
Jun Wu 2018-02-02 12:18:00 -08:00 committed by Saurabh Singh
parent 5dabd90466
commit f623fe9d3c
2 changed files with 13 additions and 6 deletions

View File

@ -5,7 +5,7 @@
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import, print_function
from __future__ import absolute_import
import difflib
import errno
@ -1010,8 +1010,3 @@ def rejectpush(ui, **kwargs):
# mercurial hooks use unix process conventions for hook return values
# so a truthy return means failure
return True
if __name__ == '__main__':
import hgdemandimport
hgdemandimport.enable()
run()

12
mercurial/main.py Normal file
View File

@ -0,0 +1,12 @@
# Copyright 2018 Facebook, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import
if __name__ == '__main__':
import hgdemandimport
hgdemandimport.enable()
from . import dispatch
dispatch.run()