diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index c33ec057cfe2ce895ac8be03efbe6c65a8977e6b_LmdpdGxhYi1jaS55bWw=..0a957277827854c05820ba29d60c22168fa2fedf_LmdpdGxhYi1jaS55bWw= 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -8,8 +8,7 @@
   BASE_IMAGES_TAG: $CI_COMMIT_HG_BRANCH
   BASE_IMAGES_COLLECTION: registry.heptapod.net:443/heptapod/ci-images
   BASE_IMAGES_MERCURIAL: $BASE_IMAGES_COLLECTION/mercurial
-  # good enough for now, will have to depend on branch at some point:
-  MERCURIAL_RUST_DEP_REVISION: default
+  MERCURIAL_SHARE_FROM: /opt/mercurial/hg
   CARGO_HOME: ${CI_PROJECT_DIR}/cargo_home
 
 
@@ -68,7 +67,7 @@
   cache:
     policy: pull-push
   script:
-    - ci/prepare-rhgitaly
+    - make -C rust dev-dependencies
     - cargo test --manifest-path rust/Cargo.toml
     - rust/lint
   artifacts:
@@ -95,7 +94,7 @@
   variables:
     GITALY_INSTALL_DIR: /opt/gitlab/gitaly
   script:
-    - ci/prepare-rhgitaly
+    - make -C rust dev-dependencies
     # prebuilding RHGitaly to avoid doing it from tests
     # (output is interesting and we avoid timeout issues)
     - . /root/.cargo/env
diff --git a/ci/prepare-rhgitaly b/ci/prepare-rhgitaly
deleted file mode 100755
index c33ec057cfe2ce895ac8be03efbe6c65a8977e6b_Y2kvcHJlcGFyZS1yaGdpdGFseQ==..0000000000000000000000000000000000000000
--- a/ci/prepare-rhgitaly
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/bin/sh
-
-# Mercurial dependency. Thanks to the share from
-# the base image, the pull should be small
-MERCURIAL_RUST_DEP=rust/dependencies/mercurial
-hg share --noupdate /opt/mercurial/hg ${MERCURIAL_RUST_DEP}
-hg -R ${MERCURIAL_RUST_DEP} pull -r ${MERCURIAL_RUST_DEP_REVISION} \
-    https://foss.heptapod.net/mercurial/mercurial-devel
-hg -R ${MERCURIAL_RUST_DEP} update -r ${MERCURIAL_RUST_DEP_REVISION}
diff --git a/rust/Makefile b/rust/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..0a957277827854c05820ba29d60c22168fa2fedf_cnVzdC9NYWtlZmlsZQ==
--- /dev/null
+++ b/rust/Makefile
@@ -0,0 +1,30 @@
+all: help
+
+MERCURIAL_SOURCE_REPO = dependencies/mercurial
+MERCURIAL_SOURCE_REV := $(shell cat mercurial.rev)
+MERCURIAL_SOURCE_REMOTE ?= https://foss.heptapod.net/mercurial/mercurial-devel
+
+.PHONY: help
+help:
+	@echo "Makefile for RHGitaly development setup and packaging"
+	@echo ""
+	@echo "Available commands: "
+	@echo "  make dev-dependencies:  prepare development dependencies"
+	@echo "                          (hg-core, various resources)"
+	@echo
+	@echo "Interesting variables: "
+	@echo "  MERCURIAL_SHARE_FROM: if set, Mercurial sources repository"
+	@echo "                        will be created (if needed) with"
+	@echo "                        'hg share' from this given path."
+
+.PHONY: dev-dependencies
+dev-dependencies: dependencies/mercurial/.hg
+	hg -R $(MERCURIAL_SOURCE_REPO) pull -r $(MERCURIAL_SOURCE_REV) $(MERCURIAL_SOURCE_REMOTE)
+	hg -R $(MERCURIAL_SOURCE_REPO) update --config commands.update.check=abort $(MERCURIAL_SOURCE_REV)
+
+dependencies/mercurial/.hg:
+ifdef MERCURIAL_SHARE_FROM
+	hg share --noupdate $(MERCURIAL_SHARE_FROM) $(MERCURIAL_SOURCE_REPO)
+else
+	hg clone --noupdate $(MERCURIAL_SOURCE_REMOTE) $(MERCURIAL_SOURCE_REPO)
+endif
diff --git a/rust/mercurial.rev b/rust/mercurial.rev
new file mode 100644
index 0000000000000000000000000000000000000000..0a957277827854c05820ba29d60c22168fa2fedf_cnVzdC9tZXJjdXJpYWwucmV2
--- /dev/null
+++ b/rust/mercurial.rev
@@ -0,0 +1,1 @@
+59fda8516774ee9e47d2a88e5b6c9f42ab611b1c