forked from hanaguro8/vss2git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvss2git.rb
executable file
·1618 lines (1407 loc) · 47.2 KB
/
vss2git.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# = Migration tool for VSS->Git, VSS->Hg or VSS->Bzr
#
# Author:: Hanaguro
# License:: MIT License
# Version:: 1.12
#
# Copyright (c) <2012-2014>, <Satoshi Hasegawa>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted.
#
# Requirement:
# - Windows7 or Windows XP operating system
# Windows8 or Windows VISTA may be OK (not verified).
#
# - Ruby 2.0 or 1.9.3 (32 bits)
# Ruby 1.8.7 or earlier is not supported.
#
# - Microsoft Visual Source Safe 2005 or Microsoft Visual Source Safe 6.0d
# VSS 2005: The language setting has to be English.
# VSS 6.0d: English version is necessary.
#
# - Target version control system
# The git, mercurial or bazaar has to be installed.
# Its executable path has to be added to the PATH.
#
#
require 'win32ole'
require 'getoptlong'
require 'time'
require 'json'
require 'pp'
VERSION = "1.12"
REVISION_DATE = "2015/12/06"
AUTHOR = "Hanaguro"
#------------------------------------------------------------------------------
# Utility
#---------------------------------------------------------------------------*/
module Utility
# Print header line
# "str"
# "------------------------------------------------------------------------"
#
# str:: Message
#----------------------------------------------------------------------------
def pps_header(str)
str = "\n" + str + "\n" + line
pps(str)
end
# Dump hash object (for debug)
# "key = value"
#
# str:: Hash name
# obj:: Hash object
#----------------------------------------------------------------------------
def pps_hash(str, obj)
pps_header(str)
s = ""
obj.each do |key, value|
s += " #{key}".ljust(24) + "= #{value}\n"
end
pps(s)
end
# Dump object (for debug)
#
# str:: Object name
# obj:: Object
#----------------------------------------------------------------------------
def pps_object(str, obj)
pps_header(str)
pp obj
end
# Print message to STDOUT
#
# str:: Message
#----------------------------------------------------------------------------
def pps(str)
puts "#{str}"
end
private :pps
# Seperlator line
# "------------------------------------------------------------------------"
#----------------------------------------------------------------------------
def line
"-" * 72
end
private :line
# Print processing status to STDERR when verbose != 0
# "mes1 : mes2"
#
# verbose:: verbose mode
# mes1:: 1st message
# mes2:: 2nd message
#----------------------------------------------------------------------------
def ppe_status(verbose, mes1, mes2 = "")
return if verbose == 0
s = mes1.ljust(32)
s += ": " + mes2 unless mes2 == ""
s += "\r"
STDERR.print s
end
# Print error message and exit
#
# str:: Error message
#----------------------------------------------------------------------------
def ppe_exit(str)
STDERR.print(str)
exit 1
end
# Execute windows command
#
# str:: Command string
#----------------------------------------------------------------------------
def ex(str)
puts str
%x(#{str})
end
end
#------------------------------------------------------------------------------
# MODULE: Vcs
#
# VCS (Version Control System) command module
#------------------------------------------------------------------------------
module Vcs
#-- definition of VCS oparations
ACTION_ADD = "ADD"
ACTION_BRANCH = "BRANCH"
ACTION_COMMIT = "COMMIT"
ACTION_INIT = "INIT"
ACTION_MERGE = "MERGE"
ACTION_MOVE = "MOVE"
ACTION_REMOVE = "REMOVE"
ACTION_TAG = "TAG"
#-- temporally message file name
MESSAGE_FILE = ".message"
#----------------------------------------------------------------------------
# CLASS: Git
#
# Git command class
#----------------------------------------------------------------------------
class Git
include Utility
# Create repository
#
# message:: Initial commit message
#--------------------------------------------------------------------------
def create_repository(message)
# create "master" branch
ex("git init -q")
# create .gitignore file
ex("echo *.scc>>.gitignore")
ex("echo #{MESSAGE_FILE}>>.gitignore")
# initial commit
ex("git add *")
commit("", Time.at(0), message)
end
# Clean working directory
#--------------------------------------------------------------------------
def clean_working_directory
ex("for /D %a in (*) do @if not %a==.git rd %a /s /q")
ex("for %a in (*) do @if not %a==.gitignore del %a /f")
end
# Create branch and switch to the branch
#
# branch:: Branch name
# base_branch:: Base branch name
#--------------------------------------------------------------------------
def create_branch(branch, base_branch)
switch_branch(base_branch)
ex("git branch -q #{branch}")
switch_branch(branch)
end
# Switch branch
#
# branch:: Branch name
#--------------------------------------------------------------------------
def switch_branch(branch)
ex("git checkout -q #{branch}")
end
# Add file to index
#
# file:: File name
#--------------------------------------------------------------------------
def add(file = ".")
ex("git add \"#{file}\"")
end
# Merge specified branch to current branch
#
# branch:: Branch name which you want to merge
# author:: Author
# date:: Date
# message:: Message
#--------------------------------------------------------------------------
def merge(branch, author, date, message)
ex("git merge --no-ff --no-commit -q #{branch} 2>&1 >NUL")
commit(author, date, message)
end
# Commit file
#
# author:: Author
# date:: Date
# message:: Message
# file:: File name. The "" means all files.
#--------------------------------------------------------------------------
def commit(author, date, message, file = "")
# Create message file (temporally)
message = "-" if message == ""
message_file = MESSAGE_FILE
ec = Encoding::Converter.new(Encoding.find("locale"), "utf-8")
File.open(message_file, "w") do |f|
begin
f.print(ec.convert(message))
rescue
f.print("")
end
end
# Commit
cmd = "git commit -q"
cmd << " --file=#{message_file}"
cmd << " --author=\"#{author}\"" unless author == ""
cmd << " --date=\"#{date}\"" unless date == ""
cmd << " \"#{file}\"" unless file == ""
ex(cmd)
ex("del #{message_file}")
end
# Assign tag
#
# tag:: Tag name
# author:: Author
# date:: Date
#--------------------------------------------------------------------------
def tag(tag, author, date)
ex("git tag -f \"#{tag}\"")
end
# Verify repository
#--------------------------------------------------------------------------
def verify
ex("git verify")
end
# Pack repository
#--------------------------------------------------------------------------
def pack
ex("git gc")
end
# Get latest commit information
#--------------------------------------------------------------------------
def latest_commit
log = ex("git log -n 1")
ec = Encoding::Converter.new("utf-8", Encoding.find("locale"))
ret = {}
ret[:Commit] = ec.convert(log).scan(/^commit *(.*)$/)[0][0]
ret[:Date] = Time.parse(ec.convert(log).scan(/^Date: *(.*)$/)[0][0])
ret[:Author] = ec.convert(log).scan(/^Author: *(.*)$/)[0][0]
ret
end
end # Class Git
#----------------------------------------------------------------------------
# CLASS: Hg
#
# Hg command class
# (Not verified sufficiently)
#----------------------------------------------------------------------------
class Hg
include Utility
# Create repository
#
# message:: Initial commit message
#--------------------------------------------------------------------------
def create_repository(message)
# create "master" branch
ex("hg init")
ex("hg branch master")
# create .hgignore file
ex("echo syntax: glob>>.hgignore")
ex("echo *.scc>>.hgignore")
ex("echo #{MESSAGE_FILE}>>.hgignore")
# initial commit
ex("hg add")
commit("", Time.at(0), message)
end
# Clean working directory
#--------------------------------------------------------------------------
def clean_working_directory
ex("for /D %a in (*) do @if not %a==.hg rd %a /s /q")
ex("for %a in (*) do @if not %a==.hgignore del %a /f")
end
# Create branch and switch to the branch
#
# branch:: Branch name
# base_branch:: Base branch name
#--------------------------------------------------------------------------
def create_branch(branch, base_branch)
switch_branch(base_branch)
ex("hg branch #{branch}")
commit("", Time.at(0), "create branch")
end
# Switch branch
#
# branch:: Branch name
#--------------------------------------------------------------------------
def switch_branch(branch)
ex("hg update -C #{branch}")
end
# Add file to index
#
# file:: File name
#--------------------------------------------------------------------------
def add(file = ".")
ex("hg add \"#{file}\"")
end
# Merge specified branch to current branch
#
# branch:: Branch name which you want to merge
# author:: Author
# date:: Date
# message:: Message
#--------------------------------------------------------------------------
def merge(branch, author, date, message)
ex("hg merge #{branch}")
commit(author, date, message)
end
# Commit the file
#
# author:: Author
# date:: Date
# message:: Message
# file:: File name. The "" means all files.
#--------------------------------------------------------------------------
def commit(author, date, message, file = "")
# Create message file (temporally)
message = "-" if message == ""
message_file = MESSAGE_FILE
File.open(message_file, "w") do |f|
begin
f.print(message)
rescue
f.print("")
end
end
# Commit
cmd = "hg commit"
cmd << " --logfile #{message_file}"
cmd << " --user \"#{author}\"" unless author == ""
cmd << " --date \"#{date}\"" unless date == ""
cmd << " \"#{file}\"" unless file == ""
ex(cmd)
ex("del #{message_file}")
end
# Assign tag
#
# tag:: Tag name
# author:: Author
# date:: Date
#--------------------------------------------------------------------------
def tag(tag, author, date)
cmd = "hg tag -f"
cmd << " --user \"#{author}\"" unless author == ""
cmd << " --date \"#{date}\"" unless date == ""
cmd << " \"#{tag}\""
ex(cmd)
end
# Verify repository
#--------------------------------------------------------------------------
def verify
ex("hg verify")
end
# Pack repository
#--------------------------------------------------------------------------
def pack
end
# Get latest commit information
#--------------------------------------------------------------------------
def latest_commit
log = ex("set LC_ALL=en&hg log -l 1")
ret = {}
ret[:Commit] = log.scan(/^changeset: *(.*)$/)[0][0]
ret[:Date] = Time.parse(log.scan(/^date: *(.*)$/)[0][0])
ret[:Author] = log.scan(/^user: *(.*)$/)[0][0]
ret
end
end # Class Hg
#----------------------------------------------------------------------------
# CLASS: Bzr
#
# Bazaar command class
# (Not verified sufficiently)
#----------------------------------------------------------------------------
class Bzr
include Utility
# Initialize instance
#--------------------------------------------------------------------------
def initialize
@basedir = Dir.pwd
end
# Create repository
#
# message:: Initial commit message
#--------------------------------------------------------------------------
def create_repository(message)
# create "master" branch
ex("bzr init-repo .")
ex("bzr config add.maximum_file_size=50000000")
ex("md master")
switch_branch("master")
ex("bzr init")
# create .gitignore file
ex("bzr ignore *.scc")
# initial commit
ex("bzr add *")
commit("", Time.at(0), message)
end
# Clean working directory
#--------------------------------------------------------------------------
def clean_working_directory
ex("for /D %a in (*) do @if not %a==.bzr rd %a /s /q")
ex("for %a in (*) do @if not %a==.bzrignore del %a /f")
end
# Create branch and switch to the branch
#
# branch:: Branch name
# base_branch:: Base branch name
#--------------------------------------------------------------------------
def create_branch(branch, base_branch)
switch_branch(@basedir)
ex("bzr branch #{base_branch} #{branch}")
switch_branch(branch)
end
# Switch branch
#
# branch:: Branch name
#--------------------------------------------------------------------------
def switch_branch(branch)
Dir.chdir(@basedir)
Dir.chdir(branch)
end
# Add file to index
#
# file:: File name
#--------------------------------------------------------------------------
def add(file = "")
cmd = "bzr add"
cmd << " \"#{file}\"" unless file == ""
ex(cmd)
end
# Merge specified branch to current branch
#
# branch:: Branch name which you want to merge
# author:: Author
# date:: Date
# message:: Message
#--------------------------------------------------------------------------
def merge(branch, author, date, message)
ex("bzr merge ..\\#{branch}")
commit(author, date, message)
end
# Commit the file
#
# author:: Author
# date:: Date
# message:: Message
# file:: File name. The "" means all files.
#--------------------------------------------------------------------------
def commit(author, date, message, file = "")
# Create message file (temporally)
message = "-" if message == ""
message_file = "..\\#{MESSAGE_FILE}"
File.open(message_file, "w") do |f|
begin
f.print(message)
rescue
ppe_exit "ERROR: Bzr.commit: Cannot open file: #{message_file}"
end
end
# Commit
cmd = "bzr commit -q"
cmd << " --file=#{message_file}"
cmd << " --author=\"#{author}\"" unless author == ""
cmd << " --commit-time=\"#{date}\"" unless date == ""
cmd << " \"#{file}\"" unless file == ""
ex(cmd)
ex("del #{message_file}")
end
# Assign tag
#
# tag:: Tag name
# author:: Author
# date:: Date
#--------------------------------------------------------------------------
def tag(tag, author, date)
ex("bzr tag --force \"#{tag}\"")
end
# Verify repository
#--------------------------------------------------------------------------
def verify
ex("bzr check")
end
# Pack repository
#--------------------------------------------------------------------------
def pack
ex("bzr pack")
end
# Get latest commit information
#--------------------------------------------------------------------------
def latest_commit
log = ex("bzr log -r-1")
ret = {}
ret[:Commit] = log.scan(/^revno: *(.*)$/)[0][0]
ret[:Date] = Time.parse(log.scan(/^timestamp: *(.*)$/)[0][0])
ret[:Author] = log.scan(/^author: *(.*)$/)[0][0]
ret
end
end # Class Bzr
end # Module Vcs
#------------------------------------------------------------------------------
# CLASS: Vss
#
# VSS (Visual Source Safe) operation class
#
# This class operates Visual Source Safe via Win32OLE interface.
#------------------------------------------------------------------------------
class VssError < StandardError; end
class Vss
include Utility
# VSS constant
module VssConstant
end
# VSS actions
VSS_ACTION = [
{ String: /added/, Action: :Added },
{ String: /archived versions of/, Action: :ArchivedVersionsOf },
{ String: /archived/, Action: :Archived },
{ String: /branched at version/, Action: :BranchedAtVersion },
{ String: /checked in/, Action: :CheckedIn },
{ String: /created/, Action: :Created },
{ String: /deleted/, Action: :Deleted },
{ String: /destroyed/, Action: :Destroyed },
{ String: /labeled/, Action: :Labeled },
{ String: /moved from/, Action: :MovedFrom },
{ String: /moved to/, Action: :MovedTo },
{ String: /pinned to version/, Action: :PinnedToVersion },
{ String: /purged/, Action: :Purged },
{ String: /recovered/, Action: :Recovered },
{ String: /renamed to/, Action: :RenamedTo },
{ String: /restored/, Action: :Restored },
{ String: /rollback to version/, Action: :RollbackToVersion },
{ String: /shared/, Action: :Shared },
{ String: /unpinned/, Action: :Unpinned },
{ String: /.*/, Action: :Other }]
# Initialize Vss instance
#
# vssdir:: VSS database directory
# user:: VSS user name
# password:: VSS pasword
# project:: Project name
# workdir:: Working directory
# verbose:: Verbose mode
#--------------------------------------------------------------------------
def initialize(vssdir, user, password, project, workingdir, verbose)
@project = project
@workingdir = workingdir
@verbose = verbose
@history = []
# open VSS db
begin
@vssdb = WIN32OLE.new("SourceSafe")
WIN32OLE.const_load(@vssdb, VssConstant)
rescue
raise VssError,
%(\nERROR: Visual Source Safe is not installed.)
end
# validation of srcsafe.ini
file = vssdir + "srcsafe.ini"
unless FileTest.exist?(file)
raise VssError,
%(\nERROR: Invalid VSS database folder: #{file})
end
begin
@vssdb.Open(file, user, password)
rescue
raise VssError,
%(\nERROR: Invalid user name or password)
end
# The GetSetting() is only available on VSS 2005.
# VSS 6.0 does not have the GetSetting().
begin
if @vssdb.GetSetting("Force_Dir") == "Yes"
raise VssError,
%(\nERROR: VSS setting error.) +
%(\n "Assume working folder based on current project" should be off.) +
%(\n "Tools" -> "Options" -> "Command Line Options" tab)
end
if @vssdb.GetSetting("Force_Prj") == "Yes"
raise VssError,
%(\nERROR: VSS setting error.) +
%(\n "Assume project based on working folder" should be off.) +
%(\n "Tools" -> "Options" -> "Command Line Options" tab)
end
rescue
pps "VSS version may be 6.0"
pps "Skip validation of the 'Force_Dir' and 'Force_Prj' settings."
end
end
# Analyze
#
# Analyze VSS and get history
#----------------------------------------------------------------------------
def analyze
@counter = { File: 0 }
files = get_filelist(@project)
files.each_with_index do |file, i|
item = get_item(file)
next unless item
@history += get_history_of_the_file(file, item)
ppe_status(
@verbose,
"Get history ...",
"#{i + 1} / #{files.size} files")
end
ppe_status(@verbose, "\n")
pps_object("history generated by get_history", @history) if @verbose >= 2
end
# Get history
#----------------------------------------------------------------------------
def get_history
@history
end
# Get VSS information
#
# history:: History of VSS
#----------------------------------------------------------------------------
def get_vssinfo(history)
vssinfo = {}
VSS_ACTION.each do |act|
vssinfo[act[:Action]] = 0
end
history.each do |h|
vssinfo[h[:Action]] += 1
end
vssinfo
end
# Get users
#
# history:: History of VSS
#----------------------------------------------------------------------------
def get_users(history)
users = []
history.each do |h|
users << h[:Author] unless users.include?(h[:Author])
end
users
end
# Get file list
#
# project:: Project folder name (Ex. $/, $/project etc.)
#----------------------------------------------------------------------------
def get_filelist(project)
files = walk_tree(project).uniq.sort
ppe_status(@verbose, "Make file list ...", "#{files.size} files\n")
files
end
private :get_filelist
# Walk VSS project tree to get file list
#
# project:: Project folder name (Ex. $/, $/project etc.)
#----------------------------------------------------------------------------
def walk_tree(project)
files = []
root = get_item(project)
return files unless root
items = root.Items(false)
items.each do |item|
pps_item(item)
if item.Type == VssConstant::VSSITEM_PROJECT
subproject = item.Name
files += walk_tree("#{project}#{subproject}/")
ppe_status(
@verbose, "Meke file list ...", "#{@counter[:File]} files")
else
@counter[:File] += 1
files << item.Spec
end
end
files
end
private :walk_tree
# Get IVSSItem object
#
# file:: File name or project folder name
#----------------------------------------------------------------------------
def get_item(file)
begin
@vssdb.VSSItem(file, false)
rescue
message = "WARNING: Cannot handle the file: #{file}"
puts message
ppe_status(@verbose, message + "\n")
nil
end
end
private :get_item
# Get history of the file
#
# file:: File name
# item:: VSSItem object
#----------------------------------------------------------------------------
def get_history_of_the_file(file, item)
history = []
versions = item.Versions
versions.each do |ver|
pps_version(file, ver)
hs = {}
hs[:File] = file
hs[:Version] = ver.VersionNumber
hs[:Author] = ver.Username.downcase
hs[:Date] = ver.Date
hs[:Message] = ver.Comment.gsub(/[\r\n][\r\n]/, "\n").chomp
hs[:Tag] = ver.Label.chomp
hs[:LatestVersion] = (item.VersionNumber == hs[:Version])
pps ver.Action if @verbose >= 2
action = VSS_ACTION.find do |act|
ver.Action.downcase =~ act[:String]
end
hs[:Action] = action[:Action]
history << hs
end
history
end
private :get_history_of_the_file
# Get file
#
# file:: File name or project folder name
# version:: Version number.
# If version is nil, the latest version of file is got.
#----------------------------------------------------------------------------
def get_file(file, version)
item = get_item(file)
return unless item
item = item.Version(version) if version
fail "item.Version() return nil" unless item
# VSSFLAG setting
flag = VssConstant::VSSFLAG_CMPFAIL |
VssConstant::VSSFLAG_FORCEDIRNO |
VssConstant::VSSFLAG_RECURSYES |
VssConstant::VSSFLAG_REPREPLACE
# build local path name
lpath = file.gsub(/[^\/]*$/, "").gsub(@project, "")
lpath = @workingdir + lpath.gsub(/\//, "\\")
lpath.gsub!(/\\$/, "")
case item.Type
when VssConstant::VSSITEM_PROJECT
lpath = ".\\" + lpath
ex("if not exist #{lpath} md #{lpath}")
when VssConstant::VSSITEM_FILE
lpath = ".\\" + lpath + "\\" + item.Name
end
# get file
puts "Checkout #{file}"
begin
item.Get(lpath, flag)
true
rescue
puts "WARNING: Cannot get file: #{file}: V#{version}"
false
end
end
# Dump IVSSItem object (for debug)
#
# item:: IVSSItem object
#----------------------------------------------------------------------------
def pps_item(item)
return unless @verbose >= 2
pps_header("item")
puts "item.Spec: #{item.Spec}"
puts "item.Deleted: #{item.Deleted}"
puts "item.Type: #{item.Type}"
puts "item.LocalSpec: #{item.LocalSpec}"
puts "item.Name: #{item.Name}"
puts "item.VersionNumber: #{item.VersionNumber}"
end
private :pps_item
# Dump IVSSVersion object (for debug)
#
# file:: File name
# ver:: IVSSVersion object
#----------------------------------------------------------------------------
def pps_version(file, ver)
return unless @verbose >= 2
pps_header("version")
puts "file: #{file}"
puts "ver.VersionNumber: #{ver.VersionNumber}"
puts "ver.Action: #{ver.Action}"
puts "ver.Date: #{ver.Date}"
puts "ver.Username: #{ver.Username}"
puts "ver.Comment: #{ver.Comment}"
puts "ver.Label: #{ver.Label}"
end
private :pps_version
end # Class Vss
#------------------------------------------------------------------------------
# CLASS: Vss2xxx
#
# Migrate from VSS to Git, Hg or Bzr
#------------------------------------------------------------------------------
class Vss2xxx
include Vcs
include Utility
#-- Each commit in the following time range are assumed to a same changeset.
VSS_CHANGESET_RANGE_1 = 600 # sec # When same author & same message
VSS_CHANGESET_RANGE_2 = 120 # sec # When same author & no message
#-- definition of VCS oparations
ACTION_ADD = "ADD"
ACTION_BRANCH = "BRANCH"
ACTION_COMMIT = "COMMIT"
ACTION_INIT = "INIT"
ACTION_MERGE = "MERGE"
ACTION_MOVE = "MOVE"
ACTION_REMOVE = "REMOVE"
ACTION_TAG = "TAG"
#-- definition of branch name
MASTER_BRANCH = "master"
PRODUCT_BRANCH = "product"
DEVELOP_BRANCH = "develop"
#-- VCS actions
ACTION = [
{ Vss: :Added, Vcs: nil },
{ Vss: :ArchivedVersionsOf, Vcs: ACTION_ADD },
{ Vss: :Archived, Vcs: nil },
{ Vss: :BranchedAtVersion, Vcs: nil },
{ Vss: :CheckedIn, Vcs: ACTION_ADD },
{ Vss: :Created, Vcs: ACTION_ADD },
{ Vss: :Deleted, Vcs: nil },
{ Vss: :Destroyed, Vcs: nil },
{ Vss: :Labeled, Vcs: ACTION_TAG },
{ Vss: :MovedFrom, Vcs: nil },
{ Vss: :MovedTo, Vcs: nil },
{ Vss: :PinnedToVersion, Vcs: nil },
{ Vss: :Purged, Vcs: nil },
{ Vss: :Recovered, Vcs: nil },
{ Vss: :RenamedTo, Vcs: nil },
{ Vss: :Restored, Vcs: nil },
{ Vss: :RollbackToVersion, Vcs: nil },
{ Vss: :Shared, Vcs: nil },
{ Vss: :Unpinned, Vcs: nil },
{ Vss: :Other, Vcs: "OTHER" }]
#-- Run mode
RUNMODE_ANALYZE = 0
RUNMODE_FULL_MIGRATION = 1
RUNMODE_CONTINUOUS_MIGRATION = 2
# Initialize instance
#
# opt:: command line option
# [:Runmode] Run mode
# [:Vssdir] VSS repository folder
# [:User] VSS user account
# [:Password] VSS password
# [:Project] VSS project foler
# [:Vcs] Target VCS ("git", "hg" or "bzr")
# [:Emaildomain] E-mail domain address.
# [:Userlist] User list to convert user name from VSS to VCS
# [:Branch] Branching model
# [:Verbose] Verbose mode
# [:Timeshift] Time shift value when migrating
# [:Workingdir] Working folder
# [:Version] Version number of this script
#----------------------------------------------------------------------------
def initialize(opt)
@runmode = opt[:Runmode]
@vssdir = opt[:Vssdir]
@user = opt[:User]
@password = opt[:Password]
@project = opt[:Project]