7

I want to be able to search within the commit logs of svn. I know you can do that on tortoise, but couldn't find a way using the command line.

We are moving to a two-tiered repository approach, so that the stable branch will only get stories fully completed and tested. To achieve that, we would need a way to search within the commit messages for the story code (eg:#s1322) and get a list of the revisions to be used in a subsequent merge command.

Ex: searchsvnapp http://[repo location root] #s1322

result: 4233,4249,4313

Emerson
  • 935
  • 4
  • 13
  • 27

5 Answers5

9

For Subversion 1.8 The Natural Way (tm) is to use new options --search + --search-and for filtering logs

svn log --search #s1322 URL

And, BTW, each story can be separated into own branch - in this case detection of revision-range is not needed at all and you just merge branch

Lazy Badger
  • 94,711
  • 9
  • 78
  • 110
6

Wouldn't this work?

svn log | grep "something"
the_void
  • 5,512
  • 2
  • 28
  • 34
  • Most of our developers use windows and don't have much unix knowledge. It would be great if it would be a tool that could be used on any platform. – Emerson Jun 17 '10 at 16:14
  • You can install Cygwin on Windows, and use grep (among other great 'nix utilities). It's not even that messy of an install; it's self-contained, and you just put it on your path. You'll be glad you made the effort. It can be very useful. – Stephen Harmon Jun 17 '10 at 16:44
  • 1
    I use [GnuWin utils](http://gnuwin32.sourceforge.net/) for Windows environment, so OS is not an issue here. And piping several simple programs is very powerful concept that you should learn to work effectively. – chalup Jun 17 '10 at 16:50
  • I would also advise you to install `Cygwin`, but adding it to the system path may cause problems. If you don't want `Cygwin`, you could install a `svn` command line client (like `SilkSVN`) and use `find` instead of `grep`, as William pointed out. – the_void Jun 17 '10 at 16:58
  • Hmm, not sure that's fast if you've got 40K commits. – Joseph Lust Feb 25 '13 at 21:48
3

Windows version of the_void's answer:

svn log | find "something"
William Leara
  • 10,595
  • 4
  • 36
  • 58
  • I'm running XP SP3 and it's there for me. Also verified present in Vista and Win7. – William Leara Jun 24 '10 at 14:49
  • Seems this way it shows only the log content, without showing the revision number, which is what I really need... – Emerson Jun 28 '10 at 09:10
  • @Emerson perhaps if you used --xml with svn log and then ran it through some kind of xquery-grep-thing (if such a thing exists) – Jeff Dec 29 '16 at 03:48
1

First, make sure you have the Subversion command line (collabnet is the distro I use) that matches your Tortoise 'Subversion' release. Check in the Tortoise about box to find the Subversion revision. Each subversion tool has its own copy of the Subversion client, and they're not always interchangeable. Major releases will break the compatibility.

From the command line:

svn log > svn.out

Then pop it up in your favourite editor!

Kieveli
  • 10,944
  • 6
  • 56
  • 81
  • I know that you can do that, but I expected something a bit more straighforward... Anyway, I'm doing a quick webapp using svnkit to search svn for a code and returnthe right command... – Emerson Jun 28 '10 at 09:11
0

I ended up developing my own tool, using svnkit.

Further below is the main bit of the code that searches on the logs. I had to use the "SVNWCUtil.createDefaultAuthenticationManager" using a temporary folder so that it wouldn't mess with the svn configuration of a cmd line svn tool that I have in the same box that should run the tool. If there is enough interest I can make the whole webtool opensource. Please let me know (voting on the answer maybe?) if you are interested.

public Collection<SVNLogEntry> searchSVN(String url, String name,
        String password, long startRevision, long endRevision,
        String searchTerm, String svnUser) throws Exception {
    DAVRepositoryFactory.setup();
    SVNRepository repository = null;
    repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
    // changed the config folder to avoid conflicting with anthill svn use
    ISVNAuthenticationManager authManager = SVNWCUtil
            .createDefaultAuthenticationManager(new File("/tmp"), name,
                    password, false);
    repository.setAuthenticationManager(authManager);
    Collection<SVNLogEntry> resultLogEntries = new LinkedList();
    Collection<SVNLogEntry> logEntries = repository.log(
            new String[] { "" }, null, startRevision, endRevision, true,
            true);
    for (SVNLogEntry svnLogEntry : logEntries) {
        if (svnLogEntry.getMessage().indexOf(searchTerm) > -1) {
            if ((svnUser == null || svnUser.equals(""))
                    || svnLogEntry.getAuthor().equals(svnUser)) {
                resultLogEntries.add(svnLogEntry);
            }
        }
    }
    return resultLogEntries;
}
Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361
Emerson
  • 935
  • 4
  • 13
  • 27