vcs-svn / fast_export.con commit vcs-svn: add a comment before each commit (7e11902)
   1/*
   2 * Licensed under a two-clause BSD-style license.
   3 * See LICENSE for details.
   4 */
   5
   6#include "git-compat-util.h"
   7#include "fast_export.h"
   8#include "line_buffer.h"
   9#include "repo_tree.h"
  10#include "string_pool.h"
  11
  12#define MAX_GITSVN_LINE_LEN 4096
  13
  14static uint32_t first_commit_done;
  15static struct line_buffer report_buffer = LINE_BUFFER_INIT;
  16
  17void fast_export_init(int fd)
  18{
  19        if (buffer_fdinit(&report_buffer, fd))
  20                die_errno("cannot read from file descriptor %d", fd);
  21}
  22
  23void fast_export_deinit(void)
  24{
  25        if (buffer_deinit(&report_buffer))
  26                die_errno("error closing fast-import feedback stream");
  27}
  28
  29void fast_export_reset(void)
  30{
  31        buffer_reset(&report_buffer);
  32}
  33
  34void fast_export_delete(uint32_t depth, uint32_t *path)
  35{
  36        putchar('D');
  37        putchar(' ');
  38        pool_print_seq(depth, path, '/', stdout);
  39        putchar('\n');
  40}
  41
  42void fast_export_modify(uint32_t depth, uint32_t *path, uint32_t mode,
  43                        uint32_t mark)
  44{
  45        /* Mode must be 100644, 100755, 120000, or 160000. */
  46        printf("M %06"PRIo32" :%"PRIu32" ", mode, mark);
  47        pool_print_seq(depth, path, '/', stdout);
  48        putchar('\n');
  49}
  50
  51void fast_export_begin_commit(uint32_t revision)
  52{
  53        printf("# commit %"PRIu32".\n", revision);
  54}
  55
  56static char gitsvnline[MAX_GITSVN_LINE_LEN];
  57void fast_export_commit(uint32_t revision, uint32_t author, char *log,
  58                        uint32_t uuid, uint32_t url,
  59                        unsigned long timestamp)
  60{
  61        if (!log)
  62                log = "";
  63        if (~uuid && ~url) {
  64                snprintf(gitsvnline, MAX_GITSVN_LINE_LEN,
  65                                "\n\ngit-svn-id: %s@%"PRIu32" %s\n",
  66                                 pool_fetch(url), revision, pool_fetch(uuid));
  67        } else {
  68                *gitsvnline = '\0';
  69        }
  70        printf("commit refs/heads/master\n");
  71        printf("mark :%"PRIu32"\n", revision);
  72        printf("committer %s <%s@%s> %ld +0000\n",
  73                   ~author ? pool_fetch(author) : "nobody",
  74                   ~author ? pool_fetch(author) : "nobody",
  75                   ~uuid ? pool_fetch(uuid) : "local", timestamp);
  76        printf("data %"PRIu32"\n%s%s\n",
  77                   (uint32_t) (strlen(log) + strlen(gitsvnline)),
  78                   log, gitsvnline);
  79        if (!first_commit_done) {
  80                if (revision > 1)
  81                        printf("from refs/heads/master^0\n");
  82                first_commit_done = 1;
  83        }
  84        repo_diff(revision - 1, revision);
  85        fputc('\n', stdout);
  86
  87        printf("progress Imported commit %"PRIu32".\n\n", revision);
  88}
  89
  90static const char *get_response_line(void)
  91{
  92        const char *line = buffer_read_line(&report_buffer);
  93        if (line)
  94                return line;
  95        if (buffer_ferror(&report_buffer))
  96                die_errno("error reading from fast-import");
  97        die("unexpected end of fast-import feedback");
  98}
  99
 100void fast_export_blob(uint32_t mode, uint32_t mark, uint32_t len, struct line_buffer *input)
 101{
 102        if (mode == REPO_MODE_LNK) {
 103                /* svn symlink blobs start with "link " */
 104                buffer_skip_bytes(input, 5);
 105                len -= 5;
 106        }
 107        printf("blob\nmark :%"PRIu32"\ndata %"PRIu32"\n", mark, len);
 108        buffer_copy_bytes(input, len);
 109        fputc('\n', stdout);
 110}