D10020: debian: support a "chg-first" installation mechanism (hg is actually chg)

spectral (Kyle Lippincott) phabricator at mercurial-scm.org
Thu Feb 18 23:36:05 UTC 2021


spectral created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This mechanism builds chg such that it looks for `hg` to be available at
  /usr/lib/mercurial/hg instead of in the $PATH as `hg`, and makes the `hg` in
  /usr/bin be a symlink to `chg`.
  
  It's important to note that the hg binary must continue to be named `hg`. If we
  wanted to instead place it at /usr/bin/pyhg or something similar, we would need
  to modify Mercurial to allow that basename. Failure to do so would break
  Mercurial's shell aliases that use `hg`, `chg`, or `$HG`.
  
  I don't know if we should ever have a setup like this be the default setup, but
  I'm willing to get more information on our experience with it for making such a
  determination. Actually making it the default might be rather involved, as we
  don't maintain the official debian packaging rules.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10020

AFFECTED FILES
  contrib/packaging/debian/rules

CHANGE DETAILS

diff --git a/contrib/packaging/debian/rules b/contrib/packaging/debian/rules
--- a/contrib/packaging/debian/rules
+++ b/contrib/packaging/debian/rules
@@ -18,6 +18,10 @@
 #   DEB_HG_PYTHON_VERSIONS="3.7 3.8" make deb
 DEB_HG_MULTI_VERSION?=0
 
+# Set to 1 to make /usr/bin/hg a symlink to chg, and move hg to
+# /usr/lib/mercurial/hg.
+DEB_HG_CHG_BY_DEFAULT?=0
+
 CPUS=$(shell cat /proc/cpuinfo | grep -E ^processor | wc -l)
 
 # By default, only build for the version of python3 that the system considers
@@ -40,6 +44,12 @@
 	DEB_HG_PYTHON_VERSIONS?=$(shell py3versions -vd)
 endif
 
+ifeq ($(DEB_HG_CHG_BY_DEFAULT), 1)
+	# Important: the "real" hg must have a 'basename' of 'hg'. Otherwise, hg
+	# behaves differently when setting $HG and breaks aliases that use that.
+	export HGPATH=/usr/lib/mercurial/hg
+endif
+
 export HGPYTHON3=1
 export PYTHON=python3
 
@@ -86,3 +96,8 @@
 	cp contrib/bash_completion "$(CURDIR)"/debian/mercurial/usr/share/bash-completion/completions/hg
 	mkdir -p "$(CURDIR)"/debian/mercurial/usr/share/zsh/vendor-completions
 	cp contrib/zsh_completion "$(CURDIR)"/debian/mercurial/usr/share/zsh/vendor-completions/_hg
+	if [[ "$(DEB_HG_CHG_BY_DEFAULT)" -eq 1 ]]; then \
+		mkdir -p "$(CURDIR)"/debian/mercurial/usr/lib/mercurial; \
+		mv "$(CURDIR)"/debian/mercurial/usr/bin/hg "$(CURDIR)"/debian/mercurial/usr/lib/mercurial/hg; \
+		ln -s chg "$(CURDIR)"/debian/mercurial/usr/bin/hg; \
+	fi



To: spectral, #hg-reviewers
Cc: mercurial-patches, mercurial-devel


More information about the Mercurial-devel mailing list