From c5f7674a97e621bfab5544165098b4860ee6e247 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sat, 16 Jul 2005 10:05:26 -0700 Subject: [PATCH] Prepare git-tools for merging into the main git archive Rename into a "tools" subdirectory, and change name of "dotest" to "applymbox". Remove stripspace (which was already copied into git) and cvs2git (which was likewise already copied into git, and then replaced by a much better perl version). All of this was brought on by Ryan Anderson shaming me into it. Thanks. I guess. --- cvs2git.c | 307 ------------------------------- stripspace.c | 48 ----- Makefile => tools/Makefile | 4 +- dotest => tools/applymbox | 4 +- applypatch => tools/applypatch | 0 mailinfo.c => tools/mailinfo.c | 0 mailsplit.c => tools/mailsplit.c | 0 7 files changed, 5 insertions(+), 358 deletions(-) delete mode 100644 cvs2git.c delete mode 100644 stripspace.c rename Makefile => tools/Makefile (70%) rename dotest => tools/applymbox (87%) rename applypatch => tools/applypatch (100%) rename mailinfo.c => tools/mailinfo.c (100%) rename mailsplit.c => tools/mailsplit.c (100%) diff --git a/cvs2git.c b/cvs2git.c deleted file mode 100644 index 06dd74b368..0000000000 --- a/cvs2git.c +++ /dev/null @@ -1,307 +0,0 @@ -/* - * cvs2git - * - * Copyright (C) Linus Torvalds 2005 - */ - -#include -#include -#include -#include -#include - -static int verbose = 0; - -/* - * This is a really stupid program that takes cvsps output, and - * generates a a long _shell_script_ that will create the GIT archive - * from it. - * - * You've been warned. I told you it was stupid. - * - * NOTE NOTE NOTE! In order to do branches correctly, this needs - * the fixed cvsps that has the "Ancestor branch" tag output. - * Hopefully David Mansfield will update his distribution soon - * enough (he's the one who wrote the patch, so at least we don't - * have to figt maintainer issues ;) - * - * Usage: - * - * TZ=UTC cvsps -A | - * cvs2git --cvsroot=[root] --module=[module] > script - * - * Creates a shell script that will generate the .git archive of - * the names CVS repository. - * - * IMPORTANT NOTE ABOUT "cvsps"! This requires version 2.1 or better, - * and the "TZ=UTC" and the "-A" flag is required for sane results! - */ -enum state { - Header, - Log, - Members -}; - -static const char *cvsroot; -static const char *cvsmodule; - -static char date[100]; -static char author[100]; -static char branch[100]; -static char ancestor[100]; -static char tag[100]; -static char log[32768]; -static int loglen = 0; -static int initial_commit = 1; - -static void lookup_author(char *n, char **name, char **email) -{ - /* - * FIXME!!! I'm lazy and stupid. - * - * This could be something like - * - * printf("lookup_author '%s'\n", n); - * *name = "$author_name"; - * *email = "$author_email"; - * - * and that would allow the script to do its own - * lookups at run-time. - */ - *name = n; - *email = n; -} - -static void prepare_commit(void) -{ - char *author_name, *author_email; - char *src_branch; - - lookup_author(author, &author_name, &author_email); - - printf("export GIT_COMMITTER_NAME=%s\n", author_name); - printf("export GIT_COMMITTER_EMAIL=%s\n", author_email); - printf("export GIT_COMMITTER_DATE='+0000 %s'\n", date); - - printf("export GIT_AUTHOR_NAME=%s\n", author_name); - printf("export GIT_AUTHOR_EMAIL=%s\n", author_email); - printf("export GIT_AUTHOR_DATE='+0000 %s'\n", date); - - if (initial_commit) - return; - - src_branch = *ancestor ? ancestor : branch; - if (!strcmp(src_branch, "HEAD")) - src_branch = "master"; - printf("ln -sf refs/heads/'%s' .git/HEAD\n", src_branch); - - /* - * Even if cvsps claims an ancestor, we'll let the new - * branch name take precedence if it already exists - */ - if (*ancestor) { - src_branch = branch; - if (!strcmp(src_branch, "HEAD")) - src_branch = "master"; - printf("[ -e .git/refs/heads/'%s' ] && ln -sf refs/heads/'%s' .git/HEAD\n", - src_branch, src_branch); - } - - printf("git-read-tree -m HEAD || exit 1\n"); - printf("git-checkout-cache -f -u -a\n"); -} - -static void commit(void) -{ - const char *cmit_parent = initial_commit ? "" : "-p HEAD"; - const char *dst_branch; - int i; - - printf("tree=$(git-write-tree)\n"); - printf("cat > .cmitmsg < .git/refs/heads/'%s'\n", dst_branch); - - printf("echo 'Committed (to %s):' ; cat .cmitmsg; echo\n", dst_branch); - - *date = 0; - *author = 0; - *branch = 0; - *ancestor = 0; - *tag = 0; - loglen = 0; - - initial_commit = 0; -} - -static void update_file(char *line) -{ - char *name, *version; - char *dir; - - while (isspace(*line)) - line++; - name = line; - line = strchr(line, ':'); - if (!line) - return; - *line++ = 0; - line = strchr(line, '>'); - if (!line) - return; - *line++ = 0; - version = line; - line = strchr(line, '('); - if (line) { /* "(DEAD)" */ - printf("git-update-cache --force-remove '%s'\n", name); - return; - } - - dir = strrchr(name, '/'); - if (dir) - printf("mkdir -p %.*s\n", (int)(dir - name), name); - - printf("cvs -q -d %s checkout -r%s -p '%s/%s' > '%s'\n", cvsroot, version, cvsmodule, name, name); - printf("git-update-cache --add -- '%s'\n", name); -} - -struct hdrentry { - const char *name; - char *dest; -} hdrs[] = { - { "Date:", date }, - { "Author:", author }, - { "Branch:", branch }, - { "Ancestor branch:", ancestor }, - { "Tag:", tag }, - { "Log:", NULL }, - { NULL, NULL } -}; - -int main(int argc, char **argv) -{ - static char line[1000]; - enum state state = Header; - int i; - - for (i = 1; i < argc; i++) { - const char *arg = argv[i]; - if (!memcmp(arg, "--cvsroot=", 10)) { - cvsroot = arg + 10; - continue; - } - if (!memcmp(arg, "--module=", 9)) { - cvsmodule = arg+9; - continue; - } - if (!strcmp(arg, "-v")) { - verbose = 1; - continue; - } - } - - - if (!cvsroot) - cvsroot = getenv("CVSROOT"); - - if (!cvsmodule || !cvsroot) { - fprintf(stderr, "I need a CVSROOT and module name\n"); - exit(1); - } - - printf("[ -d .git ] && exit 1\n"); - printf("git-init-db\n"); - printf("mkdir -p .git/refs/heads\n"); - printf("mkdir -p .git/refs/tags\n"); - printf("ln -sf refs/heads/master .git/HEAD\n"); - - while (fgets(line, sizeof(line), stdin) != NULL) { - int linelen = strlen(line); - - while (linelen && isspace(line[linelen-1])) - line[--linelen] = 0; - - switch (state) { - struct hdrentry *entry; - - case Header: - if (verbose) - printf("# H: %s\n", line); - for (entry = hdrs ; entry->name ; entry++) { - int len = strlen(entry->name); - char *val; - - if (memcmp(entry->name, line, len)) - continue; - if (!entry->dest) { - state = Log; - break; - } - val = line + len; - linelen -= len; - while (isspace(*val)) { - val++; - linelen--; - } - memcpy(entry->dest, val, linelen+1); - break; - } - continue; - - case Log: - if (verbose) - printf("# L: %s\n", line); - if (!strcmp(line, "Members:")) { - while (loglen && isspace(log[loglen-1])) - log[--loglen] = 0; - prepare_commit(); - state = Members; - continue; - } - - if (loglen + linelen + 5 > sizeof(log)) - continue; - memcpy(log + loglen, line, linelen); - loglen += linelen; - log[loglen++] = '\n'; - continue; - - case Members: - if (verbose) - printf("# M: %s\n", line); - if (!linelen) { - commit(); - state = Header; - continue; - } - update_file(line); - continue; - } - } - return 0; -} diff --git a/stripspace.c b/stripspace.c deleted file mode 100644 index 96cd0a88f0..0000000000 --- a/stripspace.c +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include -#include - -/* - * Remove empty lines from the beginning and end. - * - * Turn multiple consecutive empty lines into just one - * empty line. - */ -static void cleanup(char *line) -{ - int len = strlen(line); - - if (len > 1 && line[len-1] == '\n') { - do { - unsigned char c = line[len-2]; - if (!isspace(c)) - break; - line[len-2] = '\n'; - len--; - line[len] = 0; - } while (len > 1); - } -} - -int main(int argc, char **argv) -{ - int empties = -1; - char line[1024]; - - while (fgets(line, sizeof(line), stdin)) { - cleanup(line); - - /* Not just an empty line? */ - if (line[0] != '\n') { - if (empties > 0) - putchar('\n'); - empties = 0; - fputs(line, stdout); - continue; - } - if (empties < 0) - continue; - empties++; - } - return 0; -} diff --git a/Makefile b/tools/Makefile similarity index 70% rename from Makefile rename to tools/Makefile index 99986829f8..8e7252e592 100644 --- a/Makefile +++ b/tools/Makefile @@ -2,8 +2,8 @@ CC=gcc CFLAGS=-Wall -O2 HOME=$(shell echo $$HOME) -PROGRAMS=mailsplit mailinfo stripspace cvs2git -SCRIPTS=dotest applypatch +PROGRAMS=mailsplit mailinfo +SCRIPTS=applymbox applypatch all: $(PROGRAMS) diff --git a/dotest b/tools/applymbox similarity index 87% rename from dotest rename to tools/applymbox index c6f44e1c41..5ac8d2b4da 100755 --- a/dotest +++ b/tools/applymbox @@ -4,6 +4,8 @@ ## I never got around to renaming after I tested it. We're now on the ## second generation of scripts, still called "dotest". ## +## Update: Ryan Anderson finally shamed me into naming this "applymbox". +## ## You give it a mbox-format collection of emails, and it will try to ## apply them to the kernel using "applypatch" ## @@ -20,7 +22,7 @@ mailsplit $1 .dotest || exit 1 for i in .dotest/* do mailinfo .dotest/msg .dotest/patch < $i > .dotest/info || exit 1 - stripspace < .dotest/msg > .dotest/msg-clean + git-stripspace < .dotest/msg > .dotest/msg-clean applypatch .dotest/msg-clean .dotest/patch .dotest/info "$2" ret=$? if [ $ret -ne 0 ]; then diff --git a/applypatch b/tools/applypatch similarity index 100% rename from applypatch rename to tools/applypatch diff --git a/mailinfo.c b/tools/mailinfo.c similarity index 100% rename from mailinfo.c rename to tools/mailinfo.c diff --git a/mailsplit.c b/tools/mailsplit.c similarity index 100% rename from mailsplit.c rename to tools/mailsplit.c -- GitLab