ReactOS  0.4.14-dev-999-g61c8d34
revision.c
Go to the documentation of this file.
1 /*
2  * ReactOS log2lines
3  * Written by Jan Roeloffzen
4  *
5  * - SVN interface and revision analysis
6  */
7 
8 #include <stdio.h>
9 #include <string.h>
10 #include <stdlib.h>
11 
12 #include "version.h"
13 #include "compat.h"
14 #include "util.h"
15 #include "options.h"
16 #include "log2lines.h"
17 
18 static void
19 log_rev_check(FILE *outFile, char *fileName, int showfile)
20 {
21  int rev = 0;
22  char s[LINESIZE];
23 
25  strcat(s, fileName);
26  rev = getRevision(s, 1);
27  if (!showfile)
28  s[0] = '\0';
29  if (revinfo.opt_verbose)
30  log(outFile, "| R--- %s Last Changed Rev: %d\n", s, rev);
31 
32  if (rev && opt_Revision_check)
33  {
35  {
37  log(outFile, "| R--- Conflict %s: source tree(%d) < build(%d)\n", s, rev, revinfo.buildrev);
38  }
39  else if (rev > revinfo.buildrev)
40  {
42  log(outFile, "| R--- Conflict %s: file(%d) > build(%d)\n", s, rev, revinfo.buildrev);
43  }
44  }
45 }
46 
47 static void
48 logRevCheck(FILE *outFile)
49 {
50  int twice = 0;
51 
52  twice = (lastLine.nr2 && strcmp(lastLine.file1, lastLine.file2) != 0);
53  log_rev_check(outFile, lastLine.file1, twice);
54  if (twice)
55  {
56  log_rev_check(outFile, lastLine.file2, twice);
57  }
58 }
59 
60 int
61 getRevision(char *fileName, int lastChanged)
62 {
63  char s[LINESIZE];
64  FILE *psvn;
65  int rev = 0;
66 
67  if (!fileName)
68  fileName = opt_SourcesPath;
69  sprintf(s, "svn info %s", fileName);
70  if ((psvn = POPEN(s, "r")))
71  {
72  while (fgets(s, LINESIZE, psvn))
73  {
74  if (lastChanged)
75  {
76  if (sscanf(s, "Last Changed Rev: %d", &rev))
77  break;
78  }
79  else
80  {
81  if (sscanf(s, "Revision: %d", &rev))
82  break;
83  }
84  }
85  }
86  else
87  l2l_dbg(1, "Can't popen: \"%s\"\n", s);
88 
89  if (psvn)
90  PCLOSE(psvn);
91 
92  return rev;
93 }
94 
95 int
96 getTBRevision(char *fileName)
97 {
98  char *s;
99  int rev = 0;
100 
101  s = strrchr(fileName, PATH_CHAR);
102  if (s)
103  s += 1;
104  else
105  s = fileName;
106 
107  sscanf(s, TRKBUILDPREFIX "%d", &rev);
108  if (!rev)
109  {
110  s = strrchr(fileName, PATH_CHAR);
111  if (s)
112  *s = '\0'; // clear, so we have the parent dir
113  else
114  {
115  // where else to look?
116  fileName = opt_SourcesPath;
117  }
118  rev = getRevision(fileName, 1);
119  if (s)
120  *s = PATH_CHAR; // restore
121  }
122 
123  l2l_dbg(1, "TBRevision: %d\n", rev);
124  return rev;
125 }
126 
127 
128 void
130 {
131  if (opt_Revision_check)
132  {
133  if (lastLine.valid)
134  logRevCheck(outFile);
135  }
136 }
137 
138 unsigned long
139 findRev(FILE *finx, int *rev)
140 {
141  unsigned long pos = 0L;
142 
143  while (!fseek(finx, (*rev) * sizeof(unsigned long), SEEK_SET))
144  {
145  fread(&pos, sizeof(long), 1, finx);
146  (*rev)--;
147  if (pos)
148  break;
149  }
150  return pos;
151 }
152 
153 int
154 regscan(FILE *outFile)
155 {
156  int res = 0;
157  char logname[PATH_MAX];
158  char inxname[PATH_MAX];
159  char line[LINESIZE + 1];
160  char line2[LINESIZE + 1];
161  FILE *flog = NULL;
162  FILE *finx = NULL;
163  unsigned long pos = 0L;
164  int r;
165 
166  sprintf(logname, "%s" PATH_STR "%s", opt_SourcesPath, SVNDB);
167  sprintf(inxname, "%s" PATH_STR "%s", opt_SourcesPath, SVNDB_INX);
168  flog = fopen(logname, "rb");
169  finx = fopen(inxname, "rb");
170 
171  if (flog && finx)
172  {
173  r = revinfo.buildrev;
174  if (!fread(&pos, sizeof(long), 1, finx))
175  {
176  res = 2;
177  l2l_dbg(0, "Cannot read magic number\n");
178  }
179 
180  if (!res)
181  {
182  if (pos != MAGIC_INX)
183  {
184  res = 3;
185  l2l_dbg(0, "Incorrect magic number (%lx)\n", pos);
186  }
187  }
188 
189  if (!res)
190  {
191  char flag[2];
192  char path[PATH_MAX];
193  char path2[PATH_MAX];
194  int wflag = 0;
195  clilog(outFile, "Regression candidates:\n");
196  while (( pos = findRev(finx, &r) ))
197  {
198  if (r < (revinfo.buildrev - revinfo.range))
199  {
200  l2l_dbg(1, "r%d is outside range of %d revisions\n", r, revinfo.range);
201  break;
202  }
203  fseek(flog, pos, SEEK_SET);
204  wflag = 1;
205  fgets(line, LINESIZE, flog);
206  fgets(line2, LINESIZE, flog);
207  while (fgets(line2, LINESIZE, flog))
208  {
209  path2[0] = '\0';
210  if (sscanf(line2, "%1s %s %s", flag, path, path2) >= 2)
211  {
213  {
214  if (wflag == 1)
215  {
216  clilog(outFile, "%sChanged paths:\n", line);
217  summ.regfound++;
218  wflag = 2;
219  }
220  clilog(outFile, "%s", line2);
221  }
222  }
223  else
224  break;
225  }
226  if (wflag == 2)
227  {
228  int i = 0;
229  clilog(outFile, "\n");
230  while (fgets(line2, LINESIZE, flog))
231  {
232  i++;
233  clilog(outFile, "%s", line2);
234  if (strncmp(LOGBOTTOM, line2, sizeof(LOGBOTTOM) - 1) == 0)
235  break;
236  }
237  }
238  }
239  }
240  }
241  else
242  {
243  res = 1;
244  l2l_dbg(0, "Cannot open %s or %s\n", logname, inxname);
245  }
246 
247  if (flog)
248  fclose(flog);
249  if (finx)
250  fclose(finx);
251 
252  return res;
253 }
254 
255 
256 int
258 {
259  int res = 0;
260  char logname[PATH_MAX];
261  char inxname[PATH_MAX];
262  char line[LINESIZE + 1];
263  FILE *flog = NULL;
264  FILE *finx = NULL;
265  unsigned long pos;
266  int r, y, m, d;
267  char name[NAMESIZE];
268 
269  sprintf(logname, "%s" PATH_STR "%s", opt_SourcesPath, SVNDB);
270  sprintf(inxname, "%s" PATH_STR "%s", opt_SourcesPath, SVNDB_INX);
271  flog = fopen(logname, "rb");
272  finx = fopen(inxname, "wb");
273 
274  if (flog && finx)
275  {
276  pos = MAGIC_INX;
277  fwrite(&pos, sizeof(long), 1, finx);
278  pos = ftell(flog);
279  while (fgets(line, LINESIZE, flog))
280  {
281  if (sscanf(line, "r%d | %s | %d-%d-%d", &r, name, &y, &m, &d) == 5)
282  {
283  l2l_dbg(1, "%ld r%d | %s | %d-%d-%d\n", pos, r, name, y, m, d);
284  fseek(finx, r * sizeof(unsigned long), SEEK_SET);
285  fwrite(&pos, sizeof(unsigned long), 1, finx);
286  }
287  pos = ftell(flog);
288  }
289  }
290 
291  if (flog)
292  fclose(flog);
293  if (finx)
294  fclose(finx);
295 
296  return res;
297 }
298 
299 /* EOF */
static const WCHAR path2[]
Definition: path.c:29
int updateSvnlog(void)
Definition: revision.c:257
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
static void logRevCheck(FILE *outFile)
Definition: revision.c:48
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define MAGIC_INX
Definition: config.h:11
#define TRKBUILDPREFIX
Definition: config.h:15
int getRevision(char *fileName, int lastChanged)
Definition: revision.c:61
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
#define PCLOSE
Definition: compat.h:22
const GLfloat * m
Definition: glext.h:10848
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define NAMESIZE
Definition: config.h:35
int opt_Revision_check
Definition: options.c:41
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
#define SVNDB_INX
Definition: config.h:9
#define l2l_dbg(level,...)
Definition: util.h:35
smooth NULL
Definition: ftsmooth.c:416
REVINFO revinfo
Definition: log2lines.c:37
_Check_return_opt_ _CRTIMP int __cdecl fseek(_Inout_ FILE *_File, _In_ long _Offset, _In_ int _Origin)
GLsizei GLenum * sources
Definition: glext.h:7753
Definition: parser.c:48
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
LINEINFO lastLine
Definition: log2lines.c:33
int revconflicts
Definition: stat.h:20
#define SEEK_SET
Definition: jmemansi.c:26
PLIST_MEMBER entry_lookup(PLIST list, char *name)
Definition: list.c:19
#define d
Definition: ke_i.h:81
static void log_rev_check(FILE *outFile, char *fileName, int showfile)
Definition: revision.c:19
int rev
Definition: sort.c:17
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
#define PATH_MAX
Definition: types.h:280
#define clilog(outFile, fmt,...)
Definition: util.h:27
int opt_verbose
Definition: revision.h:17
static const WCHAR L[]
Definition: oid.c:1250
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean flag
Definition: glfuncs.h:52
GLdouble s
Definition: gl.h:2039
char file2[LINESIZE]
Definition: log2lines.h:19
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
#define PATH_CHAR
Definition: rmkdir.c:17
#define LOGBOTTOM
Definition: config.h:7
char file1[LINESIZE]
Definition: log2lines.h:16
_Check_return_opt_ _CRTIMP char *__cdecl fgets(_Out_writes_z_(_MaxCount) char *_Buf, _In_ int _MaxCount, _Inout_ FILE *_File)
#define LINESIZE
Definition: chargen.c:18
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
unsigned long findRev(FILE *finx, int *rev)
Definition: revision.c:139
int getTBRevision(char *fileName)
Definition: revision.c:96
Definition: name.c:38
GLuint res
Definition: glext.h:9613
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
_Check_return_ _CRTIMP long __cdecl ftell(_Inout_ FILE *_File)
void reportRevision(FILE *outFile)
Definition: revision.c:129
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define SVNDB
Definition: config.h:8
SUMM summ
Definition: log2lines.c:36
int regscan(FILE *outFile)
Definition: revision.c:154
int regfound
Definition: stat.h:21
#define PATH_STR
Definition: compat.h:27
#define POPEN
Definition: compat.h:21
#define log(outFile, fmt,...)
Definition: util.h:15
char opt_SourcesPath[LINESIZE]
Definition: options.c:47