2

I am using TortoiseSVN on windows, with the command-line svn.exe.

I am struggling to get latest svn log message for a particular text in log Message. I am using the below command to get all the log messages for a particular text.

svn log --search="text"

I get a list of messages having that "text". But from this list, I just want the latest one. How can I get that?

2 Answers 2

2

You need to add a -l 1 to your command like this:

svn log -l 1 --search="text"

The -l flag is the shorter version of --limit:

--limit (-l) NUM

Shows only the first NUM log messages.

By first NUM log messages it means the first it hits in order from newest -> oldest.

You view some documenation on the svn log command here.


The above doesn't actually work in this case as per @bahrep's answer however as this doesn't appear to be possible using svn.exe only. I have created a python script that does it:

import xml.etree.ElementTree as ET
import subprocess
import sys

# Change the below to your url and search string
url = "http://svn.apache.org/repos/asf/spamassassin/trunk"
search_term = "160"

# Run the svn log command and get the results as xml
args = ["svn", "log",'--search="{0}"'.format(search_term), url, "--xml"]
svn_out = subprocess.check_output(" ".join(args))
svn_xml = ET.fromstring(svn_out)

try:
    # Get the latest log by revision number
    latest_log = max(svn_xml, key=lambda x : int(x.attrib["revision"]))
except ValueError:
    sys.exit("No Results Found")  # Empty svn_xml would indicate no results.

# Print log author and message
author = latest_log.find("author").text
msg = latest_log.find("msg").text
print "{0} : {1}".format(author, msg)

Which returns for me using python 2.7 in Windows:

python .\svn_redemption.py
spamassassin_role : updated scores for revision 1607021 active rules added since last mass-check

Basically it gets the xml results from the the command line output, then gets the highest revision as the result.

You'll need to change the url and the search_term variables to the ones you want, but it should work.

Sign up to request clarification or add additional context in comments.

2 Comments

It is not able to find anything. svn log --search="0072" <SVN-URL> gives 3 set of rows in the result. But when I use svn log --search="0072" -l 1 <SVN_URL>, it doesnt return any row.
It appears that -l 1 option limits the search to 1 last revision. It looks useless in such case.
0

It looks like it's not possible with just svn.exe command-line client.

Unactual part below, see updated @Noelkd's answer!

@Noelkd's answer is not correct, as far as I can see now. Using -l 1 option limits the search query's range, not the output it produces.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.