describe-commit: New script to describe commits in terms of refs#12
describe-commit: New script to describe commits in terms of refs#12dbnicholson wants to merge 2 commits intoostreedev:masterfrom
Conversation
cgwalters
left a comment
There was a problem hiding this comment.
Two minor comments, otherwise looks good.
| rev) | ||
| if commit is None: | ||
| break | ||
| refmap[rev].append((depth, ref + depth * '^')) |
There was a problem hiding this comment.
At some point we should add '~42` syntax like to ostree if we do more stuff like this.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
This also silently exits if the user typo'd a checksum. Is that intentional? We already break out below if there's no parent.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
I turned this into an error if the ref is pointing to a non-existent commit. See below.
| from gi.repository import GLib, Gio, OSTree | ||
| import sys | ||
|
|
||
| def commit_describe(repo, checksum, all_refs=True): |
There was a problem hiding this comment.
all_refs=True
This should be False by default, right?
There was a problem hiding this comment.
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.
1cb66f1 to
6c59562
Compare
dbnicholson
left a comment
There was a problem hiding this comment.
I think I addressed the comments now.
| while True: | ||
| _, commit = repo.load_variant_if_exists(OSTree.ObjectType.COMMIT, | ||
| rev) | ||
| if commit is None: |
There was a problem hiding this comment.
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.
| rev) | ||
| if commit is None: | ||
| break | ||
| refmap[rev].append((depth, ref + depth * '^')) |
There was a problem hiding this comment.
Yeah, I've thought about it many times but never spent the time to try to code it.
| from gi.repository import GLib, Gio, OSTree | ||
| import sys | ||
|
|
||
| def commit_describe(repo, checksum, all_refs=True): |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
I turned this into an error if the ref is pointing to a non-existent commit. See below.
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.