The following code pulls the first line out of a gitlog commit if 1.2.0 is found later in the text: raku -e 'put $_.split("\n") if m/ \1\.2\.0 / given slurp() ' Ideally your test input (or inputs) should exercise many different possibilities: multiple commit records, both before and after the target, duplicate records, etc, especially if this code is to be used in any sort of unattented fashion without a human right there to sanity check the results: % 1.1.1Ĭommit ffffffffffffffffffffffffffffffffffffffff This allows the parse to go line-by-line: % 1.2.0/) ' Or, it could match the commit multiple times, as there is nothing that restricts the version information to only matching with the commit line prior to it.Īnother method is to remember the last commit, and use that value when However, this could be extremely inefficient as the regularĮxpression might have to search the entire log multiple times for eachĬommit and perhaps may not find the desired version number. ( -0777 slurps up the whole input), and the ms regular expressionįlags lets ^ match newlines anywhere and the. Here -0777 is a less experimental version of the GNU grep -z flag Unless GNU grep has a flag to modify where ^ matches like Perl does: % 1.2.0/ms' Use ^commit to limit where the match starts, but -z prevents that, With a line-based regular expression one could Also, theĭocumentation for the PCRE flag -P mentions something about beingĮxperimental with -z. Which is maybe not ideal, given the false positive. This is what actually happens using regexr.įor the sample commit log saved to the file gitlog, the GNU grep command pulls up % 1.2.0)'Ī1357f4e1cb2c34aa1a1357f4e1cb2c34aa1471fmessage% Using the aforementioned regex on this input should output the commit hash: Obviously, this being the log of all the commits done on a certain repository, there may be more than one commit as well. I want to pick the hash of the commit where version changed to a certain value ( 1.2.0 in the regex I wrote). To clarify, this is an example of git log: commit a1357f4e1cb2c34aa1a1357f4e1cb2c34aa1471f I'm surely missing something, but I cannot figure out what. Git log -full-history -p pom.xml | perl -nle 'print \$1 if /commit \K*(?=*\ .*1.2.0)/'īut neither of them worked (nothing seems to match). I then tried to run with the following commands: I created it on regexr and it works using PCRE this is my regex: I'd like to filter the content of a log of a pom.xml file using a regex.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |