From 913f2c63b31d0548326a8af0f372fd0103b21d8c Mon Sep 17 00:00:00 2001 From: Peter Donis Date: Sun, 13 Mar 2016 15:13:57 -0400 Subject: [PATCH 1/3] Add be3.fi git extractor test with tags. --- test/Makefile | 2 +- test/be3.fi | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 test/be3.fi diff --git a/test/Makefile b/test/Makefile index b8bad28ea..1d890e9d0 100644 --- a/test/Makefile +++ b/test/Makefile @@ -133,7 +133,7 @@ coalesce: @rm -f /tmp/regress # Test the git extractor -GITLOADS = bs be be2 +GITLOADS = bs be be2 be3 git-regress: @echo "=== Testing git-extractor:" @if command -v git >/dev/null 2>&1 ; \ diff --git a/test/be3.fi b/test/be3.fi new file mode 100644 index 000000000..c4934f6d9 --- /dev/null +++ b/test/be3.fi @@ -0,0 +1,116 @@ +blob +mark :1 +data 13 +Test file 1. + +reset refs/tags/0.1 +commit refs/tags/0.1 +mark :2 +author "J. Random Hacker" 1456976347 -0500 +committer "J. Random Hacker" 1456976347 -0500 +data 20 +Commit test file 1. +M 100644 :1 testfile1 + +blob +mark :3 +data 13 +Test file 2. + +commit refs/tags/0.1a +mark :4 +author "J. Random Hacker" 1456976408 -0500 +committer "J. Random Hacker" 1456976408 -0500 +data 20 +Commit test file 2. +from :2 +M 100644 :3 testfile2 + +blob +mark :5 +data 13 +Test file 3. + +commit refs/tags/0.1 +mark :6 +author "J. Random Hacker" 1456976475 -0500 +committer "J. Random Hacker" 1456976475 -0500 +data 20 +Commit test file 3. +from :2 +M 100644 :5 testfile3 + +commit refs/tags/1.0 +mark :7 +author "J. Random Hacker" 1456976606 -0500 +committer "J. Random Hacker" 1456976606 -0500 +data 19 +Merge test branch. +from :6 +merge :4 +M 100644 :3 testfile2 + +blob +mark :8 +data 13 +Test file 4. + +commit refs/tags/1.0a +mark :9 +author "J. Random Hacker" 1456976715 -0500 +committer "J. Random Hacker" 1456976715 -0500 +data 20 +Commit test file 4. +from :4 +M 100644 :8 testfile4 + +blob +mark :10 +data 13 +Test file 5. + +commit refs/tags/1.1 +mark :11 +author "J. Random Hacker" 1456976798 -0500 +committer "J. Random Hacker" 1456976798 -0500 +data 20 +Commit test file 5. +from :7 +M 100644 :10 testfile5 + +blob +mark :12 +data 26 +Test file 5. +Second line. + +commit refs/heads/master +mark :13 +author "J. Random Hacker" 1457895329 -0400 +committer "J. Random Hacker" 1457895329 -0400 +data 25 +Add line to test file 5. +from :11 +M 100644 :12 testfile5 + +blob +mark :14 +data 26 +Test file 4. +Second line. + +commit refs/heads/test +mark :15 +author "J. Random Hacker" 1457895350 -0400 +committer "J. Random Hacker" 1457895350 -0400 +data 25 +Add line to test file 4. +from :9 +M 100644 :14 testfile4 + +reset refs/heads/master +from :13 + +reset refs/heads/test +from :15 + -- GitLab From d1a53df7e1c975d4f830ba0efd9b4f1b6027f92c Mon Sep 17 00:00:00 2001 From: Peter Donis Date: Sun, 13 Mar 2016 15:42:57 -0400 Subject: [PATCH 2/3] Fix hg extractor branch coloring to use tags in preference to branch names when applicable. --- reposurgeon | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/reposurgeon b/reposurgeon index 65f564f9e..98a1c4067 100755 --- a/reposurgeon +++ b/reposurgeon @@ -839,8 +839,8 @@ class Extractor(object): # are, for whatever reason, not caught for refname, refobj in sorted(self.refs.items(), key=lambda ref: self.revlist.index(ref[1])): - self.__branch_color(refobj, refname) - def __branch_color(self, rev, color): + self._branch_color(refobj, refname) + def _branch_color(self, rev, color): if rev.startswith("ref"): return while 'branch' not in self.meta[rev]: @@ -854,7 +854,7 @@ class Extractor(object): rev = parents[0] else: for parent in parents: - self.__branch_color(parent, color) + self._branch_color(parent, color) break def pre_extract(self, repo): "Hook for any setup actions required before streaming." @@ -1142,13 +1142,37 @@ class HgExtractor(Extractor): # creates the tag as an annotation, but that's a job for the surgeon # later, not the extractor now. def _color_branches(self): - # Hg stores branch info in the metadata for each commit, - # so we just need to get it using hg log - with self.hg_or_die("log", "--template", "{node|short} {branch}\\n") as fp: + # Hg stores branch and tag info in the metadata for each commit, + # so we just need to get it using hg log; to match the behavior of + # git fast-export, tags take precedence over branches, and we don't + # color branches here because they should only appear for the branch + # tip commits and their ancestors back to the first tag, which will + # be taken care of by + tags_found = [] + with self.hg_or_die("log", "--template", "{node|short} {tags}\\n") as fp: for line in fp: - h, branch = polystr(line).strip().split() - self.meta[h]['branch'] = "refs/heads/" + branch - # This should not be needed, but do it for completeness + fields = polystr(line).strip().split() + if (len(fields) > 1) and (fields[1] != "tip"): + h = fields[0] + tag = fields[1] + self.meta[h]['branch'] = "refs/tags/" + tag + tags_found.append((h, tag)) + if tags_found: + # If we found tags, we need to color the commits in between them, which + # won't be labeled with a tag in the hg log output above + for h, tag in tags_found: + for parent in self.get_parents(h): + self._branch_color(parent, "refs/tags/" + tag) + else: + # If we didn't find any tags, we need to go back and color the commits + # using branch names; we can't depend on the superclass algorithm to + # do this correctly + with self.hg_or_die("log", "--template", "{node|short} {branch}\\n") as fp: + for line in fp: + h, branch = polystr(line).strip().split() + self.meta[h]['branch'] = "refs/heads/" + branch + # This will take care of branch tip commits and their ancestors back + # to the first tag, if we found tags above; otherwise it should be a no-op Extractor._color_branches(self) def post_extract(self, repo): super(HgExtractor, self).post_extract(repo) -- GitLab From e5054a4877a229b0fcf01e027a8382f60dfa579e Mon Sep 17 00:00:00 2001 From: Peter Donis Date: Sun, 13 Mar 2016 15:43:44 -0400 Subject: [PATCH 3/3] Add be3 to hg extractor test. --- test/Makefile | 2 +- test/hg-be3-test | 95 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100755 test/hg-be3-test diff --git a/test/Makefile b/test/Makefile index 1d890e9d0..aa30f84a1 100644 --- a/test/Makefile +++ b/test/Makefile @@ -165,7 +165,7 @@ hg-regress: @rm -f /tmp/regress # Test the hg extractor with multiple hg branches -HGBRANCHES = be be2 +HGBRANCHES = be be2 be3 hg-buildregress-branches: @for file in $(HGBRANCHES); do \ echo "Remaking $${file}.fi"; \ diff --git a/test/hg-be3-test b/test/hg-be3-test new file mode 100755 index 000000000..0b3d2eac7 --- /dev/null +++ b/test/hg-be3-test @@ -0,0 +1,95 @@ +#!/bin/sh +# +# Test reposurgeon branch naming issue with hg repo including merge and tags +# +# This test cannot use the usual hg-to-fi script because it +# needs an hg repo with actual hg branches, not hg bookmarks; +# the hg convert utility converts git branches in a fast-import +# stream to hg bookmarks, so the hg-regress test target only +# tests correct handling of hg bookmarks, not hg branches + +# Required because $PWD seems to be undefined in Gitlab's CI environment +BIN=`realpath ..` + +build=True +stream=True +cleanup=True + +pecho() { printf %s\\n "$*"; } +log() { pecho "$@"; } +error() { log "ERROR: $@" >&2; } +fatal() { error "$@"; exit 1; } +try() { "$@" || fatal "'$@' failed"; } + +while getopts nr opt +do + case $opt in + n) build=True; stream=False ; cleanup=False ;; + r) build=False; stream=True ; cleanup=False ;; + esac +done +shift $(($OPTIND - 1)) + +testrepo=${1:-/tmp/test-repo} + +USER='"J. Random Hacker" ' + +# Should we build the repo? +if [ $build = True ] +then + # Build hg test repo with multiple hg branches + try rm -fr $testrepo + try hg init $testrepo || exit 1 + try cd $testrepo >/dev/null + # The weird --date incantation in the hg commits is to ensure that the commit + # timestamps match those in the .fi file; the 18000 is because hg wants the time zone + # offset in seconds west of UTC, for what reason I know not--I know there are weird + # time zones in the world but I didn't think any of them got down to one-second + # granularity in offsets... + ( + try echo "Test file 1." > testfile1 + try hg add testfile1 >/dev/null + try hg commit --user "$USER" --date "1456976347 18000" -m "Commit test file 1." >/dev/null + try hg branch test >/dev/null + try echo "Test file 2." > testfile2 + try hg add testfile2 >/dev/null + try hg commit --user "$USER" --date "1456976408 18000" -m "Commit test file 2." >/dev/null + try hg tag --local 0.1a >/dev/null + try hg update default >/dev/null + try echo "Test file 3." > testfile3 + try hg add testfile3 >/dev/null + try hg commit --user "$USER" --date "1456976475 18000" -m "Commit test file 3." >/dev/null + try hg tag --local 0.1 >/dev/null + try hg merge test >/dev/null + try hg commit --user "$USER" --date "1456976606 18000" -m "Merge test branch." >/dev/null + try hg tag --local 1.0 >/dev/null + try hg update test >/dev/null + try echo "Test file 4." > testfile4 + try hg add testfile4 >/dev/null + try hg commit --user "$USER" --date "1456976715 18000" -m "Commit test file 4." >/dev/null + try hg tag --local 1.0a >/dev/null + try hg update default >/dev/null + try echo "Test file 5." > testfile5 + try hg add testfile5 >/dev/null + try hg commit --user "$USER" --date "1456976798 18000" -m "Commit test file 5." >/dev/null + try hg tag --local 1.1 >/dev/null + try echo "Second line." >> testfile5 + try hg commit --user "$USER" --date "1457895329 14400" -m "Add line to test file 5." >/dev/null + try hg update test >/dev/null + try echo "Second line." >> testfile4 + try hg commit --user "$USER" --date "1457895350 14400" -m "Add line to test file 4." >/dev/null + ) || exit 1 + try cd - >/dev/null +fi + +# Should we stream the repo? +if [ $stream = True ] +then + try ${BIN}/reposurgeon "read $testrepo" "sourcetype git" "write -" +fi + +# Should we clean up the test directory +if [ $cleanup = True ] +then + try rm -fr $testrepo +fi -- GitLab