Skip to content

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

Open
dbnicholson wants to merge 2 commits intoostreedev:masterfrom
dbnicholson:describe-commit
Open

describe-commit: New script to describe commits in terms of refs#12
dbnicholson wants to merge 2 commits intoostreedev:masterfrom
dbnicholson:describe-commit

Conversation

@dbnicholson
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread describe-commit
rev)
if commit is None:
break
refmap[rev].append((depth, ref + depth * '^'))
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread describe-commit
while True:
_, commit = repo.load_variant_if_exists(OSTree.ObjectType.COMMIT,
rev)
if commit is None:
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

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

def commit_describe(repo, checksum, all_refs=True):
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread describe-commit
while True:
_, commit = repo.load_variant_if_exists(OSTree.ObjectType.COMMIT,
rev)
if commit is None:
Copy link
Copy Markdown
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.

Comment thread describe-commit
rev)
if commit is None:
break
refmap[rev].append((depth, ref + depth * '^'))
Copy link
Copy Markdown
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.

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

def commit_describe(repo, checksum, all_refs=True):
Copy link
Copy Markdown
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.

Comment thread describe-commit
while True:
_, commit = repo.load_variant_if_exists(OSTree.ObjectType.COMMIT,
rev)
if commit is None:
Copy link
Copy Markdown
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?

Comment thread describe-commit
while True:
_, commit = repo.load_variant_if_exists(OSTree.ObjectType.COMMIT,
rev)
if commit is None:
Copy link
Copy Markdown
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