Mon, 30 Jun 2014 05:52:10 +0300
- refactor
807
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
1 | /* updaterevision.c |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
2 | * |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
3 | * Public domain. This program uses the svnversion command to get the |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
4 | * repository revision for a particular directory and writes it into |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
5 | * a header file so that it can be used as a project's build number. |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
6 | */ |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
7 | |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
8 | #define _CRT_SECURE_NO_DEPRECATE |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
9 | |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
10 | #include <stdio.h> |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
11 | #include <stdlib.h> |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
12 | #include <string.h> |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
13 | #include <ctype.h> |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
14 | #include <errno.h> |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
15 | // [BB] New #includes. |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
16 | #include <sys/stat.h> |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
17 | #include <time.h> |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
18 | |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
19 | int main(int argc, char **argv) |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
20 | { |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
21 | char *name; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
22 | char currev[64], lastrev[64], run[256], *rev; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
23 | unsigned long urev; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
24 | FILE *stream = NULL; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
25 | int gotrev = 0, needupdate = 1; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
26 | // [BB] Are we working with a SVN checkout? |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
27 | int svnCheckout = 0; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
28 | char hgdateString[64]; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
29 | time_t hgdate = 0; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
30 | char hgHash[13]; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
31 | hgHash[0] = '\0'; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
32 | |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
33 | if (argc != 3) |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
34 | { |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
35 | fprintf (stderr, "Usage: %s <repository directory> <path to svnrevision.h>\n", argv[0]); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
36 | return 1; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
37 | } |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
38 | |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
39 | // [BB] Try to figure out whether this is a SVN or a Hg checkout. |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
40 | { |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
41 | struct stat st; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
42 | char filename[1024]; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
43 | sprintf ( filename, "%s/.svn/entries", argv[1] ); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
44 | if ( stat ( filename, &st ) == 0 ) |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
45 | svnCheckout = 1; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
46 | // [BB] If stat failed we have to manually clear errno, otherwise the code below doesn't work. |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
47 | else |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
48 | errno = 0; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
49 | } |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
50 | |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
51 | // Use svnversion to get the revision number. If that fails, pretend it's |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
52 | // revision 0. Note that this requires you have the command-line svn tools installed. |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
53 | // [BB] Depending on whether this is a SVN or Hg checkout we have to use the appropriate tool. |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
54 | if ( svnCheckout ) |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
55 | sprintf (run, "svnversion -cn %s", argv[1]); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
56 | else |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
57 | sprintf (run, "hg identify -n"); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
58 | if ((name = tempnam(NULL, "svnout")) != NULL) |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
59 | { |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
60 | #ifdef __APPLE__ |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
61 | // tempnam will return errno of 2 even though it is successful for our purposes. |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
62 | errno = 0; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
63 | #endif |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
64 | if((stream = freopen(name, "w+b", stdout)) != NULL && |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
65 | system(run) == 0 && |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
66 | #ifndef __FreeBSD__ |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
67 | errno == 0 && |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
68 | #endif |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
69 | fseek(stream, 0, SEEK_SET) == 0 && |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
70 | fgets(currev, sizeof currev, stream) == currev && |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
71 | (isdigit(currev[0]) || (currev[0] == '-' && currev[1] == '1'))) |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
72 | { |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
73 | gotrev = 1; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
74 | // [BB] Find the date the revision of the working copy was created. |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
75 | if ( ( svnCheckout == 0 ) && |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
76 | ( system("hg log -r. --template \"{date|hgdate} {node|short}\"") == 0 ) && |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
77 | ( fseek(stream, strlen(currev), SEEK_SET) == 0 ) && |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
78 | ( fgets(hgdateString, sizeof ( hgdateString ), stream) == hgdateString ) ) |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
79 | { |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
80 | // [BB] Find the hash in the output and store it. |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
81 | char *p = strrchr ( hgdateString, ' ' ); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
82 | strncpy ( hgHash, p ? ( p+1 ) : "hashnotfound" , sizeof( hgHash ) - 1 ); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
83 | hgHash[ sizeof ( hgHash ) - 1 ] = '\0'; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
84 | // [BB] Extract the date from the output and store it. |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
85 | hgdate = atoi ( hgdateString ); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
86 | } |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
87 | } |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
88 | } |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
89 | if (stream != NULL) |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
90 | { |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
91 | fclose (stream); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
92 | remove (name); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
93 | } |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
94 | if (name != NULL) |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
95 | { |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
96 | free (name); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
97 | } |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
98 | |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
99 | if (!gotrev) |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
100 | { |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
101 | fprintf (stderr, "Failed to get current revision: %s\n", strerror(errno)); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
102 | strcpy (currev, "0"); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
103 | rev = currev; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
104 | } |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
105 | else |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
106 | { |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
107 | rev = strchr (currev, ':'); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
108 | if (rev == NULL) |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
109 | { |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
110 | rev = currev; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
111 | } |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
112 | else |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
113 | { |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
114 | rev += 1; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
115 | } |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
116 | } |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
117 | |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
118 | // [BB] Create date version string. |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
119 | if ( gotrev && ( svnCheckout == 0 ) ) |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
120 | { |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
121 | char *endptr; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
122 | unsigned long parsedRev = strtoul(rev, &endptr, 10); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
123 | unsigned int localChanges = ( *endptr == '+' ); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
124 | struct tm *lt = gmtime( &hgdate ); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
125 | if ( localChanges ) |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
126 | sprintf ( rev, "%d%02d%02d-%02d%02dM", lt->tm_year - 100, lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, lt->tm_min); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
127 | else |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
128 | sprintf ( rev, "%d%02d%02d-%02d%02d", lt->tm_year - 100, lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, lt->tm_min); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
129 | } |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
130 | |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
131 | stream = fopen (argv[2], "r"); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
132 | if (stream != NULL) |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
133 | { |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
134 | if (!gotrev) |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
135 | { // If we didn't get a revision but the file does exist, leave it alone. |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
136 | fprintf( stderr, "No revision found.\n" ); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
137 | fclose (stream); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
138 | return 0; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
139 | } |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
140 | // Read the revision that's in this file already. If it's the same as |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
141 | // what we've got, then we don't need to modify it and can avoid rebuilding |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
142 | // dependant files. |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
143 | if (fgets(lastrev, sizeof lastrev, stream) == lastrev) |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
144 | { |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
145 | if (lastrev[0] != '\0') |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
146 | { // Strip trailing \n |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
147 | lastrev[strlen(lastrev) - 1] = '\0'; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
148 | } |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
149 | if (strcmp(rev, lastrev + 3) == 0) |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
150 | { |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
151 | needupdate = 0; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
152 | } |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
153 | } |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
154 | fclose (stream); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
155 | } |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
156 | |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
157 | if (needupdate) |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
158 | { |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
159 | stream = fopen (argv[2], "w"); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
160 | if (stream == NULL) |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
161 | { |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
162 | return 1; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
163 | } |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
164 | // [BB] Use hgdate as revision number. |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
165 | if ( hgdate ) |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
166 | urev = hgdate; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
167 | else |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
168 | urev = strtoul(rev, NULL, 10); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
169 | fprintf (stream, |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
170 | "// %s\n" |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
171 | "//\n" |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
172 | "// This file was automatically generated by the\n" |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
173 | "// updaterevision tool. Do not edit by hand.\n" |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
174 | "\n" |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
175 | "#define SVN_REVISION_STRING \"%s\"\n" |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
176 | "#define SVN_REVISION_NUMBER %lu\n", |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
177 | rev, rev, urev); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
178 | |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
179 | // [BB] Also save the hg hash. |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
180 | if ( svnCheckout == 0 ) |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
181 | fprintf (stream, "#define HG_REVISION_HASH_STRING \"%s\"\n", hgHash); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
182 | |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
183 | fclose (stream); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
184 | fprintf (stderr, "%s updated to revision %s.\n", argv[2], rev); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
185 | } |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
186 | else |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
187 | { |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
188 | fprintf (stderr, "%s is up to date at revision %s.\n", argv[2], rev); |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
189 | } |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
190 | |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
191 | return 0; |
2a8889692c25
- transitioned from git to hg
Santeri Piippo <crimsondusk64@gmail.com>
parents:
774
diff
changeset
|
192 | } |