Commit Graph

19978 Commits

Author SHA1 Message Date
Boris Feld
2c9df67473 configitems: register the 'hostsecurity.*:fingerprints' config 2017-10-14 00:29:31 +02:00
Boris Feld
3411c59c2f configitems: register the 'hostsecurity.*:ciphers' config 2017-10-14 00:28:48 +02:00
Boris Feld
a087914d79 configitems: register the 'hostsecurity.*:minimumprotocol' config 2017-10-14 00:28:13 +02:00
Boris Feld
c8ced9d060 configitems: register the 'extdata' section 2017-10-13 23:23:48 +02:00
Boris Feld
967247e8ec configitems: fix registration of extensions config
The new 'itemregister' class should be used when loading the extension config.
This was and oversight when itemregister was introduced.
2017-10-13 23:33:31 +02:00
Boris Feld
4c94a47479 configitems: register the 'web.staticurl' config 2017-10-13 23:03:46 +02:00
Boris Feld
14093a3043 configitems: register the 'hgweb-paths' section 2017-10-12 00:44:45 +02:00
Boris Feld
eeada116f6 configitems: register the 'hostfingerprints' section 2017-10-12 00:20:41 +02:00
Boris Feld
a345bd5d76 configitems: register the 'hostsecurity.minimumprotocol' config 2017-10-12 00:19:12 +02:00
Boris Feld
cb6b7ec15b configitems: register the 'progress.format' config 2017-10-11 22:53:17 +02:00
Augie Fackler
27aba6c982 hgweb: fix decodevaluefromheaders to always return a bytes value
That's more in line with what we want, and we know it's ASCII data
since that's all HTTP technically allows in headers anyway.

Differential Revision: https://phab.mercurial-scm.org/D1112
2017-10-15 00:43:01 -04:00
Augie Fackler
386ad003ae hgweb: more "headers are native strs" cleanup
I'll fix the decodevaluefromheaders function in an upcoming change.

Differential Revision: https://phab.mercurial-scm.org/D1111
2017-10-15 00:42:25 -04:00
Augie Fackler
db6ecaafd2 hgweb: when unpacking args from request form, convert to bytes
We assume http-originated values are ASCII, which should be safe based
on the RFC.

Differential Revision: https://phab.mercurial-scm.org/D1110
2017-10-15 00:41:34 -04:00
Augie Fackler
4b3002a912 wireproto: more strkwargs cleanup
Differential Revision: https://phab.mercurial-scm.org/D1109
2017-10-15 00:39:53 -04:00
Augie Fackler
22c84078c4 hgweb: more "http headers are native strs" cleanup
Differential Revision: https://phab.mercurial-scm.org/D1108
2017-10-15 00:38:33 -04:00
Augie Fackler
4fa42c83ce wireproto: bounce kwargs to/from bytes/str as needed
Differential Revision: https://phab.mercurial-scm.org/D1107
2017-10-15 00:05:43 -04:00
Boris Feld
5068121d4c configitems: fixup default value of annotate config option
It turned out that configbool is used for most of them so the registered
default value was wrong.
2017-10-16 15:12:50 +02:00
Denis Laxalde
ff300063f3 transaction-summary: use a revset to filter obsoletes in reportnewcs()
Thanks to Yuya Nishihara for suggesting.
2017-10-16 15:35:08 +02:00
Boris Feld
834dcb3800 configitems: fixup default value of diff config option
It turned out that configbool is used for most of them so the registered
default value was wrong.
2017-10-13 22:08:55 +02:00
Boris Feld
2253c06027 devel-warn: add 'warn-' to 'devel.empty-changegroup' config
Rename 'devel.empty-changegroup' to 'devel.warn-empty- changegroup' in order
to clarify it controls a warning message.

No alias is installed since the previous configuration option was not
documented.
2017-10-08 21:42:32 +02:00
Augie Fackler
25449b9adb peer: ensure command names are always ascii bytestrs
Differential Revision: https://phab.mercurial-scm.org/D1104
2017-10-15 00:05:00 -04:00
Augie Fackler
aff2a14d65 httppeer: always produce native str header keys and values
Differential Revision: https://phab.mercurial-scm.org/D1103
2017-10-15 00:03:31 -04:00
Augie Fackler
f4a2677719 wireproto: use %d to encode int, not %s
Differential Revision: https://phab.mercurial-scm.org/D1102
2017-10-15 00:40:07 -04:00
Augie Fackler
29944e3fdf wireproto: use a proper exception instead of assert False
Differential Revision: https://phab.mercurial-scm.org/D1101
2017-10-15 00:06:06 -04:00
Augie Fackler
7914273147 wireproto: use listcomp instead of map()
The latter returns a generator object on Python 3, which breaks
various parts of hg that expected a list.

Differential Revision: https://phab.mercurial-scm.org/D1100
2017-10-15 00:39:29 -04:00
Augie Fackler
e90604cb5e dagutil: use a listcomp instead of a map()
In Python 3, the map() returns a generator object instead of a list,
and some parts of hg depend on this being consumable more than once or
sortable in place.

Differential Revision: https://phab.mercurial-scm.org/D1099
2017-10-15 00:37:24 -04:00
Augie Fackler
510310c11a peer: when collecting method names for batch calls, bytes-ify __name__
This will explode violently if we have a non-ascii command name. That
shouldn't ever happen in core, and seems unlikely even in third-party
code. Regardless, it'll explode violently, so we can revisit things in
the future if we need to change the encoding here.

Differential Revision: https://phab.mercurial-scm.org/D1092
2017-10-14 12:03:42 -04:00
Augie Fackler
6509db2306 python3: replace im_{self,func} with __{self,func}__ globally
These new names are portable back to Python 2.6.

Differential Revision: https://phab.mercurial-scm.org/D1091
2017-10-14 12:02:15 -04:00
Augie Fackler
e5d72894dc httppeer: extract content-type from headers using native str
Differential Revision: https://phab.mercurial-scm.org/D1090
2017-10-14 12:00:35 -04:00
Augie Fackler
74dcc6aa29 httppeer: convert request url back to bytes before inspecting it
Differential Revision: https://phab.mercurial-scm.org/D1089
2017-10-14 11:59:51 -04:00
Augie Fackler
ffc31606d6 templater: explode if we try to emit a str
Without this if branch, we infinitely recurse in _flatten, which is
very confusing. Something in an hgweb template is trying to write out
a string instead of a bytes on Python 3, and this at least makes it
crash politely.

Differential Revision: https://phab.mercurial-scm.org/D1088
2017-10-14 11:30:17 -04:00
Augie Fackler
1eb0868158 hgweb: fill in content-type and content-length as native strings
This lets me actually get a capabilities response from hgweb over
http.

Differential Revision: https://phab.mercurial-scm.org/D1087
2017-10-14 11:20:31 -04:00
Augie Fackler
d3a0083e45 hgweb: mimetype guessing needs a unicode path
Differential Revision: https://phab.mercurial-scm.org/D1086
2017-10-14 10:47:29 -04:00
Augie Fackler
dfaf4b98bc hgweb: set sent_headers attr as early as practical
While doing Python 3 porting work, I've seen exceptions happen in
parts of hgweb we normally assume are robust. It won't hurt anything
to set this attribute significantly earlier, so let's do so and save
confusing during the porting process.

Differential Revision: https://phab.mercurial-scm.org/D1085
2017-10-14 15:37:33 -04:00
Augie Fackler
caec472139 hgweb: detect Python 3-era libraries and use modern attribute names
Differential Revision: https://phab.mercurial-scm.org/D1084
2017-10-05 14:53:52 -04:00
Augie Fackler
1f7e395752 server: indent block that's about to get conditionalized
Differential Revision: https://phab.mercurial-scm.org/D1083
2017-10-14 15:53:36 -04:00
Yuya Nishihara
62122f42ea templates: fix missed space between instability labels 2017-10-14 18:41:20 +09:00
Yuya Nishihara
0e862d288f templates: introduce labelcset() function in map-cmdline.default as example 2017-10-14 18:24:01 +09:00
Yuya Nishihara
550442a9eb templater: load aliases from [templatealias] section in map file
This seems sometimes useful as an alias can be a function, but a template
fragment can't.
2017-10-14 18:06:42 +09:00
Yuya Nishihara
994c332a3b templater: load template fragments from [templates] section in map file
This allows us to %include map-cmdline.<style> file in our .hgrc files. The
syntax is slightly different as hgrc doesn't support loading an external
template file, but map-cmdline files don't use this feature, so the syntax
can be considered identical in practice.

Unnamed section is remapped for backward compatibility.
2017-10-14 17:51:01 +09:00
Yuya Nishihara
615ab8c775 config: allow remapping the default section
The next patch depends on it. It doesn't make sense that the default section
can't be remapped with {'': whatever}.
2017-10-14 17:41:41 +09:00
Yuya Nishihara
e2e58c1839 templater: simplify merge of __base__ dicts by reading it first 2016-08-20 18:33:02 +09:00
Boris Feld
3905794a8c phase: add a dedicated pretxnclose-phase hook
This new hook mirror the newly introduced 'txnclose-phase' but can abort the
transaction.
2017-10-08 17:23:18 +02:00
Boris Feld
5dfba786e8 phase: add a dedicated txnclose-phase hook
The new 'txnclose-phase' hook expose the phase movement information stored in
'tr.changes['phases]'. To provide a simple and straightforward hook API to the
users, we introduce a new hook called for each revision affected.  Since a
transaction can affect the phase of multiple changesets, updating the existing
'txnclose' hook to expose that information would be more complex. The data for
all moves will not fit in environment variables and iterations over each move
would be cumbersome. So the introduction of a new dedicated hook is
preferred in this changesets.

This does not exclude the addition of the full phase movement information to
the existing 'txnclose' in the future to help write more complex hooks.
2017-10-08 17:50:46 +02:00
Boris Feld
db2e8fadae bookmark: add a dedicated pretxnclose-bookmark hook
This new hook mirror the newly introduced 'txnclose-bookmark' but can abort the
transaction.
2017-10-08 18:50:14 +02:00
Boris Feld
4815e3ce8d bookmark: add a dedicated txnclose-bookmark hook
The new 'txnclose-bookmark' hook expose the bookmark movement information
stored in 'tr.changes['bookmarks]'. To provide a simple and straightforward
hook API to the users, we introduce a new hook called for each bookmark
touched. Since a transaction can affect multiple bookmarks, updating the
existing 'txnclose' hook to expose that information would be more complex. The
data for all moves might not fit in environment variables and iterations over
each move would be cumbersome. So the introduction of a new dedicated hook is
preferred in this changeset.

This does not exclude the addition to the full bookmark information to the
existing 'txnclose' in the future to help write more complex hooks.
2017-10-10 17:53:42 +02:00
Augie Fackler
83f88ecb85 tweakdefaults: make commands.update.check be noconflict
This is the second-safest option we have to offer in `updatecheck`,
with `abort` being the safest and `linear` being the default. At the
sprint we discussed how much `none` and `linear` make us all
uncomfortable, and how we'd like to move the default behavior if we can.

I'm not sure we can get away with actually changing the out of the box
default behavior, but we can at *least* do this.

Differential Revision: https://phab.mercurial-scm.org/D1062
2017-10-13 15:58:54 -04:00
Augie Fackler
bc69639184 hgweb: fix logging to use native strings as appropriate
Kind of a tangled mess, but now logging works in both Python 2 and 3.

# no-check-commit because of the interface required by Python's HTTP
server code.

Differential Revision: https://phab.mercurial-scm.org/D1080
2017-10-14 15:43:06 -04:00
Augie Fackler
2fea5f41d1 config: graduate experimental.updatecheck to commands.update.check
.. feature::

  New `commands.update.check` feature to adjust constraints on when
  `hg update` will allow updates with a dirty working copy.

also

.. bc::

    The `experimental.updatecheck` name for the new `commands.update.check`
    feature is now deprecated, and will be removed after this release.

Differential Revision: https://phab.mercurial-scm.org/D1070
2017-10-14 03:13:50 -04:00
Augie Fackler
3327fe780e hgweb: rewrite most obviously-native-strings to be native strings
This clearly won't be everything, but it unblocks a fair amount of
stuff here.

Differential Revision: https://phab.mercurial-scm.org/D1079
2017-10-14 15:42:38 -04:00
Augie Fackler
9f097cd648 hgweb: use native strings consistently for querystring parsing
Differential Revision: https://phab.mercurial-scm.org/D1078
2017-10-05 14:48:52 -04:00
Augie Fackler
4fec03fc61 hgweb: rewrite two X or Y and Z ad-hoc ternaries with Y if X else Z
Just easier to muddle through for my brain now that I don't see the
old pattern much anymore.

Differential Revision: https://phab.mercurial-scm.org/D1077
2017-10-05 14:48:31 -04:00
Augie Fackler
14c0f38685 httppeer: use native strings for headers
On Python 3, we need to use unicodes, rather than bytes. This lets
test-pull.t get a lot further along.

Differential Revision: https://phab.mercurial-scm.org/D887
2017-10-01 12:12:34 -04:00
Augie Fackler
58adac28f6 hgweb: more native string treatment in query string parsing
Differential Revision: https://phab.mercurial-scm.org/D1076
2017-10-05 14:29:51 -04:00
Augie Fackler
97ea947740 httppeer: pass url to urllib as native str, not bytes
Differential Revision: https://phab.mercurial-scm.org/D1075
2017-10-14 14:07:39 -04:00
Denis Laxalde
6c2c086e11 tersestatus: rework dirnode and tersedir docstrings
Follow-up on refactorings 6a96abee0045 and b8c13fc92233 of the original
changeset 8c58ee1e5fa4 by updating the docstrings of dirnode class and tersedir
function:

* rewrite dirnode.iterfilepaths()'s docstring (the method got
  renamed and reimplemented in b8c13fc92233);
* simplify and update dirnode.tersewalk() to remove reference to 'self' and
  'tersedict';
* use the imperative form of verbs in the first sentence of all docstrings.

Differential Revision: https://phab.mercurial-scm.org/D1072
2017-10-14 13:33:37 +02:00
Augie Fackler
714a44cc5e bitmanipulation: reformat with clang-format
Mostly un-wrapping over-wrapped definitions.

Differential Revision: https://phab.mercurial-scm.org/D1069
2017-10-04 10:52:50 -04:00
Augie Fackler
a67386352a python3: use our bytes-only version of cgi.escape everywhere
As suggested by Yuya in D965.

Differential Revision: https://phab.mercurial-scm.org/D1067
2017-10-05 14:16:20 -04:00
Augie Fackler
5167a44c70 url: add cgi.escape equivalent for bytestrings
This seems like a sensible enough place to put it.

Differential Revision: https://phab.mercurial-scm.org/D1066
2017-10-14 02:57:26 -04:00
Augie Fackler
a4bc1fe43c python3: move from using func_name to __name__
Previously reviewed as D964, but required some fixups and therefore
seems to need a new revision.

Differential Revision: https://phab.mercurial-scm.org/D1065
2017-10-05 14:15:05 -04:00
Boris Feld
00846dabc6 hook: add a 'hashook' function to test for hook existence
Preparing the data for some hooks can be expensive. Add a function to check if
a hook exists so we can skip useless preparation if no hook is configured.
2017-10-08 13:08:31 +02:00
Phil Cohen
0d0a416a27 context: add a fast-comparision for arbitraryfilectx and workingfilectx
Differential Revision: https://phab.mercurial-scm.org/D1056
2017-10-13 12:40:05 -07:00
Denis Laxalde
6ff583b949 tersestatus: avoid modifying tersedict
Turn dirnode's methods into generators which can be used to update "tersedict"
in caller. So instead of passing the "tersedict" to be mutated here and there,
it's now clearer where it is updated as it's purely a local variable to
tersedir() function.

While I was here, I renamed _processtersestatus to tersewalk and
_addfilestotersed to iterfilepaths.

Differential Revision: https://phab.mercurial-scm.org/D1043
2017-10-13 04:02:06 +05:30
Denis Laxalde
e623051ee4 tersestatus: make methods part of the dirnode class
Differential Revision: https://phab.mercurial-scm.org/D1042
2017-10-11 21:19:19 +02:00
Pulkit Goyal
4b9eb4d057 tersestatus: re-implement the functionality to terse the status
The previous terse status implementation was hacking around os.listdir() and was
flaky. There have been a lot of instances of mercurial buildbots failing
and google's internal builds failing because of the
hacky implementation of terse status. Even though I wrote the last
implementation but it was hard for me to find the reason for the flake.

The new implementation can be slower than the old one but is clean and easy to
understand.

In this we create a node object for each directory and create a tree
like structure starting from the root of the working copy. While building the
tree like structure we store some information on the nodes which will be helpful
for deciding later whether we can terse the dir or not.
Once the whole tree is build we traverse and built the list of files for each
status with required tersing.

There is no behaviour change as the old test, test-status-terse.t passes with
the new implementation.

Differential Revision: https://phab.mercurial-scm.org/D985
2017-10-06 20:54:23 +05:30
Phil Cohen
b6042b5881 context: add is isinmemory() to filectx
This will make it easier to skip certain behavior when running an in-memory
merge.

Differential Revision: https://phab.mercurial-scm.org/D1061
2017-10-13 12:54:46 -07:00
Ryan McElroy
25aff2d866 merge: ensure that we always commit the mergestate
In future patches, we may halt the merge process based on configuration or
user requests by raising exceptions. We need to ensure that the mergestate
is unconditionally committed even when such an exception is raised.

Depends on D930.

Differential Revision: https://phab.mercurial-scm.org/D931
2017-10-06 06:48:43 -07:00
Durham Goode
1d4b04170c dirstate: move the _dirfoldmap to dirstatemap
Now that dirstatemap is the source of truth for the list of directories, let's
move _dirfoldmap on to it.

This pattern of moving cached variables onto the dirstate map makes it easier to
invalidate them, as seen by how the cache invalidation functions are slowly
shrinking to just be recreating the dirstatemap instance.

Differential Revision: https://phab.mercurial-scm.org/D983
2017-10-05 11:34:41 -07:00
Durham Goode
e37fd6649b dirstate: remove _dirs property cache
Now that dirs is source of truthed on the dirstatemap, let's get rid of the
_dirs propertycache on the dirstate.

Differential Revision: https://phab.mercurial-scm.org/D982
2017-10-05 11:34:41 -07:00
Durham Goode
1b9b3caa47 dirstate: remove _filefoldmap property cache
Now that the filefoldmap is source of truthed on the dirstatemap, let's get rid
of the property cache on the dirstate.

Differential Revision: https://phab.mercurial-scm.org/D981
2017-10-05 11:34:41 -07:00
Durham Goode
28f48a6846 dirstate: move identity to dirstatemap
Moving the identity function to the dirstatemap class will allow alternative
dirstate implementations to replace the implementation.

Differential Revision: https://phab.mercurial-scm.org/D980
2017-10-05 11:34:41 -07:00
Durham Goode
f97f617524 dirstate: move nonnormal and otherparent sets to dirstatemap
As part of separating dirstate business logic from storage, let's move the
nonnormal and otherparent storage to the dirstatemap class. This will allow
alternative dirstate storage to persist these sets instead of recomputing them.

Differential Revision: https://phab.mercurial-scm.org/D979
2017-10-05 11:34:41 -07:00
Durham Goode
99779c0bbb dirstate: move write into dirstatemap
As part of separating the dirstate business logic from the dirstate storage
logic, let's move the serialization code down into dirstatemap.

Differential Revision: https://phab.mercurial-scm.org/D978
2017-10-05 11:34:41 -07:00
Durham Goode
76bcc9b3be dirstate: move _read into dirstatemap
As part of separating the dirstate business logic from the storage, let's move
the read code into the new dirstatemap class.

Differential Revision: https://phab.mercurial-scm.org/D977
2017-10-05 11:34:41 -07:00
Boris Feld
7fa654bef2 configitems: register the 'templates' section 2017-10-08 21:29:24 +02:00
Boris Feld
1dca7c7296 configitems: register the 'paths' config section 2017-10-11 05:01:55 +02:00
Boris Feld
2ea04ee5d5 configitems: register the 'pager.attend-.*' options 2017-10-11 02:26:09 +02:00
Boris Feld
9296910ea4 configitems: register the 'hooks' config section 2017-10-13 16:39:06 +02:00
Boris Feld
0748d57ee7 configitems: register the 'extensions' section 2017-10-10 10:48:47 +02:00
Boris Feld
90436ba7a8 configitems: register the 'defaults' section 2017-10-08 20:39:51 +02:00
Boris Feld
04cc694185 configitems: register the 'committemplate' section 2017-10-08 21:02:02 +02:00
Boris Feld
abe633ebaf configitems: register the 'color' section 2017-10-10 10:49:28 +02:00
Boris Feld
101b5cf034 configitems: register the 'alias' section 2017-10-08 20:26:25 +02:00
Boris Feld
f9a854f7cf configitems: allow for the registration of "generic" config item
Some section can contains arbitrary keys (eg: color, alias, extensions). We
add a way to register some generic config items for them. This is necessary to
get all the config registered. We use a regular expression because some sub-
attributes (eg: hooks.xxx.priority) can define default value on their own.
2017-10-10 10:49:15 +02:00
Denis Laxalde
9efc7f05e3 transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Upon pull or unbundle, we display a message with the range of new revisions
fetched. This revision range could readily be used after a pull to look out
what's new with 'hg log'. The algorithm takes care of filtering "obsolete"
revisions that might be present in transaction's "changes" but should not be
displayed to the end user.
2017-10-12 09:39:50 +02:00
Yuya Nishihara
1b540c162d i18n: cache translated messages per encoding
This is a simpler workaround alternative to D958, "i18n: clean msgcache when
encoding changes." The cache won't be bloated unless you run tons of commands
with different --encoding options on command server, or serve many repositories
of different web.encoding options on hgweb.

The test was originally written by Jun Wu.

Differential Revision: https://phab.mercurial-scm.org/D1053
2017-10-13 21:36:10 +09:00
Yuya Nishihara
239bc0e96c templater: fix ifcontains() to handle type mismatch gracefully
This was unintentionally changed in b8023e389b64. Since ifcontains() takes
needle of any types, it shouldn't abort depending on the given container type.
2017-10-12 22:09:11 +09:00
Yuya Nishihara
11659330ed help: use single quotes in `template example`
It was hard to read because ``""`` was rendered as """".
2017-10-12 21:56:13 +09:00
Yuya Nishihara
b3bcc5233c help: hide template keywords of obsolescence as they are still experimental 2017-10-12 21:48:02 +09:00
Yuya Nishihara
c9014c6361 help: fix formatting of template keywords
Our minirst formatter can't render multi-paragraph definition lists well.
Also added periods where appropriate.
2017-10-12 21:42:42 +09:00
Yuya Nishihara
a312ee40fa configitems: drop redundant default of web.allow<archtype>
Otherwise develwarn would be sent to stderr. I've added blackbox logging
to capture warnings.
2017-10-13 00:22:54 +09:00
Yuya Nishihara
607219189c configitems: correct default values of web.allow<archtype> and web.hidden
The default of ui.configbool() is False unless explicitly specified.
2017-10-13 00:14:28 +09:00
Yuya Nishihara
1f85a4e152 bdiff: include compat.h in header to define ssize_t
Before cb121eb76276, compat.h was included first so it happened to work.
But we shouldn't rely on the include order.
2017-10-13 22:38:24 +09:00
Pulkit Goyal
9492c3a9ec repoview: remove incorrect documentation of the function
In repoview.py, computeunserved() and computemutable() functions had the same
documentation. The documentation of computemutable() is wrong. I was unable to
write documentation for the function but it's better to not having the
documentation than having it wrong.

Differential Revision: https://phab.mercurial-scm.org/D1016
2017-10-10 23:19:35 +05:30
Jun Wu
79d026fdfe codemod: use pycompat.isdarwin
This is done by:

  sed -i "s/pycompat\.sysplatform == 'darwin'/pycompat.isdarwin/" **/*.py

Plus a manual change to `sslutil.py` which involves indentation change that
cannot be done by `sed`.

Differential Revision: https://phab.mercurial-scm.org/D1035
2017-10-12 23:34:34 -07:00
Jun Wu
72d17900ca codemod: use pycompat.isposix
This is done by:

  sed -i "s/pycompat\.osname == 'posix'/pycompat.isposix/" **/*.py

Differential Revision: https://phab.mercurial-scm.org/D1036
2017-10-12 09:04:22 -07:00
Jun Wu
2ae56b14de codemod: use pycompat.iswindows
This is done by:

  sed -i "s/pycompat\.osname == 'nt'/pycompat.iswindows/" **/*.py
  sed -i "s/pycompat\.osname != 'nt'/not pycompat.iswindows/" **/*.py
  sed -i 's/pycompat.osname == "nt"/pycompat.iswindows/' **/*.py

Differential Revision: https://phab.mercurial-scm.org/D1034
2017-10-12 23:30:46 -07:00
Jun Wu
7b62930cd9 pycompat: define operating system constants
As suggested by Ryan in D1019, it's cleaner if we use defined constants
instead of `osname == 'nt'` everywhere.

Differential Revision: https://phab.mercurial-scm.org/D1033
2017-10-12 19:20:04 -07:00
Jun Wu
d91707e2a4 hgweb: do not import uuid immediately to avoid its side effect
With hgdemandimport disabled (chg's case), `import uuid` has an immediate
side effect calling `ctypes.util.find_library` trying to locate the
`libuuid` library.  This happens at `import` time before `dispatch.run()`.
The call trace is like:

  File "hg/hg", line 54, in <module>
    from mercurial import (
  File "hg/mercurial/dispatch.py", line 24, in <module>
    from . import (
  File "hg/mercurial/commands.py", line 23, in <module>
    from . import (
  File "hg/mercurial/help.py", line 33, in <module>
    from .hgweb import (
  File "hg/mercurial/hgweb/__init__.py", line 20, in <module>
    from . import (
  File "hg/mercurial/hgweb/hgweb_mod.py", line 14, in <module>
    from .common import (
  File "hg/mercurial/hgweb/common.py", line 15, in <module>
    import uuid
  File "/usr/lib64/python2.7/uuid.py", line 404, in <module>
    lib = ctypes.CDLL(ctypes.util.find_library(libname))

The problem is, `ctypes.util.find_library` will execute
`sh -c '/sbin/ldconfig -p 2>/dev/null'` on Python <= 2.7.12. The output of
`sh` may pollute the terminal:

  shell-init: error retrieving current directory: getcwd: cannot access
  parent directories: No such file or directory

This patch moves `import uuid` so its side-effect can only happen after the
cwd check in `dispatch._getlocal`. Therefore the terminal won't be
polluted by importing `uuid`.

Differential Revision: https://phab.mercurial-scm.org/D1024
2017-10-11 21:24:32 -07:00
Jun Wu
7f6381a6d9 selectors2: do not use platform.system()
`platform.system()` may have a side effect spawning a shell executing
`uname -p`, which may print a warning when the current directory is removed:

  shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory

This patch changes selectors2 to test the `sys.platform` string, which is a
much safer way to detect Jython.

Jython's `sys.platform` looks like this:

  Jython 2.7.1 (default:0df7adb1b397, Jun 30 2017, 19:02:43)
  [OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.8.0_144
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import sys
  >>> sys.platform
  'java1.8.0_144 ( ==linux2 for targets )'

Differential Revision: https://phab.mercurial-scm.org/D1018
2017-10-11 17:27:21 -07:00