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);
73 printf("export GIT_AUTHOR_NAME=%s\n", author_name);
74 printf("export GIT_AUTHOR_EMAIL=%s\n", author_email);
76 printf("export GIT_AUTHOR_DATE='%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);
85 printf("git-read-tree -m HEAD || exit 1\n");
86 printf("git-checkout-cache -f -u -a\n");
89 static void commit(void)
91 const char *cmit_parent = initial_commit ? "" : "-p HEAD";
92 const char *dst_branch;
94 printf("tree=$(git-write-tree)\n");
95 printf("cat > .cmitmsg <<EOFMSG\n%s\nEOFMSG\n", log);
96 printf("commit=$(cat .cmitmsg | git-commit-tree $tree %s)\n", cmit_parent);
99 if (!strcmp(dst_branch, "HEAD"))
100 dst_branch = "master";
102 printf("echo $commit > .git/refs/heads/'%s'\n", dst_branch);
114 static void get_rcs_name(char *rcspathname, char *name, char *dir)
116 sprintf(rcspathname, "%s/%s,v", rcsdir, name);
117 if (!access(rcspathname, R_OK))
120 sprintf(rcspathname, "%s/Attic/%s,v", rcsdir, name);
121 if (!access(rcspathname, R_OK))
125 sprintf(rcspathname, "%s/%.*s/Attic/%s,v", rcsdir, (int)(dir - name), name, dir+1);
126 if (!access(rcspathname, R_OK))
129 fprintf(stderr, "Unable to find RCS file for %s\n", name);
133 static void update_file(char *line)
135 static char rcspathname[4096];
136 char *name, *version;
139 while (isspace(*line))
142 line = strchr(line, ':');
146 line = strchr(line, '>');
151 line = strchr(line, '(');
152 if (line) { /* "(DEAD)" */
153 printf("git-update-cache --force-remove '%s'\n", name);
157 dir = strrchr(name, '/');
159 printf("mkdir -p %.*s\n", (int)(dir - name), name);
161 get_rcs_name(rcspathname, name, dir);
163 printf("co -q -p -r%s '%s' > '%s'\n", version, rcspathname, name);
164 printf("git-update-cache --add -- '%s'\n", name);
172 { "Author:", author },
173 { "Branch:", branch },
174 { "Ancestor branch:", ancestor },
180 int main(int argc, char **argv)
182 static char line[1000];
183 enum state state = Header;
185 rcsdir = getenv("RCSDIR");
187 fprintf(stderr, "I need an $RCSDIR\n");
191 printf("[ -d .git ] && exit 1\n");
192 printf("git-init-db\n");
193 printf("mkdir -p .git/refs/heads\n");
194 printf("mkdir -p .git/refs/tags\n");
195 printf("ln -sf refs/heads/master .git/HEAD\n");
197 while (fgets(line, sizeof(line), stdin) != NULL) {
198 int linelen = strlen(line);
200 while (linelen && isspace(line[linelen-1]))
204 struct hdrentry *entry;
208 printf("# H: %s\n", line);
209 for (entry = hdrs ; entry->name ; entry++) {
210 int len = strlen(entry->name);
213 if (memcmp(entry->name, line, len))
221 while (isspace(*val)) {
225 memcpy(entry->dest, val, linelen+1);
232 printf("# L: %s\n", line);
233 if (!strcmp(line, "Members:")) {
234 while (loglen && isspace(log[loglen-1]))
241 if (loglen + linelen + 5 > sizeof(log))
243 memcpy(log + loglen, line, linelen);
245 log[loglen++] = '\n';
250 printf("# M: %s\n", line);