On Mon, 17 Aug 2015 18:04:37 +0200, <[email protected]> wrote:

​I read the search feature is in a trial stage.
Can it be expanded to search in actual source files?
Now using the browser and only per file. Or of course in an external tool
in my checkout folder.

Thanks for Fossil.

until the time comes where fossil supports grep out of the box I'm using the following q&d shell script. provided you are on linux/unix/macosx this should work for you (N.B.: I'm using `ksh' rather than `bash' (or `zsh'). to make it work with `bash' you'd need to replace the `print' command by `echo' or a suitable `printf' call (and find out what the equivalent of `print -r --' in bash is ... probably some similar `printf' construct). in any case you get the idea.... sure it is inefficient (dumps all revisions of the file and greps through all of them ...), but it works OK for me.

8<------------------------------------------------------------------------------------------

#!/usr/bin/env ksh
#------------------------------------------------------------------
# purpose: grep through all revisions of one or more files from a `fossil'
# repository.
#
# calling syntax:
#
#    fslgrep grep-options pattern file {file ...}
#
# where `grep-options' is passed to `grep'. options taking arguments for the
# time being must *not* contain spaces (or the whole option string must
# be enclosed in quotes).
#
# example:
#
#     fslgrep '-C 5' foo bar.txt
#
# will look for `foo' in all revisions of `bar.txt' and report them with a 5 line context.

#------------------------------------------------------------------
function getHashes { # `fossil finfo -W 0' output
   print "$1" | awk '
      NR == 1 {next}
      /^[0-9]/ {
         sha1 = substr($2, 2, length($2) - 2)
         print sha1
      }
   '
}
#------------------------------------------------------------------
# define default grep options to be used:
options="--colour=always "

# append user defined options and extract grep search pattern
for i do
   [[ $i == -* ]] && {
      options+="$i "
      ((optcnt++))
   }
done
((optcnt > 0)) && shift $optcnt
pattern=$1
shift

for i do
   timeline=$(fossil finfo -W 0 $i)
   (($? == 0)) || continue
   hashes=$(getHashes "$timeline")

   for h in $hashes; do
      rep=$(fossil cat -r $h $i | cat -n | grep $options "$pattern")
      (($? == 0)) &&  {
         print -- "\n** $i [$h] **"
         print -r -- "$rep"
      }
   done
done

8<------------------------------------------------------------------------------------------

HTH

j.
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
_______________________________________________
fossil-users mailing list
[email protected]
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users

Reply via email to