* A few questions regarding git annotated tags @ 2019-01-05 15:50 Michal Novotny 2019-01-06 6:50 ` Jeff King 0 siblings, 1 reply; 3+ messages in thread From: Michal Novotny @ 2019-01-05 15:50 UTC (permalink / raw) To: git Hello, I am making an rpm packaging application called rpkg-util (https://pagure.io/rpkg-util) that can render parts of rpm metadata from git metadata, e.g. software version. It uses annotated tags to store most of the data that are then rendered to an rpm spec file (e.g. the version or changelog). Now I would like to make sure that I am not omitting some better approach than the one that I am currently using and for that I would like to ask the following questions. I could potentially make it so that I tag subtrees instead of commits and then derive the needed information from these subtree tags. This could be useful if I have multiple rpm packages in different subtrees of the same repo. I could then tag the subtree where the rpm package is placed. This could bring some simplification into the code but as far as I know, you cannot easily checkout a tree tag, which is something a packager should be able to do easily: to checkout a state of repo when a certain subpackage was tagged. This is the first question. Can you e.g. do: git tag somename HEAD: and then do something similar to git checkout somename which would restore the repository or at least the respective subtree of it into the state when "somename" tag was created? Right now, I am putting a package name directly into tag name so I know what tags belong to what package based on that. And I am using normal annotated tags. This works quite well, I would say, but at one point I need to use shared state to move the discovered package name from one part of the code to another so that the other part can work with the correct subset of the available annotated tags. I wouldn't need to do that if I could derive the correct tag subset based just on the path to the subtree where a package is placed. The path can be simply an input parameter of all my functions and they could all fetch the correct tag subset based just on that information. Those functions are independent of each other, they all derive some information from the tags but each one is specialized to fetch a different piece of information. This would be nice. Right now some of my functions accept name when they need to fetch the associated tag set and work with it and some accept path if they don't require the tag set. Alternative approach to creating the tree tags would be to store the path information into annotated tag message, which I could do. But is there a relatively simple way to filter tags based on their message content? Can I put the information into some other part of tag than name or the message so that it can be easily filtered? It would be also good if the association of the tags to the subtrees was made obvious (it will no longer be obvious when it won't depend on name of the tag) but that's a different problem that I could potentially solve if I can make the tag<->subtree relation work in some way. I am pretty happy with the current name-based solution but I don't want to miss something obvious or less obvious. Thank you Michal Novotny ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: A few questions regarding git annotated tags 2019-01-05 15:50 A few questions regarding git annotated tags Michal Novotny @ 2019-01-06 6:50 ` Jeff King 2019-01-10 13:24 ` Michal Novotny 0 siblings, 1 reply; 3+ messages in thread From: Jeff King @ 2019-01-06 6:50 UTC (permalink / raw) To: Michal Novotny; +Cc: git On Sat, Jan 05, 2019 at 04:50:30PM +0100, Michal Novotny wrote: > I could potentially make it so that I tag subtrees instead of commits > and then derive the needed information from these subtree tags. This > could be useful if I have multiple rpm packages in different subtrees > of the same repo. I could then tag the subtree where the rpm package > is placed. > > This could bring some simplification into the code but as far as I > know, you cannot easily checkout a tree tag, which is something a > packager should be able to do easily: to checkout a state of repo when > a certain subpackage was tagged. This is the first question. Can you > e.g. do: > > git tag somename HEAD: > > and then do something similar to > > git checkout somename > > which would restore the repository or at least the respective subtree > of it into the state when "somename" tag was created? No, there's no easy way to check out a bare tree (and in fact, HEAD is forbidden to point to a non-commit). You could hack around that by making a new commit that wraps the tree, like: commit=$(echo 'wrap foo package' | git commit-tree HEAD:foo) git tag foo-1.2.3 $commit There are also useful things to do with the tag of the bare tree. E.g., export it via git-archive, diff it, "git checkout -p" changes from it, etc. But actually creating a working tree state from it is awkward: # move to being on an "unborn" branch foo git checkout --orphan foo # load the desired tree state; "-u" will update the working tree # files git read-tree -m -u foo-1.2.3 # if we were to commit now, it would become the root commit of the # "foo" branch, with no parents. That would make it pretty useful for # things like merging between tags. git commit -m 'kind of weird' So it seems kind of awkward and useless. I'm not sure I totally understand your problem space, but if you can have actual commits with a logical progression (i.e., where the parent links actually mean something), I think Git's tools will be more useful. > Right now, I am putting a package name directly into tag name so I > know what tags belong to what package based on that. And I am using > normal annotated tags. This works quite well, I would say, but at one > point I need to use shared state to move the discovered package name > from one part of the code to another so that the other part can work > with the correct subset of the available annotated tags. I wouldn't > need to do that if I could derive the correct tag subset based just on > the path to the subtree where a package is placed. I'm not sure I understand this bit. Even if you tag a subtree, like: git tag foo-1.2.3 HEAD:foo then that tree doesn't "know" that it was originally at the path "foo". You'd have to tag the root tree, and then know to look in the "foo" subtree from there. At which point you might as well tag the commit that contains that root tree. Whether it happens to touch the "foo" path or not, it represents a particular state. > Alternative approach to creating the tree tags would be to store the > path information into annotated tag message, which I could do. But is > there a relatively simple way to filter tags based on their message > content? Can I put the information into some other part of tag than > name or the message so that it can be easily filtered? I don't think there's an easy way to show only tags matching a pattern. You could do something like: git tag -m 'path: foo' foo git for-each-ref --format='%(refname:strip=2) %(subject)' refs/tags/ | grep 'path: foo' | awk '{print $1}' to grep their subjects (or body, if you want to make the grep stage a little more clever). Obviously that is not really a structured lookup, but if you control the tag contents, it might be OK. In commit messages there's a concept of machine-readable trailers, like "Signed-off-by", etc, and even some tools for displaying those. But there's not currently any support for parsing them out of tag objects. I sort of answered your questions literally, but TBH I'm still not entirely sure what you're trying to accomplish. So hopefully it was useful, but feel free to follow up with more questions. ;) -Peff ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: A few questions regarding git annotated tags 2019-01-06 6:50 ` Jeff King @ 2019-01-10 13:24 ` Michal Novotny 0 siblings, 0 replies; 3+ messages in thread From: Michal Novotny @ 2019-01-10 13:24 UTC (permalink / raw) To: Jeff King; +Cc: git Hey Jeff! On Sun, Jan 6, 2019 at 7:50 AM Jeff King <peff@peff.net> wrote: > > On Sat, Jan 05, 2019 at 04:50:30PM +0100, Michal Novotny wrote: > > > I could potentially make it so that I tag subtrees instead of commits > > and then derive the needed information from these subtree tags. This > > could be useful if I have multiple rpm packages in different subtrees > > of the same repo. I could then tag the subtree where the rpm package > > is placed. > > > > This could bring some simplification into the code but as far as I > > know, you cannot easily checkout a tree tag, which is something a > > packager should be able to do easily: to checkout a state of repo when > > a certain subpackage was tagged. This is the first question. Can you > > e.g. do: > > > > git tag somename HEAD: > > > > and then do something similar to > > > > git checkout somename > > > > which would restore the repository or at least the respective subtree > > of it into the state when "somename" tag was created? > > No, there's no easy way to check out a bare tree (and in fact, HEAD is > forbidden to point to a non-commit). > > You could hack around that by making a new commit that wraps the tree, > like: > > commit=$(echo 'wrap foo package' | git commit-tree HEAD:foo) > git tag foo-1.2.3 $commit > > There are also useful things to do with the tag of the bare tree. E.g., > export it via git-archive, diff it, "git checkout -p" changes from it, > etc. But actually creating a working tree state from it is awkward: > > # move to being on an "unborn" branch foo > git checkout --orphan foo > > # load the desired tree state; "-u" will update the working tree > # files > git read-tree -m -u foo-1.2.3 > > # if we were to commit now, it would become the root commit of the > # "foo" branch, with no parents. That would make it pretty useful for > # things like merging between tags. > git commit -m 'kind of weird' > > So it seems kind of awkward and useless. I'm not sure I totally > understand your problem space, but if you can have actual commits with a > logical progression (i.e., where the parent links actually mean > something), I think Git's tools will be more useful. > > > Right now, I am putting a package name directly into tag name so I > > know what tags belong to what package based on that. And I am using > > normal annotated tags. This works quite well, I would say, but at one > > point I need to use shared state to move the discovered package name > > from one part of the code to another so that the other part can work > > with the correct subset of the available annotated tags. I wouldn't > > need to do that if I could derive the correct tag subset based just on > > the path to the subtree where a package is placed. > > I'm not sure I understand this bit. Even if you tag a subtree, like: > > git tag foo-1.2.3 HEAD:foo > > then that tree doesn't "know" that it was originally at the path "foo". > You'd have to tag the root tree, and then know to look in the "foo" > subtree from there. At which point you might as well tag the commit that > contains that root tree. Whether it happens to touch the "foo" path or > not, it represents a particular state. > > > Alternative approach to creating the tree tags would be to store the > > path information into annotated tag message, which I could do. But is > > there a relatively simple way to filter tags based on their message > > content? Can I put the information into some other part of tag than > > name or the message so that it can be easily filtered? > > I don't think there's an easy way to show only tags matching a pattern. > You could do something like: > > git tag -m 'path: foo' foo > > git for-each-ref --format='%(refname:strip=2) %(subject)' refs/tags/ | > grep 'path: foo' | > awk '{print $1}' > > to grep their subjects (or body, if you want to make the grep stage a > little more clever). Obviously that is not really a structured lookup, > but if you control the tag contents, it might be OK. > > In commit messages there's a concept of machine-readable trailers, like > "Signed-off-by", etc, and even some tools for displaying those. But > there's not currently any support for parsing them out of tag objects. > > > I sort of answered your questions literally, but TBH I'm still not > entirely sure what you're trying to accomplish. So hopefully it was > useful, but feel free to follow up with more questions. ;) No, I think you summed it up pretty well for me. I would like to ask one more question, which is now unrelated. But I will probably ask in a new thread. Thank you! clime > > -Peff ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-01-10 13:24 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2019-01-05 15:50 A few questions regarding git annotated tags Michal Novotny 2019-01-06 6:50 ` Jeff King 2019-01-10 13:24 ` Michal Novotny
Code repositories for project(s) associated with this public inbox https://80x24.org/mirrors/git.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).