Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that parent_tag is in an ancestor of the checked out branch #211

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jengelh
Copy link
Contributor

@jengelh jengelh commented Nov 8, 2017

git rev-list A..B returns the set of commits present in B but not
A. Only if A is an ancestor of B will the cardinality of the set be
the same as the forward-running offset from A to B.

Copy link
Member

@aspiers aspiers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this sounds like a great improvement, and I'm sorry I didn't review this before - I continue to be mystified why I don't always receive email notifications from GitHub when new issues/PRs are submitted 😠
Please could you expand the commit message to explain the scenarios in which parent_tag would not be an ancestor? Is it only if parent_tag is specified manually as a parameter? Presumably if it's not specified and is calculated via _detect_parent_tag then git describe --tags will always choose an ancestor, at least according to my reading of the git-describe(1) man page.

Two other suggestions: I think the code for checking ancestry would benefit from being extracted into a separate function call to avoid _detect_version_tag_offset getting too long and unwieldly, and secondly please can we have a unit test for this?

Thanks a lot!

@jengelh
Copy link
Contributor Author

jengelh commented Jan 9, 2018

* 12345678 (tag: 1.1.0) bump version to 1.1.0
| * 23456789 (tag: 1.0.2) bump version to 1.0.2
|/
* 34567890 common base

combined with

<param name="revision">23456789</param>
<param name="parent-tag">1.1.0</param>
<param name="versionformat">@PARENT_TAG@.@TAG_OFFSET@</param>

is such an insatisfiable combination.

@aspiers
Copy link
Member

aspiers commented Jan 9, 2018

@jengelh Sure, but that doesn't answer my previous question:

Is it only if parent_tag is specified manually as a parameter?

Emphasis on "only", i.e. could it also happen if parent_tag is unspecified? AFAICS the answer is no, but I wanted to check you agree before we amend the commit message accordingly. This is important to establish because the code you are modifying can be called even if parent_tag is unspecified. Thanks!

@jengelh
Copy link
Contributor Author

jengelh commented Jan 9, 2018

When parent-tag is implicit, the tag git-describe chooses is already known to be an ancestor. Only when this is explicitly overridden with a different parent-tag in the _service file is it possible for it not to be an ancestor.

@aspiers
Copy link
Member

aspiers commented Jan 9, 2018

OK good, so we are agreed :-)

@jengelh
Copy link
Contributor Author

jengelh commented Apr 23, 2018

message updated

@aspiers
Copy link
Member

aspiers commented Jun 19, 2018

Thanks for the message update, that looks good now. I still think my previous comment is relevant though:

Two other suggestions: I think the code for checking ancestry would benefit from being extracted into a separate function call to avoid _detect_version_tag_offset getting too long and unwieldly, and secondly please can we have a unit test for this?

Copy link
Member

@aspiers aspiers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the new method is much nicer! Just needs a unit test now.

)
if rcode:
sys.exit("\033[31m`git rev-parse " + parent_tag + "` failed: " +
output + "\033[0m")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Travis correctly spotted that output is not defined here.

)
if rcode:
sys.exit("\033[31m`git rev-parse HEAD` failed: " +
output + "\033[0m")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same problem here.

sys.exit(color_red("@TAG_OFFSET@ cannot be expanded, as no parent tag was discovered."))
self.check_ancestry(parent_tag)
rcode, output = self.helpers.run_cmd(
self._get_scm_cmd() + ['rev-list', '--count', parent_tag + '..HEAD'],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (81 > 79 characters)

cmd = self._get_scm_cmd()
cmd.extend(['rev-list', '--count', parent_tag + '..HEAD'])
rcode, out = self.helpers.run_cmd(cmd, self.clone_dir)
sys.exit(color_red("@TAG_OFFSET@ cannot be expanded, as no parent tag was discovered."))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (100 > 79 characters)

@@ -6,6 +6,10 @@

from TarSCM.scm.base import Scm

def color_red(s):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected 2 blank lines, found 1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one makes no sense, there's just one line above every def

@nmorey
Copy link
Contributor

nmorey commented Nov 12, 2018

Just saw this pop in my notification.
My two cents:

The easiest way to check if a commit is an ancestor is git merge-base --is-ancestor
git merge-base --is-ancestor PARENT_TAG CURRENT_SHA

Returns 0 if it is an ancestor, 1 if it isn't.
This was introduced in 1.8 so is probably old enough to be available everywhere

`git rev-list A..B` returns the set of commits present in B but not
A. Only if A is an ancestor of B will the cardinality of the set be
the same as the forward-running offset from A to B.

When parent-tag is implicit, the tag `git-describe` chooses is
already known to be an ancestor. Only when this is explicitly
overridden with a different parent-tag in the _service file, it will
be possible for the chosen parent-tag value not to refer to a commit
that is a valid ancestor.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants