Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.

Commit 1ca80a1

Browse files
committed
Implement catchup targets
Implement a new target 'catchup' that will backport upstream commits from the current package version to HEAD. Implement a new target 'catchup-<commit|tag>' that will backport upstream commits up to the target, as resolvable by git. This powers 'catchup'. Rework the target 'backport-<commit>' to clone and use the upstream git repository instead of using GitHub URLs. This also simplifies the resolution of targets to full commit hashes, as needed to ensure unique patch names and entries in 'series'. 'make catchup' will backport all the patches to catch this package up to the upstream's HEAD 'make catchup-v5.0' will backport all the patches to catch this package up to tag "v5.0" upstream. 'make catchup-ffdcba' will backport all the patches between this package's current version and the upstream commit ffdcba. 'make backport-ffdcba' will backport ONLY upstream commit ffdcba. All targets will produce patches named "backport-<commit>.patch", where <commit> is the full SHA1 commit hash, regardless of whether you used an abbreviated hash (or a tag, for catchup-%). Patches are added to 'series' in chronological order, unless they're already anywhere in that file.
1 parent 27e359b commit 1ca80a1

1 file changed

Lines changed: 52 additions & 11 deletions

File tree

Makefile.common

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -582,27 +582,68 @@ cloc: $(SRPMFILE)
582582
@$(MOCK) --clean --scrub=chroot --uniqueext=$(PKG_NAME)
583583
cat results/cloc.txt
584584

585+
#help catchup: Backport the commits from the current version to the upstream HEAD (not release).
586+
#help Only works if giturl is defined and the current package version can be mapped to a git tag.
587+
catchup:
588+
$(MAKE) catchup-HEAD
589+
590+
#help catchup-<commit|tag>: Backport the commits from the current version to the specified commit or tag.
591+
#help Only works if giturl is defined and the current package version can be mapped to a git tag.
592+
catchup-%:
593+
@target=$*; \
594+
giturl=$$(grep -E '^giturl\s*=\s*\S+' options.conf | sed 's/giturl\s*=\s*//' 2>/dev/null); \
595+
if [[ -z "$${giturl}" ]]; then \
596+
echo "Error: giturl not defined in options.conf"; \
597+
exit 1; \
598+
fi; \
599+
mkdir -p results; \
600+
if [[ -d results/$(PKG_NAME) ]]; then \
601+
echo "Reusing existing repository..."; \
602+
git -C results/$(PKG_NAME) fetch origin; \
603+
else \
604+
echo "Cloning upstream repository..."; \
605+
git -C results clone "$${giturl}" $(PKG_NAME); \
606+
fi; \
607+
if ! git -C results/$(PKG_NAME) rev-parse --verify --quiet "$${target}" >/dev/null; then \
608+
echo "Error: Target commit/tag $${target} not found"; \
609+
exit 1; \
610+
fi; \
611+
echo "Version: $$(rpm -q --qf '%{VERSION}\n' --specfile $(SPECFILE) | head -1)"; \
612+
current_tag=$$(git -C results/$(PKG_NAME) tag --list | grep -E "^($(PKG_NAME)-)?v?$$(rpm -q --qf '%{VERSION}\n' --specfile $(SPECFILE) | head -1)$$") || { \
613+
echo "Error: No tag found for current package version"; \
614+
exit 1; \
615+
}; \
616+
echo "Catching up from $${current_tag} to $${target}"; \
617+
for commit in $$(git -C results/$(PKG_NAME) log --reverse --pretty=oneline $${current_tag}..$${target} | cut -d' ' -f1); do \
618+
$(MAKE) backport-$${commit}; \
619+
done;
620+
621+
585622
#help backport-<commit>: Retrieve a commit from the upstream git repository and save it as a backport patch.
586-
#help Currently only works with GitHub repositories. The giturl is read from options.conf.
623+
#help The giturl is read from options.conf.
587624
backport-%:
588625
@commit=$*; \
589626
echo "Backporting commit: $${commit}"; \
590-
giturl=$$(grep -E '^giturl\s*=\s*https://github.com' options.conf | sed 's/giturl\s*=\s*//' | sed 's/\.git$$//' | sed 's/\/$$//' 2>/dev/null); \
627+
giturl=$$(grep -E '^giturl\s*=\s*\S+' options.conf | sed 's/giturl\s*=\s*//' 2>/dev/null); \
591628
if [[ -z "$${giturl}" ]]; then \
592629
echo "Error: giturl not defined in options.conf"; \
593630
exit 1; \
594631
fi; \
595-
if ! curl -s -L -o $@.patch $${giturl}/commit/$*.patch || [[ "Not Found" == $$(< $@.patch) ]]; then \
596-
rm -f $@.patch; \
597-
echo "Error: Failed to download commit $*"; \
598-
exit 1; \
632+
mkdir -p results; \
633+
if [[ -d results/$(PKG_NAME) ]]; then \
634+
echo "Reusing existing repository..."; \
635+
git -C results/$(PKG_NAME) fetch origin; \
636+
else \
637+
echo "Cloning upstream repository..."; \
638+
git -C results clone "$${giturl}" $(PKG_NAME); \
599639
fi; \
600-
patch=$@.patch; \
601-
full_commit=$$(head -1 $@.patch | grep -oE '\b$*\S+' 2>/dev/null); \
602-
if ! [[ -z "$${full_commit}" ]]; then \
603-
patch=backport-$${full_commit}.patch; \
604-
mv $@.patch $${patch}; \
640+
full_commit=$$(git -C results/$(PKG_NAME) show --pretty=oneline $${commit} 2>/dev/null | head -1 | cut -d' ' -f 1); \
641+
if [[ -z "$${full_commit}" ]]; then \
642+
echo "Error: Commit for $${commit} not found"; \
643+
exit 1; \
605644
fi; \
645+
patch=backport-$${full_commit}.patch; \
646+
git -C results/$(PKG_NAME) format-patch -1 --stdout $${full_commit} > $${patch}; \
606647
if [[ -s $${patch} ]]; then \
607648
echo "$${patch} created"; \
608649
grep -qE "^$${patch}$$" series 2>/dev/null || echo "$${patch}" >> series; \

0 commit comments

Comments
 (0)