Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • mercurial/mercurial-devel
1 result
Show changes
Commits on Source (7)
  • Matt Harbison's avatar
    test-fix-path: avoid a test hang on Windows · 3fb2fbad4b13
    Matt Harbison authored
    Windows can't typically invoke `*.py` directly as a command, and will instead
    show a prompt asking what program should be used to open the file.  We can't
    directly invoke the interpreter as is usually done in this case, because the
    whole point is to run something not in `PATH`.  The easiest thing to do is
    invoke a *.bat file that runs the interpreter.  We can get away with this
    because the current implementation is to effectively run `cmd.exe /c %command%`,
    which doesn't need the file extension specified.
    3fb2fbad4b13
  • Pierre-Yves David's avatar
    cleanup: remove the `contrib/hgperf` script · b624da86830e
    Pierre-Yves David authored
    This script seems a copy `./hg` with a few adjustment. However it does not seems
    to have been used in age given that is still use old API and package name that
    has not been around for a long while.
    
    So let's just delete it.
    b624da86830e
  • Pierre-Yves David's avatar
    cleanup: drop the LIBDIR related code · 33e06272ff1a
    Pierre-Yves David authored
    This code is no longer used as the python packaging echo system evolved.
    
    This code was introduced in 10da5a1f25dd, with two feature in mind:
    
    - Mercurial may be installed into a non-standard location without
      having to set PYTHONPATH.
    - Multiple installations can use Mercurial from different locations.
    
    As a side effect it also provided performance improvement at a time where the
    `sys.path` could be greatly inflated from setuptools `.pth` files. And it also
    protected from incompatible directory within the `$PTYHONPATH` variable. Both of
    these benefit has faded overtime as `.pth` are less common and `$PYTHONPATH` is
    less used (as both where creating issue to more than just Mercurial).
    
    The initial motivation (easily install Mercurial anywhere), can now be handled
    by a new generation of tool like pipx or uv, so it is less of a concern.
    
    Regardless of all the above, the current code is no longer used. The evolution
    of python packaging means that installation always go through first building a
    location agnostic "wheel" that cannot update LIBDIR to a proper location.
    Upstream packaging (debian, redhat, etc…) does not seems to adjust this variable
    themself. So it is safer to drop this dead code that pretend we could be doing
    something with it.
    33e06272ff1a
  • Raphaël Gomès's avatar
    rust-nodemap: don't compute the error string unless needed · 155e1e8dc055
    Raphaël Gomès authored
    This is... really dumb and costs a ton of performance in a hot loop. It was
    75% of a profile for a tip to null p1 node traversal in pure Rust.
    
    I'm at fault, done in 652149ed64f0.
    
    I thought clippy had a lint for this, but apparently not?
    155e1e8dc055
  • Raphaël Gomès's avatar
    rust-index: don't compute error messages unless needed · 3fae90405966
    Raphaël Gomès authored
    Same as the previous patch, this is just dumb performance loss.
    3fae90405966
  • Mitchell Kember's avatar
    rust: enable workspace lints · 1ef08a0381a0
    Mitchell Kember authored
    This means that lints configured in rust/Cargo.toml will apply to all crates
    within the workspace. Currently there are none but I plan to add some.
    1ef08a0381a0
  • Mitchell Kember's avatar
    rust: enable clippy::or_fun_call lint · c4392e8bfb9f
    Mitchell Kember authored
    I confirmed that this would have prevented the issue in !1280.
    
    For details see:
    https://rust-lang.github.io/rust-clippy/master/index.html#/or_fun_call
    c4392e8bfb9f
#!/usr/bin/env python3
#
# hgperf - measure performance of Mercurial commands
#
# Copyright 2014 Olivia Mackall <olivia@selenic.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
'''measure performance of Mercurial commands
Using ``hgperf`` instead of ``hg`` measures performance of the target
Mercurial command. For example, the execution below measures
performance of :hg:`heads --topo`::
$ hgperf heads --topo
All command output via ``ui`` is suppressed, and just measurement
result is displayed: see also "perf" extension in "contrib".
Costs of processing before dispatching to the command function like
below are not measured::
- parsing command line (e.g. option validity check)
- reading configuration files in
But ``pre-`` and ``post-`` hook invocation for the target command is
measured, even though these are invoked before or after dispatching to
the command function, because these may be required to repeat
execution of the target command correctly.
'''
import os
import sys
libdir = '@LIBDIR@'
if libdir != '@' 'LIBDIR' '@':
if not os.path.isabs(libdir):
libdir = os.path.join(
os.path.dirname(os.path.realpath(__file__)), libdir
)
libdir = os.path.abspath(libdir)
sys.path.insert(0, libdir)
# enable importing on demand to reduce startup time
try:
from mercurial import demandimport
demandimport.enable()
except ImportError:
import sys
sys.stderr.write(
"abort: couldn't find mercurial libraries in [%s]\n"
% ' '.join(sys.path)
)
sys.stderr.write("(check your install and PYTHONPATH)\n")
sys.exit(-1)
from mercurial import (
dispatch,
util,
)
def timer(func, title=None):
results = []
begin = util.timer()
count = 0
while True:
ostart = os.times()
cstart = util.timer()
r = func()
cstop = util.timer()
ostop = os.times()
count += 1
a, b = ostart, ostop
results.append((cstop - cstart, b[0] - a[0], b[1] - a[1]))
if cstop - begin > 3 and count >= 100:
break
if cstop - begin > 10 and count >= 3:
break
if title:
sys.stderr.write("! %s\n" % title)
if r:
sys.stderr.write("! result: %s\n" % r)
m = min(results)
sys.stderr.write(
"! wall %f comb %f user %f sys %f (best of %d)\n"
% (m[0], m[1] + m[2], m[1], m[2], count)
)
orgruncommand = dispatch.runcommand
def runcommand(lui, repo, cmd, fullargs, ui, options, d, cmdpats, cmdoptions):
ui.pushbuffer()
lui.pushbuffer()
timer(
lambda: orgruncommand(
lui, repo, cmd, fullargs, ui, options, d, cmdpats, cmdoptions
)
)
ui.popbuffer()
lui.popbuffer()
dispatch.runcommand = runcommand
dispatch.run()
......@@ -12,16 +12,6 @@
import os
import sys
libdir = '@LIBDIR@'
if libdir != '@' 'LIBDIR' '@':
if not os.path.isabs(libdir):
libdir = os.path.join(
os.path.dirname(os.path.realpath(__file__)), libdir
)
libdir = os.path.abspath(libdir)
sys.path.insert(0, libdir)
# Make `pip install --user ...` packages available to the official Windows
# build. Most py2 packaging installs directly into the system python
# environment, so no changes are necessary for other platforms. The Windows
......
......@@ -2,3 +2,6 @@
members = ["hg-core", "hg-cpython", "hg-pyo3", "rhg", "pyo3-sharedref"]
exclude = ["chg", "hgcli"]
resolver = "2"
[workspace.lints.clippy]
or_fun_call = "deny"
......@@ -5,6 +5,9 @@
description = "Mercurial pure Rust core library, with no assumption on Python bindings (FFI)"
edition = "2021"
[lints]
workspace = true
[lib]
name = "hg"
......
......@@ -880,9 +880,9 @@
if parent_base.0 == p1.0 {
break;
}
p1 = self.check_revision(parent_base).ok_or(
RevlogError::InvalidRevision(parent_base.to_string()),
)?;
p1 = self.check_revision(parent_base).ok_or_else(|| {
RevlogError::InvalidRevision(parent_base.to_string())
})?;
}
while let Some(p2_entry) = self.get_entry(p2) {
if p2_entry.compressed_len() != 0 || p2.0 == 0 {
......@@ -893,10 +893,10 @@
if parent_base.0 == p2.0 {
break;
}
p2 = self.check_revision(parent_base).ok_or(
RevlogError::InvalidRevision(parent_base.to_string()),
)?;
p2 = self.check_revision(parent_base).ok_or_else(|| {
RevlogError::InvalidRevision(parent_base.to_string())
})?;
}
if base == p1.0 || base == p2.0 {
return Ok(false);
}
......@@ -899,10 +899,10 @@
}
if base == p1.0 || base == p2.0 {
return Ok(false);
}
rev = self
.check_revision(base.into())
.ok_or(RevlogError::InvalidRevision(base.to_string()))?;
rev = self.check_revision(base.into()).ok_or_else(|| {
RevlogError::InvalidRevision(base.to_string())
})?;
}
Ok(rev == NULL_REVISION)
}
......
......@@ -374,7 +374,9 @@
nodemap
.find_bin(self.index(), node)
.map_err(|err| (err, format!("{:x}", node)))?
.ok_or(RevlogError::InvalidRevision(format!("{:x}", node)))
.ok_or_else(|| {
RevlogError::InvalidRevision(format!("{:x}", node))
})
} else {
self.index().rev_from_node_no_persistent_nodemap(node)
}
......
......@@ -4,6 +4,9 @@
authors = ["Georges Racinet <gracinet@anybox.fr>"]
edition = "2021"
[lints]
workspace = true
[lib]
name='rusthg'
crate-type = ["cdylib"]
......
......@@ -3,6 +3,9 @@
version = "0.1.0"
edition = "2021"
[lints]
workspace = true
[lib]
name='rusthgpyo3'
crate-type = ["cdylib"]
......
......@@ -3,6 +3,9 @@
version = "0.1.0"
edition = "2021"
[lints]
workspace = true
[lib]
name='pyo3_sharedref'
......
......@@ -7,6 +7,9 @@
]
edition = "2021"
[lints]
workspace = true
[dependencies]
hg-core = { path = "../hg-core"}
chrono = "0.4.23"
......
......@@ -63,7 +63,6 @@
from setuptools.command.build_py import build_py
from setuptools.command.install import install
from setuptools.command.install_lib import install_lib
from setuptools.command.install_scripts import install_scripts
from setuptools.errors import (
CCompilerError,
......@@ -936,78 +935,6 @@
file_util.copy_file = realcopyfile
class hginstallscripts(install_scripts):
"""
This is a specialization of install_scripts that replaces the @LIBDIR@ with
the configured directory for modules. If possible, the path is made relative
to the directory for scripts.
"""
def initialize_options(self):
install_scripts.initialize_options(self)
self.install_lib = None
def finalize_options(self):
install_scripts.finalize_options(self)
self.set_undefined_options('install', ('install_lib', 'install_lib'))
def run(self):
install_scripts.run(self)
# It only makes sense to replace @LIBDIR@ with the install path if
# the install path is known. For wheels, the logic below calculates
# the libdir to be "../..". This is because the internal layout of a
# wheel archive looks like:
#
# mercurial-3.6.1.data/scripts/hg
# mercurial/__init__.py
#
# When installing wheels, the subdirectories of the "<pkg>.data"
# directory are translated to system local paths and files therein
# are copied in place. The mercurial/* files are installed into the
# site-packages directory. However, the site-packages directory
# isn't known until wheel install time. This means we have no clue
# at wheel generation time what the installed site-packages directory
# will be. And, wheels don't appear to provide the ability to register
# custom code to run during wheel installation. This all means that
# we can't reliably set the libdir in wheels: the default behavior
# of looking in sys.path must do.
if (
os.path.splitdrive(self.install_dir)[0]
!= os.path.splitdrive(self.install_lib)[0]
):
# can't make relative paths from one drive to another, so use an
# absolute path instead
libdir = self.install_lib
else:
libdir = os.path.relpath(self.install_lib, self.install_dir)
for outfile in self.outfiles:
with open(outfile, 'rb') as fp:
data = fp.read()
# skip binary files
if b'\0' in data:
continue
# During local installs, the shebang will be rewritten to the final
# install path. During wheel packaging, the shebang has a special
# value.
if data.startswith(b'#!python'):
logging.info(
'not rewriting @LIBDIR@ in %s because install path '
'not known',
outfile,
)
continue
data = data.replace(b'@LIBDIR@', libdir.encode('unicode_escape'))
with open(outfile, 'wb') as fp:
fp.write(data)
class hginstallcompletion(Command):
description = 'Install shell completion'
......@@ -1132,7 +1059,6 @@
'install': hginstall,
'install_completion': hginstallcompletion,
'install_lib': hginstalllib,
'install_scripts': hginstallscripts,
'build_hgexe': buildhgexe,
}
......
......@@ -20,5 +20,6 @@
> return re.sub(b' +', b' ', text.upper())
> stdout.write(format(stdin.read()))
> EOF
$ chmod +x some/dir/uppercase.py
......@@ -23,5 +24,13 @@
$ chmod +x some/dir/uppercase.py
#if windows
$ cat > some/dir/uppercase.bat <<EOF
> @echo off
> "$PYTHON" "$TESTTMP/test-repo/some/dir/uppercase.py"
> EOF
#else
$ mv some/dir/uppercase.py some/dir/uppercase
#endif
$ echo babar > babar.txt
$ hg add babar.txt
......@@ -36,7 +45,7 @@
> evolution.allowunstable=True
> [fix]
> extra-bin-paths=$TESTTMP/test-repo/some/dir/
> uppercase-whole-file:command=uppercase.py
> uppercase-whole-file:command=uppercase
> uppercase-whole-file:pattern=set:**.txt
> EOF
......