#!/usr/bin/env ruby # # $Id: //guest/robert_cowham/perforce/utils/vss_rev_date_problems.rb#7 $ # # Author: Robert Cowham # Copyright (c) 2005 Robert Cowham # # =DESCRIPTION # Script to check for files in VSS where an earlier revision has a later date/time on it. # # Uses VSS OLE Automation # Documentation on VSS Object Model can be found at: # http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvss/html/msdn_vssole.asp # # Usual disclaimers apply! require 'win32ole' require 'getoptlong' # Module for constants to be loaded into module VSS_CONST end @@verbose = 0 class CheckFiles attr_reader :count, :rev_count, :err_count def initialize(vssdb) @vssdb = vssdb @count = 0 @rev_count = 0 @err_count = 0 end # Recurse down the list of VSS directories looking for files def vss_dir_tree(dir) begin root = @vssdb.VSSItem(dir, 1) @deleted_dirs_count += 1 # print "\'#{dir}\'\n" rescue begin root = @vssdb.VSSItem(dir, 0) rescue # print "Problem with '#{dir}'\n" return end end items = root.Items(1) items.each{|item| if (item.Type == VSS_CONST::VSSITEM_PROJECT) subdir = item.Name vss_dir_tree("#{dir}/#{subdir}") else check_rev(dir, "#{dir}/#{item.Name}") end } end def get_rev(file) begin @vssdb.VSSItem(file, 1) rescue @vssdb.VSSItem(file, 0) end end def get_date(dt) # 2001/06/25 19:07:12 (date, time) = dt.split arr = date.split("/").map{|e| e.to_i} arr += time.split(":").map{|e| e.to_i} return Time.utc(*arr) end def check_rev(dir, file) @count += 1 print "Checking file #{@count}\r" if @@verbose == 1 and @count % 50 == 0 item = get_rev(file) versions = item.Versions rev_hist = Hash.new versions.each{|ver| if ver.Action !~ /^Labeled/ rev_hist[ver.VersionNumber.to_i] = ver.Date end print "#{file} #{ver.VersionNumber} #{ver.Date} #{ver.Action}\n" if @@verbose > 1 } revs = rev_hist.keys.sort @rev_count += revs.size for i in 1..revs.size-1 # if revs[i] != revs[i-1] + 1 # @err_count += 1 # print "Seq error: #{file} #{revs[i]} #{revs[i-1]}\n" # end if get_date(rev_hist[revs[i]]) < get_date(rev_hist[revs[i-1]]) @err_count += 1 print "Date Seq error: '#{file}' rev #{revs[i]} date #{rev_hist[revs[i]]}, " print "rev #{revs[i-1]} date #{rev_hist[revs[i-1]]}\n" end end end end # # Main application class # class App VERSION = "$Revision: #7 $" REVISION_DATE = "$Date: 2005/11/01 $" AUTHOR = "Robert Cowham" # # Returns a version string similar to: # <app_name>: Version: 1.2 Created on: 2002/05/08 by Jim Freeze # The version number is maintained by CVS. # The date is the last checkin date of this file. # def version "Version: #{VERSION.split[1]} Created on: " + "#{REVISION_DATE.split[1]} by #{AUTHOR}" end def initialize @debug = false # @verbose = false @user = nil @password = nil @srcsafeini = nil if 0 == ARGV.size STDERR.puts usage exit 1 end get_options rescue => err STDERR.puts err STDERR.puts usage exit 1 end # # Returns usage string # def usage <<-USAGE Usage: #{File.basename $0} -u <user> -p <password> -s <srcsafeini> [-v] file_or_dir -v|--verbose print intermediate steps to STDERR -u|--user SourceSafe user -p|--password SourceSafe password -s|--srcsafeini Full path to srcsafe.ini file USAGE end # # Processes command line arguments # def get_options opts = GetoptLong.new( [ '--verbose', '-v', GetoptLong::OPTIONAL_ARGUMENT], [ '--user', '-u', GetoptLong::REQUIRED_ARGUMENT], [ '--password', '-p', GetoptLong::REQUIRED_ARGUMENT], [ '--srcsafeini', '-s', GetoptLong::REQUIRED_ARGUMENT], [ '--help', '-h', GetoptLong::REQUIRED_ARGUMENT] ) opts.each do |opt, arg| case opt when "--verbose" if arg != "" @@verbose = arg.to_i else @@verbose = 1 end when "--user" @user = arg when "--password" @password = arg when "--srcsafeini" @srcsafeini = arg when "--help" puts usage else raise "Invalid option '#{opt}'." end end if ARGV.size != 1 puts usage raise "VSS Path argument required: [vssdir]\ne.g.\n \"\$/Project 1/subdir\"\n" end @root = ARGV[0] rescue NameError => err STDERR.puts "ERROR: #{err}" exit 1 rescue => err STDERR.puts "ERROR: #{err}" exit 1 end # # Launches the application # App.new.run # def run # Load up VSS Ole Automation vssdb = WIN32OLE.new('SourceSafe') WIN32OLE.const_load(vssdb, VSS_CONST) vssdb.Open(@srcsafeini, @user, @password) print "Checked revisions for VSS files in '#{@root}':\n" print Time.now, "\n" cf = CheckFiles.new(vssdb) cf.vss_dir_tree(@root) print "\n#{cf.err_count} file/rev errors out of #{cf.count} files, #{cf.rev_count} revs in total.\n" print Time.now, "\n" end#run end#App app = App.new.run
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#7 | 5181 | Robert Cowham | Fix redirect problem. | ||
#6 | 5180 | Robert Cowham |
Removed seq no check. Added date/time and -v to print progress. |
||
#5 | 5177 | Robert Cowham | Working and linked to docs. | ||
#4 | 5176 | Robert Cowham | Now checking dates as well. | ||
#3 | 5175 | Robert Cowham | Nearly there | ||
#2 | 5174 | Robert Cowham | Trying to work out which versions are valid! | ||
#1 | 5173 | Robert Cowham | Initial version to get moving with... | ||
//guest/robert_cowham/perforce/utils/vss_deleted_files.rb | |||||
#3 | 5172 | Robert Cowham | Tidied. | ||
#2 | 5171 | Robert Cowham | Tidied up with parameters etc. | ||
#1 | 5170 | Robert Cowham | Ruby version |