[PATCH] git-apply: Don't barf when --stat'ing a diff with no line changes.
[git.git] / cvs2git.c
index 06dd74b..ab05908 100644 (file)
--- a/cvs2git.c
+++ b/cvs2git.c
@@ -28,11 +28,17 @@ static int verbose = 0;
  * Usage:
  *
  *     TZ=UTC cvsps -A |
- *             cvs2git --cvsroot=[root] --module=[module] > script
+ *             git-cvs2git --cvsroot=[root] --module=[module] > script
  *
  * Creates a shell script that will generate the .git archive of
  * the names CVS repository.
  *
+ *     TZ=UTC cvsps -s 1234- -A |
+ *             git-cvs2git -u --cvsroot=[root] --module=[module] > script
+ *
+ * Creates a shell script that will update the .git archive with
+ * CVS changes from patchset 1234 until the last one.
+ *
  * IMPORTANT NOTE ABOUT "cvsps"! This requires version 2.1 or better,
  * and the "TZ=UTC" and the "-A" flag is required for sane results!
  */
@@ -115,6 +121,7 @@ static void commit(void)
 {
        const char *cmit_parent = initial_commit ? "" : "-p HEAD";
        const char *dst_branch;
+       char *space;
        int i;
 
        printf("tree=$(git-write-tree)\n");
@@ -147,6 +154,12 @@ static void commit(void)
 
        printf("echo $commit > .git/refs/heads/'%s'\n", dst_branch);
 
+       space = strchr(tag, ' ');
+       if (space)
+               *space = 0;
+       if (strcmp(tag, "(none)"))
+               printf("echo $commit > .git/refs/tags/'%s'\n", tag);
+
        printf("echo 'Committed (to %s):' ; cat .cmitmsg; echo\n", dst_branch);
 
        *date = 0;
@@ -186,7 +199,10 @@ static void update_file(char *line)
        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("cvs -q -d %s checkout -d .git-tmp -r%s '%s/%s'\n", 
+               cvsroot, version, cvsmodule, name);
+       printf("mv -f .git-tmp/%s %s\n", dir ? dir+1 : name, name);
+       printf("rm -rf .git-tmp\n");
        printf("git-update-cache --add -- '%s'\n", name);
 }
 
@@ -223,6 +239,10 @@ int main(int argc, char **argv)
                        verbose = 1;
                        continue;
                }
+               if (!strcmp(arg, "-u")) {
+                       initial_commit = 0;
+                       continue;
+               }
        }
 
 
@@ -234,11 +254,13 @@ int main(int argc, char **argv)
                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");
+       if (initial_commit) {
+               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);