Whamcloud - gitweb
LU-2275 mdt: Avoid setting positive dispositions too early
[fs/lustre-release.git] / lustre / scripts / version_tag-cvs.pl
1 use Time::Local;
2
3 my ($last_mtime, $pristine);
4
5 # for CVS, the buildid is that old "latest mtime" process
6 sub get_buildid()
7 {
8
9     return mtime2date($last_mtime);
10
11 }
12
13 # Use the CVS tag first otherwise use the portals version
14 sub get_tag()
15 {
16
17     my $tag;
18     my $line;
19
20     my $tagfile = new IO::File;
21     if (!$tagfile->open("lustre/CVS/Tag")) {
22         my $verfile = new IO::File;
23         if (!$verfile->open("config.h")) {
24           return "UNKNOWN";
25         }
26         while(defined($line = <$verfile>)) {
27             $line =~ /\#define VERSION "(.*)"/;
28             if ($1) {
29                 $tag = $1;
30                 last;
31             }
32         }
33         $verfile->close();
34         return $tag
35     } else {
36         my $tmp = <$tagfile>;
37         $tagfile->close();
38
39         $tmp =~ m/[TN](.*)/;
40         return $1;
41     }
42
43 }
44
45 sub get_latest_mtime()
46 {
47
48     my %months=("Jan" => 0, "Feb" => 1, "Mar" => 2, "Apr" => 3, "May" => 4,
49                 "Jun" => 5, "Jul" => 6, "Aug" => 7, "Sep" => 8, "Oct" => 9,
50                 "Nov" => 10, "Dec" => 11);
51
52     my $last_mtime = 0;
53     my $pristine = 1;
54
55     # if we got here, we are operating in a CVS checkout
56     my @entries = `find . -name Entries`;
57     my $entry_file;
58     foreach $entry_file (@entries) {
59         chomp($entry_file);
60         my $entry = new IO::File;
61         if (!$entry->open($entry_file)) {
62             die "unable to open $entry_file: $!\n";
63         }
64         my $line;
65         while (defined($line = <$entry>)) {
66             chomp($line);
67             #print "line: $line\n";
68             my ($junk, $file, $version, $date) = split(/\//, $line);
69
70             #print "junk: $junk\nfile: $file\nver: $version\ndate: $date\n";
71             #print "last_mtime: " . localtime($last_mtime) . "\n";
72
73             if ($junk eq "D" ||
74                 $file eq "lustre.spec.in") {
75                 # also used to skip: "$file !~ m/\.(c|h|am|in)$/" but I see
76                 # no good reason why only the above file patterns should
77                 # count towards pristine/changed.  it should be any file,
78                 # surely.
79                 next;
80             }
81
82             my $cur_dir = $entry_file;
83             $cur_dir =~ s/\/CVS\/Entries$//;
84             my @statbuf = stat("$cur_dir/$file");
85             my $mtime = $statbuf[9];
86             if (!defined($mtime)) {
87                 die "unable to get mtime of $cur_dir/$file: $!\n";
88             }
89             my $local_date = gmtime($mtime);
90             if ($local_date ne $date &&
91                 $file ne "lustre.spec.in") {
92                 #print "$file : " . localtime($mtime) . "\n";
93                 $pristine = 0;
94             }
95
96             if ($mtime > $last_mtime) {
97                 $last_mtime = $mtime;
98             }
99
100             if ($date) {
101                 my @t = split(/ +/, $date);
102                 if (int(@t) != 5) {
103                     #print "skipping: $date\n";
104                     next;
105                 }
106                 my ($hours, $min, $sec) = split(/:/, $t[3]);
107                 my ($mon, $mday, $year) = ($t[1], $t[2], $t[4]);
108                 my $secs = 0;
109                 $mon = $months{$mon};
110                 $secs = timelocal($sec, $min, $hours, $mday, $mon, $year);
111                 if ($secs > $last_mtime) {
112                     $last_mtime = $secs;
113                 }
114             }
115         }
116         $entry->close();
117     }
118     return $last_mtime, $pristine;
119
120 }
121
122 sub mtime2date($)
123 {
124
125     my $mtime = shift;
126
127     my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
128       localtime($mtime);
129     $year += 1900;
130     $mon++;
131     my $show_last = sprintf("%04d%02d%02d%02d%02d%02d", $year, $mon, $mday,
132                             $hour, $min, $sec);
133
134     return $show_last;
135
136 }
137
138 sub is_pristine()
139 {
140
141     return $pristine;
142
143 }
144
145 ($last_mtime, $pristine) = get_latest_mtime();
146
147 1;