Annotation of CVSROOT/record_lastdir.rb, revision 1.1

1.1     ! uid12904    1: #!/usr/bin/ruby -w
        !             2: 
        !             3: # Part of CVSspam
        !             4: #   http://www.badgers-in-foil.co.uk/projects/cvsspam/
        !             5: # Copyright (c) David Holroyd
        !             6: 
        !             7: $repositorydir = ARGV.shift
        !             8: 
        !             9: $tmpdir = ENV["TMPDIR"] || "/tmp"
        !            10: 
        !            11: # try to pick a name to avoid collisions with other people's commits
        !            12: $dirtemplate = "#cvsspam.#{Process.getpgrp}.#{Process.uid}"
        !            13: 
        !            14: def find_data_dir
        !            15:   Dir["#{$tmpdir}/#{$dirtemplate}-*"].each do |dir|
        !            16:     stat = File.stat(dir)
        !            17:     return dir if stat.owned?
        !            18:   end
        !            19:   nil
        !            20: end
        !            21: 
        !            22: $datadir = find_data_dir()
        !            23: 
        !            24: if $datadir==nil
        !            25:   $datadir = "#{$tmpdir}/#{$dirtemplate}-#{rand(99999999)}"
        !            26:   Dir.mkdir($datadir, 0700)
        !            27: end
        !            28: 
        !            29: $tags = nil
        !            30: #raise "Created data dir #{$datadir}" 
        !            31: #
        !            32: # Record any tag name found in 'Entries' for files being commited.  This is
        !            33: # required at pre-commit-time as we have no other way of dertermining what
        !            34: # branch a file was on if it's been removed.
        !            35: #
        !            36: # If the commitinfo-tags file exists from a previous, unsuccessful commit,
        !            37: # then it's possible for it to contain multiple entries for a particular file.
        !            38: # The consumer of commitinfo-tags must take care to only use the last entry
        !            39: # for a given filename.
        !            40: 
        !            41: def write_tag(name, file)
        !            42:   if $tags.nil?
        !            43:     $tags = File.new("#{$datadir}/commitinfo-tags", File::WRONLY|File::CREAT|File::APPEND);
        !            44:     return if $tags.nil?
        !            45:   end
        !            46:   $tags.puts("#{name}\t#{file}")
        !            47: end
        !            48: 
        !            49: File.open("CVS/Entries") do |file|
        !            50:   file.each_line do |line|
        !            51:     next if line =~ /^D/
        !            52:     info = line.split(/\//)
        !            53:     # skip entries not commited this invocation,
        !            54:     if ARGV.delete(info[1]).nil?
        !            55:       next
        !            56:     end
        !            57:     if info[5] =~ /^T(.+)/
        !            58:       write_tag($1, "#{$repositorydir}/#{info[1]}")
        !            59:     end
        !            60:   end
        !            61: end
        !            62: 
        !            63: $tags.close unless $tags.nil?
        !            64: 
        !            65: unless ARGV.empty?
        !            66:   $stderr.puts "Nothing in CVS/Entries for "+ARGV.join(", ")
        !            67: end
        !            68: 
        !            69: 
        !            70: # Record the directory currently being commited to.
        !            71: # 
        !            72: # This script (and collect_diffs.rb) will be run just for the files in a
        !            73: # single directory.
        !            74: # 
        !            75: # A commit to files in multiple directories will therefore produce multiple
        !            76: # invocations of these scripts.  To send the email only when the whole commit
        !            77: # is done, each run overwrites the 'lastdir' file; collect_diffs.rb will
        !            78: # later inspect the value it contains to work out if it needs to generate the
        !            79: # email yet.
        !            80: 
        !            81: File.open("#{$datadir}/lastdir", "w") { |file|
        !            82:        file.write $repositorydir
        !            83: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>