4 * Copyright (C) Linus Torvalds 2005
13 static int verbose = 0;
16 * This is a really stupid program that takes cvsps output, and
17 * generates a a long _shell_script_ that will create the GIT archive
20 * You've been warned. I told you it was stupid.
22 * NOTE NOTE NOTE! In order to do branches correctly, this needs
23 * the fixed cvsps that has the "Ancestor branch" tag output.
24 * Hopefully David Mansfield will update his distribution soon
25 * enough (he's the one who wrote the patch, so at least we don't
26 * have to figt maintainer issues ;)
36 static char date[100];
37 static char author[100];
38 static char branch[100];
39 static char ancestor[100];
41 static char log[32768];
42 static int loglen = 0;
43 static int initial_commit = 1;
45 static void lookup_author(char *n, char **name, char **email)
48 * FIXME!!! I'm lazy and stupid.
50 * This could be something like
52 * printf("lookup_author '%s'\n", n);
53 * *name = "$author_name";
54 * *email = "$author_email";
56 * and that would allow the script to do its own
57 * lookups at run-time.
63 static void prepare_commit(void)
65 char *author_name, *author_email;
68 lookup_author(author, &author_name, &author_email);
70 printf("export GIT_COMMITTER_NAME=%s\n", author_name);
71 printf("export GIT_COMMITTER_EMAIL=%s\n", author_email);
72 printf("export GIT_COMMITTER_DATE='+0000 %s'\n", date);
74 printf("export GIT_AUTHOR_NAME=%s\n", author_name);
75 printf("export GIT_AUTHOR_EMAIL=%s\n", author_email);
76 printf("export GIT_AUTHOR_DATE='+0000 %s'\n", date);
81 src_branch = *ancestor ? ancestor : branch;
82 if (!strcmp(src_branch, "HEAD"))
83 src_branch = "master";
84 printf("ln -sf refs/heads/'%s' .git/HEAD\n", src_branch);
87 * Even if cvsps claims an ancestor, we'll let the new
88 * branch name take precedence if it already exists
92 if (!strcmp(src_branch, "HEAD"))
93 src_branch = "master";
94 printf("[ -e .git/refs/heads/'%s' ] && ln -sf refs/heads/'%s' .git/HEAD\n",
95 src_branch, src_branch);
98 printf("git-read-tree -m HEAD || exit 1\n");
99 printf("git-checkout-cache -f -u -a\n");
102 static void commit(void)
104 const char *cmit_parent = initial_commit ? "" : "-p HEAD";
105 const char *dst_branch;
108 printf("tree=$(git-write-tree)\n");
109 printf("cat > .cmitmsg <<EOFMSG\n");
111 /* Escape $ characters, and remove control characters */
112 for (i = 0; i < loglen; i++) {
113 unsigned char c = log[i];
122 if (c == '\n' || c == '\t')
129 printf("\nEOFMSG\n");
130 printf("commit=$(cat .cmitmsg | git-commit-tree $tree %s)\n", cmit_parent);
133 if (!strcmp(dst_branch, "HEAD"))
134 dst_branch = "master";
136 printf("echo $commit > .git/refs/heads/'%s'\n", dst_branch);
138 printf("echo 'Committed (to %s):' ; cat .cmitmsg; echo\n", dst_branch);
150 static void get_rcs_name(char *rcspathname, char *name, char *dir)
152 sprintf(rcspathname, "%s/%s,v", rcsdir, name);
153 if (!access(rcspathname, R_OK))
156 sprintf(rcspathname, "%s/Attic/%s,v", rcsdir, name);
157 if (!access(rcspathname, R_OK))
161 sprintf(rcspathname, "%s/%.*s/Attic/%s,v", rcsdir, (int)(dir - name), name, dir+1);
162 if (!access(rcspathname, R_OK))
165 fprintf(stderr, "Unable to find RCS file for %s\n", name);
169 static void update_file(char *line)
171 static char rcspathname[4096];
172 char *name, *version;
175 while (isspace(*line))
178 line = strchr(line, ':');
182 line = strchr(line, '>');
187 line = strchr(line, '(');
188 if (line) { /* "(DEAD)" */
189 printf("git-update-cache --force-remove '%s'\n", name);
193 dir = strrchr(name, '/');
195 printf("mkdir -p %.*s\n", (int)(dir - name), name);
197 get_rcs_name(rcspathname, name, dir);
199 printf("co -q -p -r%s '%s' > '%s'\n", version, rcspathname, name);
200 printf("git-update-cache --add -- '%s'\n", name);
208 { "Author:", author },
209 { "Branch:", branch },
210 { "Ancestor branch:", ancestor },
216 int main(int argc, char **argv)
218 static char line[1000];
219 enum state state = Header;
221 rcsdir = getenv("RCSDIR");
223 fprintf(stderr, "I need an $RCSDIR\n");
227 printf("[ -d .git ] && exit 1\n");
228 printf("git-init-db\n");
229 printf("mkdir -p .git/refs/heads\n");
230 printf("mkdir -p .git/refs/tags\n");
231 printf("ln -sf refs/heads/master .git/HEAD\n");
233 while (fgets(line, sizeof(line), stdin) != NULL) {
234 int linelen = strlen(line);
236 while (linelen && isspace(line[linelen-1]))
240 struct hdrentry *entry;
244 printf("# H: %s\n", line);
245 for (entry = hdrs ; entry->name ; entry++) {
246 int len = strlen(entry->name);
249 if (memcmp(entry->name, line, len))
257 while (isspace(*val)) {
261 memcpy(entry->dest, val, linelen+1);
268 printf("# L: %s\n", line);
269 if (!strcmp(line, "Members:")) {
270 while (loglen && isspace(log[loglen-1]))
277 if (loglen + linelen + 5 > sizeof(log))
279 memcpy(log + loglen, line, linelen);
281 log[loglen++] = '\n';
286 printf("# M: %s\n", line);