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

describe-commit: New script to describe commits in terms of refs #12

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

Conversation

dbnicholson
Copy link
Member

This is similar to git-describe(1) in that it takes a commit checksum
and describes the commit in terms of refs. This is useful if you have a
repository with a lot of commits and need to do some non-standard
pruning.

Copy link
Member

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

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

Two minor comments, otherwise looks good.

describe-commit Outdated
rev)
if commit is None:
break
refmap[rev].append((depth, ref + depth * '^'))
Copy link
Member

Choose a reason for hiding this comment

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

At some point we should add '~42` syntax like to ostree if we do more stuff like this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I've thought about it many times but never spent the time to try to code it.

while True:
_, commit = repo.load_variant_if_exists(OSTree.ObjectType.COMMIT,
rev)
if commit is None:
Copy link
Member

Choose a reason for hiding this comment

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

This also silently exits if the user typo'd a checksum. Is that intentional? We already break out below if there's no parent.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I hadn't thought about that case. The reason this silently breaks is to catch the case that the parent commit is missing. The case below is when the commit doesn't actually have a parent. Perhaps this just needs to check if depth is 0 and raise an exception since that would represent the checksum that the user passed in.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually this part is not coupled to the checksum that was passed in by the user. This loop is entirely about building up names for referenced commits and their parents. I can add a warning or error if the commit pointed to by the ref itself (depth == 0) does not exist. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

I turned this into an error if the ref is pointing to a non-existent commit. See below.

describe-commit Outdated
from gi.repository import GLib, Gio, OSTree
import sys

def commit_describe(repo, checksum, all_refs=True):
Copy link
Member

@jlebon jlebon Mar 6, 2017

Choose a reason for hiding this comment

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

all_refs=True

This should be False by default, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I think so since that matches the CLI default. I almost always run it with --all since I'm usually trying to figure out if a commit can be pruned or not, but I think for consistency you're right.

This is similar to git-describe(1) in that it takes a commit checksum
and describes the commit in terms of refs. This is useful if you have a
repository with a lot of commits and need to do some non-standard
pruning.
Copy link
Member Author

@dbnicholson dbnicholson left a comment

Choose a reason for hiding this comment

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

I think I addressed the comments now.

while True:
_, commit = repo.load_variant_if_exists(OSTree.ObjectType.COMMIT,
rev)
if commit is None:
Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I hadn't thought about that case. The reason this silently breaks is to catch the case that the parent commit is missing. The case below is when the commit doesn't actually have a parent. Perhaps this just needs to check if depth is 0 and raise an exception since that would represent the checksum that the user passed in.

describe-commit Outdated
rev)
if commit is None:
break
refmap[rev].append((depth, ref + depth * '^'))
Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I've thought about it many times but never spent the time to try to code it.

describe-commit Outdated
from gi.repository import GLib, Gio, OSTree
import sys

def commit_describe(repo, checksum, all_refs=True):
Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I think so since that matches the CLI default. I almost always run it with --all since I'm usually trying to figure out if a commit can be pruned or not, but I think for consistency you're right.

while True:
_, commit = repo.load_variant_if_exists(OSTree.ObjectType.COMMIT,
rev)
if commit is None:
Copy link
Member Author

Choose a reason for hiding this comment

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

Actually this part is not coupled to the checksum that was passed in by the user. This loop is entirely about building up names for referenced commits and their parents. I can add a warning or error if the commit pointed to by the ref itself (depth == 0) does not exist. What do you think?

while True:
_, commit = repo.load_variant_if_exists(OSTree.ObjectType.COMMIT,
rev)
if commit is None:
Copy link
Member Author

Choose a reason for hiding this comment

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

I turned this into an error if the ref is pointing to a non-existent commit. See below.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants