Commit Graph

31327 Commits

Author SHA1 Message Date
Gregory Szorc
48793a9cc5 bugzilla: use util.urlreq.urlparse
And stop saving a module variable because it shouldn't be
necessary.
2017-03-21 22:39:52 -07:00
Gregory Szorc
7046e7f549 pycompat: define urlreq.urlparse and urlreq.unparse aliases
Currently, we export urlparse via util.urlparse then
call util.urlparse.urlparse() and util.urlparse.urlunparse()
in a few places. This is the only url* module exported from
pycompat, making it a one-off. So let's transition to urlreq
to match everything else.

Yes, we double import "urlparse" now on Python 2. This will
be cleaned up in a subsequent patch.

Also, the Python 3 functions trade in str/unicode not bytes.
So we'll likely need to write a custom implementation that
speaks bytes. But moving everyone to an abstracted API
is a good first step.
2017-03-21 22:34:17 -07:00
Gregory Szorc
76701c9657 pycompat: remove urlunquote alias
It is duplicated by urlreq.unquote and is unused. Kill it.

We retain the imports because it is re-exported via util.urlparse,
which is used elsewhere.

Since we no longer access attributes of urlparse at module load time,
this change /should/ result in that module reverting to a lazy module.
2017-03-21 22:28:16 -07:00
Gregory Szorc
28ebe71a15 util: use urlreq.unquote
pycompat.urlreq.unquote and pycompat.urlunquote effectively alias the
same thing. pycompat.urlunquote is only used once in the code base.
So let's switch to urlreq.unquote.

"Effectively" in the above paragraph is because pycompat.urlreq.unquote
aliases urllib.unquote and pycompat.urlunquote aliases urlparse.unquote
on Python 2. You might think one of urllib.unquote and urlparse.unquote
is an alias to the other, but you would be incorrect. In fact, these
functions are copies of each other. There is even a comment in the
CPython source code saying to keep them in sync. You can't make this
up.
2017-03-21 22:23:11 -07:00
Gregory Szorc
a0383567c2 pycompat: alias urlreq.unquote to unquote_to_bytes
Previously, urlreq.unquote aliased to urllib.parse.unquote,
which returned a str/unicode. We like bytes, so switch urlreq.unquote
to dispatch to urllib.parse.unquote_to_bytes.

This required a minor helper function to register an alias under a
different name from which it points. If this turns into a common
pattern, we could likely teach _registeralias to accept tuple
values defining the mapping. Until then, I didn't feel like
adding complexity to _registeralias.
2017-03-21 22:20:11 -07:00
Augie Fackler
656aa696dc revsetlang: portably turn int into bytestring 2017-03-19 01:03:53 -04:00
Jun Wu
ef355a6e06 osutil: export a "getfstype" method
This patch exports the "getfstype" method. So we can use it to enable
hardlinks for known safe filesystems.

The patch was tested manually via debugshell on a Linux system.
"mercurial.osutil.getfstype" works as expected. It's hard to mount
filesystem on user-space easily. I will add a test for real hardlink support
to indirectly test this patch, after turning on real hardlinks support for
certain whitelisted filesystems.
2017-03-20 16:34:12 -07:00
Jun Wu
57405f31c1 osutil: add a C function getting filesystem type
Currently it only has Linux filesystems, according to my Linux manpage,
built at 2016-03-15.

The code uses "if" instead of "switch" because there could be some
duplicated values.
2017-03-20 16:24:59 -07:00
Jun Wu
f1184d5119 setup: test some header files
The next patch will use "statfs", which requires different header files on
different platforms.

Linux:

    sys/vfs.h or sys/statfs.h

FreeBSD or OSX:

    sys/param.h and sys/mount.h

Therefore test them so we can include the correct ones.
2017-03-20 15:43:27 -07:00
Jun Wu
416be40974 setup: detect statfs
statfs is not defined by POSIX but is available in various systems to help
decide filesystem type. Let's detect it and set the macro HAVE_STATFS.
2017-03-20 15:11:18 -07:00
Jun Wu
1aec4664c3 setup: add a function to test header files 2017-03-20 15:31:21 -07:00
Jun Wu
ca75eb2417 setup: split "hasfunction" to test arbitrary code
The next patch wants to test include files.
2017-03-20 15:28:08 -07:00
Ryan McElroy
8198e58557 rebase: add flag to require destination
In some mercurial workflows, the default destination for rebase does not
always work well and can lead to confusing behavior. With this flag enabled,
every rebase command will require passing an explicit destination, eliminating
this confusion.
2017-03-14 17:43:44 -07:00
Ryan McElroy
158bdd12b9 update: add flag to require update destination
In some mercurial workflows, the default destination for update does not
always work well and can lead to confusing behavior. With this flag enabled,
every update command will require passing an explicit destination, eliminating
this confusion.
2017-03-14 17:43:18 -07:00
Yuya Nishihara
5ede78a765 mq: reject new patch name containing leading/trailing whitespace
We could create a patch of such name, but it wouldn't be processed properly
by mq as parseseries() strips leading/trailing whitespace.

The test of default message (added by 063a2c623014) is no longer be useful
so removed.

This issue was reported as:
https://bitbucket.org/tortoisehg/thg/issues/4693/
2017-03-20 11:38:37 +09:00
Kostia Balytskyi
57c52e7771 shelve: rename stripnodes to nodestoprune
Since we are introducing obs-based shelve, we are no longer
stripping temporary nodes, we are obsoleting them. Therefore
it looks like stipnodes would be a misleading name, while
prune has a connotaion of "strip but with obsolescense", so
nodestoprune seems like a good rename.
2017-03-10 16:18:43 -08:00
Kostia Balytskyi
83f829a40a shelve: add an ability to write key-val data to a new type of shelve files
Obsolescense-based shelve only needs metadata stored in .hg/shelved
and if feels that this metadata should be stored in a
simplekeyvaluefile format for potential extensibility purposes.
I want to avoid storing it in an unstructured text file where
order of lines determines their semantical meanings (as now
happens in .hg/shelvedstate. .hg/rebasestate and I suspect other
state files as well).

Not included in this series, I have ~30 commits, doubling test-shelve.t
in size and testing almost every tested shelve usecase for obs-shelve.
Here's the series for the curious now: http://pastebin.com/tGJKx0vM
I would like to send it to the mailing list and get accepted as well,
but:
1. it's big, so should I send like 6 patches a time or so?
2. instead of having a commit per test case, it more like
   a commit per some amount of copy-pasted code. I tried to keep
   it meaningful and named commits somewhat properly, but it is
   far from this list standards IMO. Any advice on how to get it
   in without turning it into a 100 commits and spending many
   days writing descriptions?
3. it makes test-shelve.t run for twice as long (and it is already
   a slow test). Newest test-shelve.r runs for ~1 minute.
2017-03-10 15:03:09 -08:00
Kostia Balytskyi
0b0228842d scmutil: add a simple key-value file helper
The purpose of the added class is to serve purposes like save files of shelve
or state files of shelve, rebase and histedit. Keys of these files can be
alphanumeric and start with letters, while values must not contain newlines.

In light of Mercurial's reluctancy to use Python's json module, this tries
to provide a reasonable alternative for a non-nested named data.
Comparing to current approach of storing state in plain text files, where
semantic meaning of lines of text is only determined by their oreder,
simple key-value file allows for reordering lines and thus helps handle
optional values.

Initial use-case I see for this is obs-shelve's shelve files. Later we
can possibly migrate state files to this approach.

The test is in a new file beause I did not figure out where to put it
within existing test suite. If you give me a better idea, I will gladly
follow it.
2017-03-10 14:33:42 -08:00
Yuya Nishihara
fe309eba0e graphlog: draw multiple edges towards null node (issue5440)
Before, edge (r, null) was processed only once by newparents. However what
we really need is just stripping the edge (null, null).
2017-03-20 11:50:55 +09:00
Augie Fackler
b97ca52d90 merge with stable 2017-03-21 18:36:14 -04:00
Ryan McElroy
372012a68d localrepo: use tryunlink 2017-03-21 06:50:28 -07:00
Ryan McElroy
cb1115163c vfs: use tryunlink 2017-03-21 06:50:28 -07:00
Ryan McElroy
41cf85dae6 server: use tryunlink 2017-03-21 06:50:28 -07:00
Ryan McElroy
b1c2e24234 dirstate: use tryunlink 2017-03-21 06:50:28 -07:00
Ryan McElroy
0030afb0ce debug: use tryunlink 2017-03-21 06:50:28 -07:00
Ryan McElroy
d5ac75bcbf chgserver: use tryunlink 2017-03-21 06:50:28 -07:00
Ryan McElroy
d625f591ce bookmarks: use tryunlink 2017-03-21 06:50:28 -07:00
Ryan McElroy
37206f8f83 shelve: use tryunlink 2017-03-21 06:50:28 -07:00
Ryan McElroy
a75b679fd2 vfs: add tryunlink method
Thoughout hg code, we see a pattern of attempting to remove a file and then
catching and ignoring any errors due to a missing file in the calling code.
Let's unify this pattern in a single implementation in the vfs layer.
2017-03-21 06:50:28 -07:00
Ryan McElroy
ac0305dcbb util: use tryunlink in unlinkpath
We just introduced a func to attempt a file removal. Start using it.
2017-03-21 06:50:28 -07:00
Ryan McElroy
ff386f9a99 util: add tryunlink function
Throughout mercurial cdoe, there is a common pattern of attempting to remove
a file and ignoring ENOENT errors. Let's move this into a common function to
allow for cleaner code.
2017-03-21 06:50:28 -07:00
Ryan McElroy
4456f7562c util: unify unlinkpath
Previously, there were two slightly different versions of unlinkpath between
windows and posix, but these differences were eliminated in previous patches.
Now we can unify these two code paths inside of the util module.
2017-03-21 06:50:28 -07:00
Ryan McElroy
cf50c1b95b posix: use local reference to removedirs
We have a local reference to os.removedirs in module scope, but we still used
os.removedirs inside functions. This changes util to use the local reference,
which will pave the way for combining duplicated code in future patches.
2017-03-21 06:50:28 -07:00
Ryan McElroy
9eb9d0168b posix: use local reference to unlink
We have a local reference to os.unlink in module scope, but we still used
os.unlink inside functions. This changes util to use the local reference,
which will pave the way for combining duplicated code in future patches.
2017-03-21 06:50:28 -07:00
Ryan McElroy
2c2aec06d7 localrepo: improve vfs documentation
At the beginning of March, I promised Yuya that I would follow up a comment I
made on a patch with improved documention for these vfs objects. Also hat tip
to Pierre-Yves for adding the documentation here in the first place.
2017-03-21 06:50:42 -07:00
Simon Farnsworth
0057b864bd ui: restrict length of autogenerated blocked tags
Long autogenerated blocked tags tend to be because the command has an absolute
path; at Facebook, we've had a few where the tag is thousands of characters
long (in association with the mergedriver).

Change the default to use a suffix of a command as the default tag, limiting us
to 85 characters (for a 100 character tag). This is long enough to overflow a
standard terminal (thus be obviously autogenerated), but short enough to be
readable.
2017-03-20 05:08:21 -07:00
Simon Farnsworth
ddbe7287e7 subrepo: move prompts out of the if (issue5505)
Prompts weren't available in the else clause
2017-03-20 04:36:55 -07:00
Augie Fackler
471b2bd76a commit: keep opts as byteskwargs as much as possible
This fixes many flag-handling bugs on 'hg commit' in Python 3.
2017-03-19 01:20:08 -04:00
Augie Fackler
0598bcdf11 util: reference __main__ in sys.modules as a sysstr 2017-03-19 01:19:27 -04:00
Augie Fackler
e225c8919b ui: convert to/from Unicode on Python 3 in ui.editor()
I considered making this I/O be done in terms of bytes, but that would
cause an observable regression for Windows users, as non-binary-mode
open does EOL conversion there. There are probably new encoding
dragons lurking here, so we may want to switch to using binary mode
and doing EOL conversion ourselves.
2017-03-19 01:38:10 -04:00
Augie Fackler
7b7bdd3bf0 manifest: refer to bytestrings as bytes, not str
Required on Python 3.
2017-03-19 01:12:03 -04:00
Augie Fackler
4840b79ea6 manifest: use node.hex instead of .encode('hex')
The latter doesn't work on Python 3.
2017-03-19 01:11:37 -04:00
Martin von Zweigbergk
299fc67d57 pure: use int instead of long
Similar to the recent 09e07907253b (revlog: use int instead of long,
2017-03-19).
2017-03-20 21:40:28 -07:00
Gregory Szorc
aff9286eb0 exchange: use v2 bundles for modern compression engines (issue5506)
Previously, `hg bundle zstd` on a non-generaldelta repo would
attempt to use a v1 bundle. This would fail because zstd is not
supported on v1 bundles.

This patch changes the behavior to automatically use a v2 bundle
when the user explicitly requests a bundlespec that is a compression
engine not supported on v1. If the bundlespec is <engine>-v1, it is
still explicitly rejected because that request cannot be fulfilled.
2017-03-16 12:33:15 -07:00
Gregory Szorc
3bbb6e2c52 exchange: reject new compression engines for v1 bundles (issue5506)
Version 1 bundles only support a fixed set of compression engines.
Before this change, we would accept any compression engine for v1
bundles, even those that may not work on v1. This could lead to
an error.

We define a fixed set of compression engines known to work with v1
bundles and we add checking to ensure a newer engine (like zstd)
won't work with v1 bundles.

I also took the liberty of adding test coverage for unknown compression
names because I noticed we didn't have coverage of it before.
2017-03-16 12:23:56 -07:00
Jun Wu
43b73290d8 histedit: inline cleanupnode
Move "cleanupnode" (unsafe strip) into "safecleanupnode" so it's impossible
to call the unsafe function directly.

This helps reduce future programming errors.
2017-03-13 22:30:07 -07:00
Jun Wu
9a92b85a6b histedit: use safecleanupnode in _aborthistedit (issue5500)
Now nobody in histedit calls the unsafe cleanupnode directly.
2017-03-13 22:22:18 -07:00
Jun Wu
a31c040564 histedit: use safecleanupnode in _finishhistedit
This simplifies code a lot.
2017-03-13 22:19:06 -07:00
Jun Wu
6525da3ca6 histedit: add a method to cleanup nodes safely
The new method will decide between:

  - cleanupnode, which calls the unsafe repair.strip
  - create obsmarkers

Ideally, nobody calls "cleanupnode" directly except for "safecleanupnode".
2017-03-13 21:10:45 -07:00
Rishabh Madan
dad9bc22cf py3: prove hg status works 2017-03-21 07:22:13 +05:30