File: CvsAddAll.tcl

package info (click to toggle)
gcvs 1.0final-12
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 12,248 kB
  • ctags: 10,631
  • sloc: ansic: 71,709; cpp: 39,780; sh: 18,434; makefile: 1,915; yacc: 1,299; tcl: 1,283; perl: 910; lex: 249; csh: 185; lisp: 7
file content (115 lines) | stat: -rwxr-xr-x 3,475 bytes parent folder | download | duplicates (3)
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
#!CVSGUI1.0 --selection --name "Add All to CVS"

# cvsaddall.tcl
# This macro adds all selected files and folders to the cvs repository
# along with all the subfolders and files 

# Author: Gopalakrishnan.P (gopal@workspot.net)
# Version: 1.0

#----------------------------------------------------------------------------
# All procedures for cvsaddall.tcl
#----------------------------------------------------------------------------


set fcount 0;   # global count 

# This procedure addes the folder/file argument to cvs using cvs add 
# In case it fails we return a 1 and break from the add loop.
# We print the cvs message irrespective of the result
proc cvsadd { fname } {
 set out [catch {cvs add $fname} cval]; 
 cvsout "$cval\n"; 
 global fcount;
  if { $out != 0 } {
    return 1; 
  } else {
    incr fcount;
    return 0;
  }
}


# This procedure takes a list and for each element calls addcvs procedure.
# If any of them fails it breaks out from the loop. If any file gets added
# the count value is returned.
proc checkadd { addlist } { 
set cnt 0;
 foreach item $addlist {
   if { [cvsadd $item] } {
     break;
   } else {
     incr cnt;
   }
  }
 return $cnt;
}

# This procedure recurses the folder list and retuns a list of folders
# and files contained therin.
proc recursefolder {flist} {
set filelist {};
set foldlist {};
  if { [llength $flist] > 0 } {
    foreach item $flist {
      cvsentries $item entrydet;
        set files [ entrydet get ];
	  foreach i $files {
	    entrydet info $i farr;
              if { [string equal -nocase $farr(kind) "folder"] && \
	           $farr(missing) == 0 && $farr(unknown) == 1 } {
	        lappend foldlist $i;
              } elseif { [string equal -nocase $farr(kind) "file"] && \
	               $farr(missing) == 0 && $farr(unknown) == 1 } {
	        lappend filelist $i;
	      }
	  }
    }
  }
  return [list $foldlist $filelist]
}

# This procedure concats two lists -- a folderlist and a filelist -- and 
# invokes checkadd procedure. Based on the return value it invokes 
# recursefolder procedure recursively.
proc addfiles {list1 list2} {
  set ret [checkadd [concat $list1 $list2]]
  if { $ret > 0 } {
    set listret [recursefolder $list1]
    if { [llength [lindex $listret 0]] > 0 || [llength [lindex $listret 1]] \
                                                                   >  0 } {
      addfiles [lindex $listret 0] [lindex $listret 1];
    } else {
      return
    }
  }
}

#----------------------------------------------------------------------------
# main body of the program
#----------------------------------------------------------------------------

set dirlist {};
set filelist {};

set select [ cvsbrowser get ]; # get the selection
foreach i $select {
  cvsbrowser info $i aname;
 if { [string equal -nocase $aname(kind) "folder"] && $aname(missing) \
                                     == 0 && $aname(unknown) == 1 } {
   lappend dirlist $i;
 } elseif { [string equal -nocase $aname(kind) "file"] && $aname(missing) \
                                         == 0 && $aname(unknown) == 1 } {
   lappend filelist $i;
 } 
}

# All unknown files and folders are available in the filelist and dirlist
# add them to cvs using addfiles procedure.

addfiles $dirlist $filelist;

# Print out the total count of folders/files added.
cvsout "\n($fcount) folders/files added to cvs repository\n";

#----------------------------------------------------------------------------