2007-12-02 17:14:13 +03:00
|
|
|
/*
|
|
|
|
* "git fast-export" builtin command
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Johannes E. Schindelin
|
|
|
|
*/
|
|
|
|
#include "builtin.h"
|
|
|
|
#include "cache.h"
|
|
|
|
#include "commit.h"
|
|
|
|
#include "object.h"
|
|
|
|
#include "tag.h"
|
|
|
|
#include "diff.h"
|
|
|
|
#include "diffcore.h"
|
|
|
|
#include "log-tree.h"
|
|
|
|
#include "revision.h"
|
|
|
|
#include "decorate.h"
|
2008-07-21 22:03:49 +04:00
|
|
|
#include "string-list.h"
|
2007-12-02 17:14:13 +03:00
|
|
|
#include "utf8.h"
|
|
|
|
#include "parse-options.h"
|
fast-export: quote paths in output
Many pathnames in a fast-import stream need to be quoted. In
particular:
1. Pathnames at the end of an "M" or "D" line need quoting
if they contain a LF or start with double-quote.
2. Pathnames on a "C" or "R" line need quoting as above,
but also if they contain spaces.
For (1), we weren't quoting at all. For (2), we put
double-quotes around the paths to handle spaces, but ignored
the possibility that they would need further quoting.
This patch checks whether each pathname needs c-style
quoting, and uses it. This is slightly overkill for (1),
which doesn't actually need to quote many characters that
vanilla c-style quoting does. However, it shouldn't hurt, as
any implementation needs to be ready to handle quoted
strings anyway.
In addition to adding a test, we have to tweak a test which
blindly assumed that case (2) would always use
double-quotes, whether it needed to or not.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-08-06 02:36:22 +04:00
|
|
|
#include "quote.h"
|
2007-12-02 17:14:13 +03:00
|
|
|
|
|
|
|
static const char *fast_export_usage[] = {
|
2012-08-20 16:32:08 +04:00
|
|
|
N_("git fast-export [rev-list-opts]"),
|
2007-12-02 17:14:13 +03:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static int progress;
|
2009-06-26 08:48:31 +04:00
|
|
|
static enum { ABORT, VERBATIM, WARN, STRIP } signed_tag_mode = ABORT;
|
2011-12-21 05:18:19 +04:00
|
|
|
static enum { ERROR, DROP, REWRITE } tag_of_filtered_mode = ERROR;
|
2008-12-20 03:00:27 +03:00
|
|
|
static int fake_missing_tagger;
|
2011-07-16 17:03:33 +04:00
|
|
|
static int use_done_feature;
|
2009-07-28 06:20:22 +04:00
|
|
|
static int no_data;
|
2010-07-17 21:00:51 +04:00
|
|
|
static int full_tree;
|
2007-12-02 17:14:13 +03:00
|
|
|
|
|
|
|
static int parse_opt_signed_tag_mode(const struct option *opt,
|
|
|
|
const char *arg, int unset)
|
|
|
|
{
|
|
|
|
if (unset || !strcmp(arg, "abort"))
|
|
|
|
signed_tag_mode = ABORT;
|
2007-12-04 01:44:39 +03:00
|
|
|
else if (!strcmp(arg, "verbatim") || !strcmp(arg, "ignore"))
|
|
|
|
signed_tag_mode = VERBATIM;
|
2007-12-02 17:14:13 +03:00
|
|
|
else if (!strcmp(arg, "warn"))
|
|
|
|
signed_tag_mode = WARN;
|
|
|
|
else if (!strcmp(arg, "strip"))
|
|
|
|
signed_tag_mode = STRIP;
|
|
|
|
else
|
|
|
|
return error("Unknown signed-tag mode: %s", arg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-26 08:48:31 +04:00
|
|
|
static int parse_opt_tag_of_filtered_mode(const struct option *opt,
|
|
|
|
const char *arg, int unset)
|
|
|
|
{
|
|
|
|
if (unset || !strcmp(arg, "abort"))
|
2011-12-21 05:18:19 +04:00
|
|
|
tag_of_filtered_mode = ERROR;
|
2009-06-26 08:48:31 +04:00
|
|
|
else if (!strcmp(arg, "drop"))
|
|
|
|
tag_of_filtered_mode = DROP;
|
|
|
|
else if (!strcmp(arg, "rewrite"))
|
|
|
|
tag_of_filtered_mode = REWRITE;
|
|
|
|
else
|
|
|
|
return error("Unknown tag-of-filtered mode: %s", arg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-12-02 17:14:13 +03:00
|
|
|
static struct decoration idnums;
|
|
|
|
static uint32_t last_idnum;
|
|
|
|
|
|
|
|
static int has_unshown_parent(struct commit *commit)
|
|
|
|
{
|
|
|
|
struct commit_list *parent;
|
|
|
|
|
|
|
|
for (parent = commit->parents; parent; parent = parent->next)
|
|
|
|
if (!(parent->item->object.flags & SHOWN) &&
|
|
|
|
!(parent->item->object.flags & UNINTERESTING))
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Since intptr_t is C99, we do not use it here */
|
2008-06-11 15:17:04 +04:00
|
|
|
static inline uint32_t *mark_to_ptr(uint32_t mark)
|
2007-12-02 17:14:13 +03:00
|
|
|
{
|
2008-06-11 15:17:04 +04:00
|
|
|
return ((uint32_t *)NULL) + mark;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t ptr_to_mark(void * mark)
|
|
|
|
{
|
|
|
|
return (uint32_t *)mark - (uint32_t *)NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mark_object(struct object *object, uint32_t mark)
|
|
|
|
{
|
|
|
|
add_decoration(&idnums, object, mark_to_ptr(mark));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mark_next_object(struct object *object)
|
|
|
|
{
|
|
|
|
mark_object(object, ++last_idnum);
|
2007-12-02 17:14:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int get_object_mark(struct object *object)
|
|
|
|
{
|
|
|
|
void *decoration = lookup_decoration(&idnums, object);
|
|
|
|
if (!decoration)
|
|
|
|
return 0;
|
2008-06-11 15:17:04 +04:00
|
|
|
return ptr_to_mark(decoration);
|
2007-12-02 17:14:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void show_progress(void)
|
|
|
|
{
|
|
|
|
static int counter = 0;
|
|
|
|
if (!progress)
|
|
|
|
return;
|
|
|
|
if ((++counter % progress) == 0)
|
|
|
|
printf("progress %d objects\n", counter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_object(const unsigned char *sha1)
|
|
|
|
{
|
|
|
|
unsigned long size;
|
|
|
|
enum object_type type;
|
|
|
|
char *buf;
|
|
|
|
struct object *object;
|
|
|
|
|
2009-07-28 06:20:22 +04:00
|
|
|
if (no_data)
|
|
|
|
return;
|
|
|
|
|
2007-12-02 17:14:13 +03:00
|
|
|
if (is_null_sha1(sha1))
|
|
|
|
return;
|
|
|
|
|
|
|
|
object = parse_object(sha1);
|
|
|
|
if (!object)
|
|
|
|
die ("Could not read blob %s", sha1_to_hex(sha1));
|
|
|
|
|
|
|
|
if (object->flags & SHOWN)
|
|
|
|
return;
|
|
|
|
|
|
|
|
buf = read_sha1_file(sha1, &type, &size);
|
|
|
|
if (!buf)
|
|
|
|
die ("Could not read blob %s", sha1_to_hex(sha1));
|
|
|
|
|
2008-06-11 15:17:04 +04:00
|
|
|
mark_next_object(object);
|
2007-12-02 17:14:13 +03:00
|
|
|
|
2008-07-03 19:52:09 +04:00
|
|
|
printf("blob\nmark :%"PRIu32"\ndata %lu\n", last_idnum, size);
|
2007-12-12 01:01:28 +03:00
|
|
|
if (size && fwrite(buf, size, 1, stdout) != 1)
|
2009-06-27 19:58:47 +04:00
|
|
|
die_errno ("Could not write blob '%s'", sha1_to_hex(sha1));
|
2007-12-02 17:14:13 +03:00
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
show_progress();
|
|
|
|
|
|
|
|
object->flags |= SHOWN;
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
|
2010-07-09 17:10:55 +04:00
|
|
|
static int depth_first(const void *a_, const void *b_)
|
|
|
|
{
|
|
|
|
const struct diff_filepair *a = *((const struct diff_filepair **)a_);
|
|
|
|
const struct diff_filepair *b = *((const struct diff_filepair **)b_);
|
|
|
|
const char *name_a, *name_b;
|
|
|
|
int len_a, len_b, len;
|
|
|
|
int cmp;
|
|
|
|
|
|
|
|
name_a = a->one ? a->one->path : a->two->path;
|
|
|
|
name_b = b->one ? b->one->path : b->two->path;
|
|
|
|
|
|
|
|
len_a = strlen(name_a);
|
|
|
|
len_b = strlen(name_b);
|
|
|
|
len = (len_a < len_b) ? len_a : len_b;
|
|
|
|
|
|
|
|
/* strcmp will sort 'd' before 'd/e', we want 'd/e' before 'd' */
|
|
|
|
cmp = memcmp(name_a, name_b, len);
|
|
|
|
if (cmp)
|
|
|
|
return cmp;
|
2010-09-07 23:33:02 +04:00
|
|
|
cmp = len_b - len_a;
|
|
|
|
if (cmp)
|
|
|
|
return cmp;
|
|
|
|
/*
|
|
|
|
* Move 'R'ename entries last so that all references of the file
|
|
|
|
* appear in the output before it is renamed (e.g., when a file
|
|
|
|
* was copied and renamed in the same commit).
|
|
|
|
*/
|
|
|
|
return (a->status == 'R') - (b->status == 'R');
|
2010-07-09 17:10:55 +04:00
|
|
|
}
|
|
|
|
|
fast-export: quote paths in output
Many pathnames in a fast-import stream need to be quoted. In
particular:
1. Pathnames at the end of an "M" or "D" line need quoting
if they contain a LF or start with double-quote.
2. Pathnames on a "C" or "R" line need quoting as above,
but also if they contain spaces.
For (1), we weren't quoting at all. For (2), we put
double-quotes around the paths to handle spaces, but ignored
the possibility that they would need further quoting.
This patch checks whether each pathname needs c-style
quoting, and uses it. This is slightly overkill for (1),
which doesn't actually need to quote many characters that
vanilla c-style quoting does. However, it shouldn't hurt, as
any implementation needs to be ready to handle quoted
strings anyway.
In addition to adding a test, we have to tweak a test which
blindly assumed that case (2) would always use
double-quotes, whether it needed to or not.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-08-06 02:36:22 +04:00
|
|
|
static void print_path(const char *path)
|
|
|
|
{
|
|
|
|
int need_quote = quote_c_style(path, NULL, NULL, 0);
|
|
|
|
if (need_quote)
|
|
|
|
quote_c_style(path, NULL, stdout, 0);
|
2012-06-28 01:58:01 +04:00
|
|
|
else if (strchr(path, ' '))
|
|
|
|
printf("\"%s\"", path);
|
fast-export: quote paths in output
Many pathnames in a fast-import stream need to be quoted. In
particular:
1. Pathnames at the end of an "M" or "D" line need quoting
if they contain a LF or start with double-quote.
2. Pathnames on a "C" or "R" line need quoting as above,
but also if they contain spaces.
For (1), we weren't quoting at all. For (2), we put
double-quotes around the paths to handle spaces, but ignored
the possibility that they would need further quoting.
This patch checks whether each pathname needs c-style
quoting, and uses it. This is slightly overkill for (1),
which doesn't actually need to quote many characters that
vanilla c-style quoting does. However, it shouldn't hurt, as
any implementation needs to be ready to handle quoted
strings anyway.
In addition to adding a test, we have to tweak a test which
blindly assumed that case (2) would always use
double-quotes, whether it needed to or not.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-08-06 02:36:22 +04:00
|
|
|
else
|
|
|
|
printf("%s", path);
|
|
|
|
}
|
|
|
|
|
2007-12-02 17:14:13 +03:00
|
|
|
static void show_filemodify(struct diff_queue_struct *q,
|
|
|
|
struct diff_options *options, void *data)
|
|
|
|
{
|
|
|
|
int i;
|
2010-07-09 17:10:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle files below a directory first, in case they are all deleted
|
|
|
|
* and the directory changes to a file or symlink.
|
|
|
|
*/
|
|
|
|
qsort(q->queue, q->nr, sizeof(q->queue[0]), depth_first);
|
|
|
|
|
2007-12-02 17:14:13 +03:00
|
|
|
for (i = 0; i < q->nr; i++) {
|
2008-07-27 00:52:54 +04:00
|
|
|
struct diff_filespec *ospec = q->queue[i]->one;
|
2007-12-02 17:14:13 +03:00
|
|
|
struct diff_filespec *spec = q->queue[i]->two;
|
2008-07-27 00:52:54 +04:00
|
|
|
|
|
|
|
switch (q->queue[i]->status) {
|
|
|
|
case DIFF_STATUS_DELETED:
|
fast-export: quote paths in output
Many pathnames in a fast-import stream need to be quoted. In
particular:
1. Pathnames at the end of an "M" or "D" line need quoting
if they contain a LF or start with double-quote.
2. Pathnames on a "C" or "R" line need quoting as above,
but also if they contain spaces.
For (1), we weren't quoting at all. For (2), we put
double-quotes around the paths to handle spaces, but ignored
the possibility that they would need further quoting.
This patch checks whether each pathname needs c-style
quoting, and uses it. This is slightly overkill for (1),
which doesn't actually need to quote many characters that
vanilla c-style quoting does. However, it shouldn't hurt, as
any implementation needs to be ready to handle quoted
strings anyway.
In addition to adding a test, we have to tweak a test which
blindly assumed that case (2) would always use
double-quotes, whether it needed to or not.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-08-06 02:36:22 +04:00
|
|
|
printf("D ");
|
|
|
|
print_path(spec->path);
|
|
|
|
putchar('\n');
|
2008-07-27 00:52:54 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DIFF_STATUS_COPIED:
|
|
|
|
case DIFF_STATUS_RENAMED:
|
fast-export: quote paths in output
Many pathnames in a fast-import stream need to be quoted. In
particular:
1. Pathnames at the end of an "M" or "D" line need quoting
if they contain a LF or start with double-quote.
2. Pathnames on a "C" or "R" line need quoting as above,
but also if they contain spaces.
For (1), we weren't quoting at all. For (2), we put
double-quotes around the paths to handle spaces, but ignored
the possibility that they would need further quoting.
This patch checks whether each pathname needs c-style
quoting, and uses it. This is slightly overkill for (1),
which doesn't actually need to quote many characters that
vanilla c-style quoting does. However, it shouldn't hurt, as
any implementation needs to be ready to handle quoted
strings anyway.
In addition to adding a test, we have to tweak a test which
blindly assumed that case (2) would always use
double-quotes, whether it needed to or not.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-08-06 02:36:22 +04:00
|
|
|
printf("%c ", q->queue[i]->status);
|
|
|
|
print_path(ospec->path);
|
|
|
|
putchar(' ');
|
|
|
|
print_path(spec->path);
|
|
|
|
putchar('\n');
|
2008-07-27 00:52:54 +04:00
|
|
|
|
|
|
|
if (!hashcmp(ospec->sha1, spec->sha1) &&
|
|
|
|
ospec->mode == spec->mode)
|
|
|
|
break;
|
|
|
|
/* fallthrough */
|
|
|
|
|
|
|
|
case DIFF_STATUS_TYPE_CHANGED:
|
|
|
|
case DIFF_STATUS_MODIFIED:
|
|
|
|
case DIFF_STATUS_ADDED:
|
2008-07-19 16:21:24 +04:00
|
|
|
/*
|
|
|
|
* Links refer to objects in another repositories;
|
|
|
|
* output the SHA-1 verbatim.
|
|
|
|
*/
|
2009-07-28 06:20:22 +04:00
|
|
|
if (no_data || S_ISGITLINK(spec->mode))
|
fast-export: quote paths in output
Many pathnames in a fast-import stream need to be quoted. In
particular:
1. Pathnames at the end of an "M" or "D" line need quoting
if they contain a LF or start with double-quote.
2. Pathnames on a "C" or "R" line need quoting as above,
but also if they contain spaces.
For (1), we weren't quoting at all. For (2), we put
double-quotes around the paths to handle spaces, but ignored
the possibility that they would need further quoting.
This patch checks whether each pathname needs c-style
quoting, and uses it. This is slightly overkill for (1),
which doesn't actually need to quote many characters that
vanilla c-style quoting does. However, it shouldn't hurt, as
any implementation needs to be ready to handle quoted
strings anyway.
In addition to adding a test, we have to tweak a test which
blindly assumed that case (2) would always use
double-quotes, whether it needed to or not.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-08-06 02:36:22 +04:00
|
|
|
printf("M %06o %s ", spec->mode,
|
|
|
|
sha1_to_hex(spec->sha1));
|
2008-07-19 16:21:24 +04:00
|
|
|
else {
|
|
|
|
struct object *object = lookup_object(spec->sha1);
|
fast-export: quote paths in output
Many pathnames in a fast-import stream need to be quoted. In
particular:
1. Pathnames at the end of an "M" or "D" line need quoting
if they contain a LF or start with double-quote.
2. Pathnames on a "C" or "R" line need quoting as above,
but also if they contain spaces.
For (1), we weren't quoting at all. For (2), we put
double-quotes around the paths to handle spaces, but ignored
the possibility that they would need further quoting.
This patch checks whether each pathname needs c-style
quoting, and uses it. This is slightly overkill for (1),
which doesn't actually need to quote many characters that
vanilla c-style quoting does. However, it shouldn't hurt, as
any implementation needs to be ready to handle quoted
strings anyway.
In addition to adding a test, we have to tweak a test which
blindly assumed that case (2) would always use
double-quotes, whether it needed to or not.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-08-06 02:36:22 +04:00
|
|
|
printf("M %06o :%d ", spec->mode,
|
|
|
|
get_object_mark(object));
|
2008-07-19 16:21:24 +04:00
|
|
|
}
|
fast-export: quote paths in output
Many pathnames in a fast-import stream need to be quoted. In
particular:
1. Pathnames at the end of an "M" or "D" line need quoting
if they contain a LF or start with double-quote.
2. Pathnames on a "C" or "R" line need quoting as above,
but also if they contain spaces.
For (1), we weren't quoting at all. For (2), we put
double-quotes around the paths to handle spaces, but ignored
the possibility that they would need further quoting.
This patch checks whether each pathname needs c-style
quoting, and uses it. This is slightly overkill for (1),
which doesn't actually need to quote many characters that
vanilla c-style quoting does. However, it shouldn't hurt, as
any implementation needs to be ready to handle quoted
strings anyway.
In addition to adding a test, we have to tweak a test which
blindly assumed that case (2) would always use
double-quotes, whether it needed to or not.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-08-06 02:36:22 +04:00
|
|
|
print_path(spec->path);
|
|
|
|
putchar('\n');
|
2008-07-27 00:52:54 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
die("Unexpected comparison status '%c' for %s, %s",
|
|
|
|
q->queue[i]->status,
|
|
|
|
ospec->path ? ospec->path : "none",
|
|
|
|
spec->path ? spec->path : "none");
|
2007-12-02 17:14:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *find_encoding(const char *begin, const char *end)
|
|
|
|
{
|
|
|
|
const char *needle = "\nencoding ";
|
|
|
|
char *bol, *eol;
|
|
|
|
|
|
|
|
bol = memmem(begin, end ? end - begin : strlen(begin),
|
|
|
|
needle, strlen(needle));
|
|
|
|
if (!bol)
|
|
|
|
return git_commit_encoding;
|
|
|
|
bol += strlen(needle);
|
|
|
|
eol = strchrnul(bol, '\n');
|
|
|
|
*eol = '\0';
|
|
|
|
return bol;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_commit(struct commit *commit, struct rev_info *rev)
|
|
|
|
{
|
|
|
|
int saved_output_format = rev->diffopt.output_format;
|
|
|
|
const char *author, *author_end, *committer, *committer_end;
|
|
|
|
const char *encoding, *message;
|
|
|
|
char *reencoded = NULL;
|
|
|
|
struct commit_list *p;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
rev->diffopt.output_format = DIFF_FORMAT_CALLBACK;
|
|
|
|
|
|
|
|
parse_commit(commit);
|
|
|
|
author = strstr(commit->buffer, "\nauthor ");
|
|
|
|
if (!author)
|
|
|
|
die ("Could not find author in commit %s",
|
|
|
|
sha1_to_hex(commit->object.sha1));
|
|
|
|
author++;
|
|
|
|
author_end = strchrnul(author, '\n');
|
|
|
|
committer = strstr(author_end, "\ncommitter ");
|
|
|
|
if (!committer)
|
|
|
|
die ("Could not find committer in commit %s",
|
|
|
|
sha1_to_hex(commit->object.sha1));
|
|
|
|
committer++;
|
|
|
|
committer_end = strchrnul(committer, '\n');
|
|
|
|
message = strstr(committer_end, "\n\n");
|
|
|
|
encoding = find_encoding(committer_end, message);
|
|
|
|
if (message)
|
|
|
|
message += 2;
|
|
|
|
|
2009-03-26 02:53:23 +03:00
|
|
|
if (commit->parents &&
|
2010-07-17 21:00:50 +04:00
|
|
|
get_object_mark(&commit->parents->item->object) != 0 &&
|
|
|
|
!full_tree) {
|
2007-12-02 17:14:13 +03:00
|
|
|
parse_commit(commit->parents->item);
|
|
|
|
diff_tree_sha1(commit->parents->item->tree->object.sha1,
|
|
|
|
commit->tree->object.sha1, "", &rev->diffopt);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
diff_root_tree_sha1(commit->tree->object.sha1,
|
|
|
|
"", &rev->diffopt);
|
|
|
|
|
2008-07-19 16:21:24 +04:00
|
|
|
/* Export the referenced blobs, and remember the marks. */
|
2007-12-02 17:14:13 +03:00
|
|
|
for (i = 0; i < diff_queued_diff.nr; i++)
|
2008-07-19 16:21:24 +04:00
|
|
|
if (!S_ISGITLINK(diff_queued_diff.queue[i]->two->mode))
|
|
|
|
handle_object(diff_queued_diff.queue[i]->two->sha1);
|
2007-12-02 17:14:13 +03:00
|
|
|
|
2008-06-11 15:17:04 +04:00
|
|
|
mark_next_object(&commit->object);
|
2007-12-02 17:14:13 +03:00
|
|
|
if (!is_encoding_utf8(encoding))
|
|
|
|
reencoded = reencode_string(message, "UTF-8", encoding);
|
2008-06-13 08:38:55 +04:00
|
|
|
if (!commit->parents)
|
|
|
|
printf("reset %s\n", (const char*)commit->util);
|
2008-07-03 19:52:09 +04:00
|
|
|
printf("commit %s\nmark :%"PRIu32"\n%.*s\n%.*s\ndata %u\n%s",
|
2007-12-02 17:14:13 +03:00
|
|
|
(const char *)commit->util, last_idnum,
|
|
|
|
(int)(author_end - author), author,
|
|
|
|
(int)(committer_end - committer), committer,
|
|
|
|
(unsigned)(reencoded
|
|
|
|
? strlen(reencoded) : message
|
|
|
|
? strlen(message) : 0),
|
|
|
|
reencoded ? reencoded : message ? message : "");
|
Avoid unnecessary "if-before-free" tests.
This change removes all obvious useless if-before-free tests.
E.g., it replaces code like this:
if (some_expression)
free (some_expression);
with the now-equivalent:
free (some_expression);
It is equivalent not just because POSIX has required free(NULL)
to work for a long time, but simply because it has worked for
so long that no reasonable porting target fails the test.
Here's some evidence from nearly 1.5 years ago:
http://www.winehq.org/pipermail/wine-patches/2006-October/031544.html
FYI, the change below was prepared by running the following:
git ls-files -z | xargs -0 \
perl -0x3b -pi -e \
's/\bif\s*\(\s*(\S+?)(?:\s*!=\s*NULL)?\s*\)\s+(free\s*\(\s*\1\s*\))/$2/s'
Note however, that it doesn't handle brace-enclosed blocks like
"if (x) { free (x); }". But that's ok, since there were none like
that in git sources.
Beware: if you do use the above snippet, note that it can
produce syntactically invalid C code. That happens when the
affected "if"-statement has a matching "else".
E.g., it would transform this
if (x)
free (x);
else
foo ();
into this:
free (x);
else
foo ();
There were none of those here, either.
If you're interested in automating detection of the useless
tests, you might like the useless-if-before-free script in gnulib:
[it *does* detect brace-enclosed free statements, and has a --name=S
option to make it detect free-like functions with different names]
http://git.sv.gnu.org/gitweb/?p=gnulib.git;a=blob;f=build-aux/useless-if-before-free
Addendum:
Remove one more (in imap-send.c), spotted by Jean-Luc Herren <jlh@gmx.ch>.
Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-01-31 20:26:32 +03:00
|
|
|
free(reencoded);
|
2007-12-02 17:14:13 +03:00
|
|
|
|
|
|
|
for (i = 0, p = commit->parents; p; p = p->next) {
|
|
|
|
int mark = get_object_mark(&p->item->object);
|
|
|
|
if (!mark)
|
|
|
|
continue;
|
|
|
|
if (i == 0)
|
|
|
|
printf("from :%d\n", mark);
|
|
|
|
else
|
2008-05-25 03:21:53 +04:00
|
|
|
printf("merge :%d\n", mark);
|
2007-12-02 17:14:13 +03:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2010-07-17 21:00:50 +04:00
|
|
|
if (full_tree)
|
|
|
|
printf("deleteall\n");
|
2007-12-02 17:14:13 +03:00
|
|
|
log_tree_diff_flush(rev);
|
|
|
|
rev->diffopt.output_format = saved_output_format;
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
show_progress();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_tail(struct object_array *commits, struct rev_info *revs)
|
|
|
|
{
|
|
|
|
struct commit *commit;
|
|
|
|
while (commits->nr) {
|
|
|
|
commit = (struct commit *)commits->objects[commits->nr - 1].item;
|
|
|
|
if (has_unshown_parent(commit))
|
|
|
|
return;
|
|
|
|
handle_commit(commit, revs);
|
|
|
|
commits->nr--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_tag(const char *name, struct tag *tag)
|
|
|
|
{
|
|
|
|
unsigned long size;
|
|
|
|
enum object_type type;
|
|
|
|
char *buf;
|
|
|
|
const char *tagger, *tagger_end, *message;
|
|
|
|
size_t message_size = 0;
|
2009-06-26 08:48:28 +04:00
|
|
|
struct object *tagged;
|
2009-06-26 08:48:31 +04:00
|
|
|
int tagged_mark;
|
|
|
|
struct commit *p;
|
2009-06-26 08:48:28 +04:00
|
|
|
|
|
|
|
/* Trees have no identifer in fast-export output, thus we have no way
|
|
|
|
* to output tags of trees, tags of tags of trees, etc. Simply omit
|
|
|
|
* such tags.
|
|
|
|
*/
|
|
|
|
tagged = tag->tagged;
|
|
|
|
while (tagged->type == OBJ_TAG) {
|
|
|
|
tagged = ((struct tag *)tagged)->tagged;
|
|
|
|
}
|
|
|
|
if (tagged->type == OBJ_TREE) {
|
|
|
|
warning("Omitting tag %s,\nsince tags of trees (or tags of tags of trees, etc.) are not supported.",
|
|
|
|
sha1_to_hex(tag->object.sha1));
|
|
|
|
return;
|
|
|
|
}
|
2007-12-02 17:14:13 +03:00
|
|
|
|
|
|
|
buf = read_sha1_file(tag->object.sha1, &type, &size);
|
|
|
|
if (!buf)
|
|
|
|
die ("Could not read tag %s", sha1_to_hex(tag->object.sha1));
|
|
|
|
message = memmem(buf, size, "\n\n", 2);
|
|
|
|
if (message) {
|
|
|
|
message += 2;
|
|
|
|
message_size = strlen(message);
|
|
|
|
}
|
|
|
|
tagger = memmem(buf, message ? message - buf : size, "\ntagger ", 8);
|
2008-12-20 03:00:27 +03:00
|
|
|
if (!tagger) {
|
|
|
|
if (fake_missing_tagger)
|
|
|
|
tagger = "tagger Unspecified Tagger "
|
|
|
|
"<unspecified-tagger> 0 +0000";
|
|
|
|
else
|
|
|
|
tagger = "";
|
|
|
|
tagger_end = tagger + strlen(tagger);
|
|
|
|
} else {
|
|
|
|
tagger++;
|
|
|
|
tagger_end = strchrnul(tagger, '\n');
|
|
|
|
}
|
2007-12-02 17:14:13 +03:00
|
|
|
|
|
|
|
/* handle signed tags */
|
|
|
|
if (message) {
|
|
|
|
const char *signature = strstr(message,
|
|
|
|
"\n-----BEGIN PGP SIGNATURE-----\n");
|
|
|
|
if (signature)
|
|
|
|
switch(signed_tag_mode) {
|
|
|
|
case ABORT:
|
|
|
|
die ("Encountered signed tag %s; use "
|
|
|
|
"--signed-tag=<mode> to handle it.",
|
|
|
|
sha1_to_hex(tag->object.sha1));
|
|
|
|
case WARN:
|
|
|
|
warning ("Exporting signed tag %s",
|
|
|
|
sha1_to_hex(tag->object.sha1));
|
|
|
|
/* fallthru */
|
2007-12-04 01:44:39 +03:00
|
|
|
case VERBATIM:
|
2007-12-02 17:14:13 +03:00
|
|
|
break;
|
|
|
|
case STRIP:
|
|
|
|
message_size = signature + 1 - message;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-26 08:48:31 +04:00
|
|
|
/* handle tag->tagged having been filtered out due to paths specified */
|
|
|
|
tagged = tag->tagged;
|
|
|
|
tagged_mark = get_object_mark(tagged);
|
|
|
|
if (!tagged_mark) {
|
|
|
|
switch(tag_of_filtered_mode) {
|
|
|
|
case ABORT:
|
|
|
|
die ("Tag %s tags unexported object; use "
|
|
|
|
"--tag-of-filtered-object=<mode> to handle it.",
|
|
|
|
sha1_to_hex(tag->object.sha1));
|
|
|
|
case DROP:
|
|
|
|
/* Ignore this tag altogether */
|
|
|
|
return;
|
|
|
|
case REWRITE:
|
|
|
|
if (tagged->type != OBJ_COMMIT) {
|
|
|
|
die ("Tag %s tags unexported %s!",
|
|
|
|
sha1_to_hex(tag->object.sha1),
|
|
|
|
typename(tagged->type));
|
|
|
|
}
|
|
|
|
p = (struct commit *)tagged;
|
|
|
|
for (;;) {
|
|
|
|
if (p->parents && p->parents->next)
|
|
|
|
break;
|
|
|
|
if (p->object.flags & UNINTERESTING)
|
|
|
|
break;
|
|
|
|
if (!(p->object.flags & TREESAME))
|
|
|
|
break;
|
|
|
|
if (!p->parents)
|
|
|
|
die ("Can't find replacement commit for tag %s\n",
|
|
|
|
sha1_to_hex(tag->object.sha1));
|
|
|
|
p = p->parents->item;
|
|
|
|
}
|
|
|
|
tagged_mark = get_object_mark(&p->object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-02 17:14:13 +03:00
|
|
|
if (!prefixcmp(name, "refs/tags/"))
|
|
|
|
name += 10;
|
2008-12-20 03:00:27 +03:00
|
|
|
printf("tag %s\nfrom :%d\n%.*s%sdata %d\n%.*s\n",
|
2009-06-26 08:48:31 +04:00
|
|
|
name, tagged_mark,
|
2007-12-02 17:14:13 +03:00
|
|
|
(int)(tagger_end - tagger), tagger,
|
2008-12-20 03:00:27 +03:00
|
|
|
tagger == tagger_end ? "" : "\n",
|
2007-12-02 17:14:13 +03:00
|
|
|
(int)message_size, (int)message_size, message ? message : "");
|
|
|
|
}
|
|
|
|
|
fast-export: don't handle uninteresting refs
They have been marked as UNINTERESTING for a reason, lets respect
that. Currently the first ref is handled properly, but not the
rest. Assuming that all the refs point at the same commit in the
following example:
% git fast-export master ^uninteresting ^foo ^bar
reset refs/heads/bar
from :0
reset refs/heads/foo
from :0
reset refs/heads/uninteresting
from :0
% git fast-export ^uninteresting ^foo ^bar master
reset refs/heads/master
from :0
reset refs/heads/bar
from :0
reset refs/heads/foo
from :0
Clearly this is wrong; the negative refs should be ignored.
After this patch:
% git fast-export ^uninteresting ^foo ^bar master
# nothing
% git fast-export master ^uninteresting ^foo ^bar
# nothing
And even more, it would only happen if the ref is pointing to exactly
the same commit, but not otherwise:
% git fast-export ^next next
reset refs/heads/next
from :0
% git fast-export ^next next^{commit}
# nothing
% git fast-export ^next next~0
# nothing
% git fast-export ^next next~1
# nothing
% git fast-export ^next next~2
# nothing
The reason this happens is that before traversing the commits,
fast-export checks if any of the refs point to the same object, and any
duplicated ref gets added to a list in order to issue 'reset' commands
after the traversing. Unfortunately, it's not even checking if the
commit is flagged as UNINTERESTING. The fix of course, is to check it.
However, in order to do it properly we need to get the UNINTERESTING
flag from the command line, not from the commit object, because
"^foo bar" will mark the commit 'bar' uninteresting if foo and bar
points at the same commit. rev_cmdline_info, which was introduced
exactly to handle this situation, contains all the information we
need for get_tags_and_duplicates(), plus the ref flag. This way the
rest of the positive refs will remain untouched; it's only the
negative ones that change in behavior.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-11-29 02:23:59 +04:00
|
|
|
static void get_tags_and_duplicates(struct rev_cmdline_info *info,
|
2008-07-21 22:03:49 +04:00
|
|
|
struct string_list *extra_refs)
|
2007-12-02 17:14:13 +03:00
|
|
|
{
|
|
|
|
struct tag *tag;
|
|
|
|
int i;
|
|
|
|
|
fast-export: don't handle uninteresting refs
They have been marked as UNINTERESTING for a reason, lets respect
that. Currently the first ref is handled properly, but not the
rest. Assuming that all the refs point at the same commit in the
following example:
% git fast-export master ^uninteresting ^foo ^bar
reset refs/heads/bar
from :0
reset refs/heads/foo
from :0
reset refs/heads/uninteresting
from :0
% git fast-export ^uninteresting ^foo ^bar master
reset refs/heads/master
from :0
reset refs/heads/bar
from :0
reset refs/heads/foo
from :0
Clearly this is wrong; the negative refs should be ignored.
After this patch:
% git fast-export ^uninteresting ^foo ^bar master
# nothing
% git fast-export master ^uninteresting ^foo ^bar
# nothing
And even more, it would only happen if the ref is pointing to exactly
the same commit, but not otherwise:
% git fast-export ^next next
reset refs/heads/next
from :0
% git fast-export ^next next^{commit}
# nothing
% git fast-export ^next next~0
# nothing
% git fast-export ^next next~1
# nothing
% git fast-export ^next next~2
# nothing
The reason this happens is that before traversing the commits,
fast-export checks if any of the refs point to the same object, and any
duplicated ref gets added to a list in order to issue 'reset' commands
after the traversing. Unfortunately, it's not even checking if the
commit is flagged as UNINTERESTING. The fix of course, is to check it.
However, in order to do it properly we need to get the UNINTERESTING
flag from the command line, not from the commit object, because
"^foo bar" will mark the commit 'bar' uninteresting if foo and bar
points at the same commit. rev_cmdline_info, which was introduced
exactly to handle this situation, contains all the information we
need for get_tags_and_duplicates(), plus the ref flag. This way the
rest of the positive refs will remain untouched; it's only the
negative ones that change in behavior.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-11-29 02:23:59 +04:00
|
|
|
for (i = 0; i < info->nr; i++) {
|
|
|
|
struct rev_cmdline_entry *e = info->rev + i;
|
2007-12-02 17:14:13 +03:00
|
|
|
unsigned char sha1[20];
|
2012-11-29 02:11:08 +04:00
|
|
|
struct commit *commit;
|
2007-12-02 17:14:13 +03:00
|
|
|
char *full_name;
|
|
|
|
|
fast-export: don't handle uninteresting refs
They have been marked as UNINTERESTING for a reason, lets respect
that. Currently the first ref is handled properly, but not the
rest. Assuming that all the refs point at the same commit in the
following example:
% git fast-export master ^uninteresting ^foo ^bar
reset refs/heads/bar
from :0
reset refs/heads/foo
from :0
reset refs/heads/uninteresting
from :0
% git fast-export ^uninteresting ^foo ^bar master
reset refs/heads/master
from :0
reset refs/heads/bar
from :0
reset refs/heads/foo
from :0
Clearly this is wrong; the negative refs should be ignored.
After this patch:
% git fast-export ^uninteresting ^foo ^bar master
# nothing
% git fast-export master ^uninteresting ^foo ^bar
# nothing
And even more, it would only happen if the ref is pointing to exactly
the same commit, but not otherwise:
% git fast-export ^next next
reset refs/heads/next
from :0
% git fast-export ^next next^{commit}
# nothing
% git fast-export ^next next~0
# nothing
% git fast-export ^next next~1
# nothing
% git fast-export ^next next~2
# nothing
The reason this happens is that before traversing the commits,
fast-export checks if any of the refs point to the same object, and any
duplicated ref gets added to a list in order to issue 'reset' commands
after the traversing. Unfortunately, it's not even checking if the
commit is flagged as UNINTERESTING. The fix of course, is to check it.
However, in order to do it properly we need to get the UNINTERESTING
flag from the command line, not from the commit object, because
"^foo bar" will mark the commit 'bar' uninteresting if foo and bar
points at the same commit. rev_cmdline_info, which was introduced
exactly to handle this situation, contains all the information we
need for get_tags_and_duplicates(), plus the ref flag. This way the
rest of the positive refs will remain untouched; it's only the
negative ones that change in behavior.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-11-29 02:23:59 +04:00
|
|
|
if (e->flags & UNINTERESTING)
|
|
|
|
continue;
|
|
|
|
|
2007-12-02 17:14:13 +03:00
|
|
|
if (dwim_ref(e->name, strlen(e->name), sha1, &full_name) != 1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch (e->item->type) {
|
|
|
|
case OBJ_COMMIT:
|
|
|
|
commit = (struct commit *)e->item;
|
|
|
|
break;
|
|
|
|
case OBJ_TAG:
|
|
|
|
tag = (struct tag *)e->item;
|
2009-03-23 15:53:09 +03:00
|
|
|
|
|
|
|
/* handle nested tags */
|
2007-12-02 17:14:13 +03:00
|
|
|
while (tag && tag->object.type == OBJ_TAG) {
|
2009-03-23 15:53:09 +03:00
|
|
|
parse_object(tag->object.sha1);
|
2010-06-26 03:41:38 +04:00
|
|
|
string_list_append(extra_refs, full_name)->util = tag;
|
2007-12-02 17:14:13 +03:00
|
|
|
tag = (struct tag *)tag->tagged;
|
|
|
|
}
|
|
|
|
if (!tag)
|
|
|
|
die ("Tag %s points nowhere?", e->name);
|
|
|
|
switch(tag->object.type) {
|
|
|
|
case OBJ_COMMIT:
|
|
|
|
commit = (struct commit *)tag;
|
|
|
|
break;
|
|
|
|
case OBJ_BLOB:
|
|
|
|
handle_object(tag->object.sha1);
|
|
|
|
continue;
|
2009-03-23 15:53:09 +03:00
|
|
|
default: /* OBJ_TAG (nested tags) is already handled */
|
2009-03-23 15:53:08 +03:00
|
|
|
warning("Tag points to object of unexpected type %s, skipping.",
|
|
|
|
typename(tag->object.type));
|
|
|
|
continue;
|
2007-12-02 17:14:13 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2009-03-23 15:53:07 +03:00
|
|
|
warning("%s: Unexpected object of type %s, skipping.",
|
|
|
|
e->name,
|
|
|
|
typename(e->item->type));
|
|
|
|
continue;
|
2007-12-02 17:14:13 +03:00
|
|
|
}
|
|
|
|
if (commit->util)
|
|
|
|
/* more than one name for the same object */
|
2010-06-26 03:41:38 +04:00
|
|
|
string_list_append(extra_refs, full_name)->util = commit;
|
2007-12-02 17:14:13 +03:00
|
|
|
else
|
|
|
|
commit->util = full_name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-21 22:03:49 +04:00
|
|
|
static void handle_tags_and_duplicates(struct string_list *extra_refs)
|
2007-12-02 17:14:13 +03:00
|
|
|
{
|
|
|
|
struct commit *commit;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = extra_refs->nr - 1; i >= 0; i--) {
|
2008-07-21 22:03:49 +04:00
|
|
|
const char *name = extra_refs->items[i].string;
|
2007-12-02 17:14:13 +03:00
|
|
|
struct object *object = extra_refs->items[i].util;
|
|
|
|
switch (object->type) {
|
|
|
|
case OBJ_TAG:
|
|
|
|
handle_tag(name, (struct tag *)object);
|
|
|
|
break;
|
|
|
|
case OBJ_COMMIT:
|
|
|
|
/* create refs pointing to already seen commits */
|
|
|
|
commit = (struct commit *)object;
|
|
|
|
printf("reset %s\nfrom :%d\n\n", name,
|
|
|
|
get_object_mark(&commit->object));
|
|
|
|
show_progress();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-11 15:17:04 +04:00
|
|
|
static void export_marks(char *file)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
uint32_t mark;
|
|
|
|
struct object_decoration *deco = idnums.hash;
|
|
|
|
FILE *f;
|
2009-07-24 12:17:13 +04:00
|
|
|
int e = 0;
|
2008-06-11 15:17:04 +04:00
|
|
|
|
|
|
|
f = fopen(file, "w");
|
|
|
|
if (!f)
|
2010-03-28 09:42:48 +04:00
|
|
|
die_errno("Unable to open marks file %s for writing.", file);
|
2008-06-11 15:17:04 +04:00
|
|
|
|
2008-07-03 11:25:23 +04:00
|
|
|
for (i = 0; i < idnums.size; i++) {
|
|
|
|
if (deco->base && deco->base->type == 1) {
|
2008-06-11 15:17:04 +04:00
|
|
|
mark = ptr_to_mark(deco->decoration);
|
2009-07-24 12:17:13 +04:00
|
|
|
if (fprintf(f, ":%"PRIu32" %s\n", mark,
|
|
|
|
sha1_to_hex(deco->base->sha1)) < 0) {
|
|
|
|
e = 1;
|
|
|
|
break;
|
|
|
|
}
|
2008-06-11 15:17:04 +04:00
|
|
|
}
|
2008-07-03 11:25:23 +04:00
|
|
|
deco++;
|
2008-06-11 15:17:04 +04:00
|
|
|
}
|
|
|
|
|
2009-07-24 12:17:13 +04:00
|
|
|
e |= ferror(f);
|
|
|
|
e |= fclose(f);
|
|
|
|
if (e)
|
2008-06-11 15:17:04 +04:00
|
|
|
error("Unable to write marks file %s.", file);
|
|
|
|
}
|
|
|
|
|
2008-07-03 11:25:23 +04:00
|
|
|
static void import_marks(char *input_file)
|
2008-06-11 15:17:04 +04:00
|
|
|
{
|
|
|
|
char line[512];
|
|
|
|
FILE *f = fopen(input_file, "r");
|
|
|
|
if (!f)
|
2009-06-27 19:58:46 +04:00
|
|
|
die_errno("cannot read '%s'", input_file);
|
2008-06-11 15:17:04 +04:00
|
|
|
|
|
|
|
while (fgets(line, sizeof(line), f)) {
|
|
|
|
uint32_t mark;
|
|
|
|
char *line_end, *mark_end;
|
|
|
|
unsigned char sha1[20];
|
|
|
|
struct object *object;
|
|
|
|
|
|
|
|
line_end = strchr(line, '\n');
|
|
|
|
if (line[0] != ':' || !line_end)
|
|
|
|
die("corrupt mark line: %s", line);
|
2008-07-03 11:25:23 +04:00
|
|
|
*line_end = '\0';
|
2008-06-11 15:17:04 +04:00
|
|
|
|
|
|
|
mark = strtoumax(line + 1, &mark_end, 10);
|
|
|
|
if (!mark || mark_end == line + 1
|
|
|
|
|| *mark_end != ' ' || get_sha1(mark_end + 1, sha1))
|
|
|
|
die("corrupt mark line: %s", line);
|
|
|
|
|
|
|
|
object = parse_object(sha1);
|
|
|
|
if (!object)
|
|
|
|
die ("Could not read blob %s", sha1_to_hex(sha1));
|
|
|
|
|
|
|
|
if (object->flags & SHOWN)
|
2012-06-12 17:45:16 +04:00
|
|
|
error("Object %s already has a mark", sha1_to_hex(sha1));
|
2008-06-11 15:17:04 +04:00
|
|
|
|
2012-11-24 07:17:01 +04:00
|
|
|
if (object->type != OBJ_COMMIT)
|
|
|
|
/* only commits */
|
|
|
|
continue;
|
|
|
|
|
2008-06-11 15:17:04 +04:00
|
|
|
mark_object(object, mark);
|
|
|
|
if (last_idnum < mark)
|
|
|
|
last_idnum = mark;
|
|
|
|
|
|
|
|
object->flags |= SHOWN;
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
2007-12-02 17:14:13 +03:00
|
|
|
int cmd_fast_export(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
struct rev_info revs;
|
2010-08-29 06:04:17 +04:00
|
|
|
struct object_array commits = OBJECT_ARRAY_INIT;
|
2010-07-04 23:46:19 +04:00
|
|
|
struct string_list extra_refs = STRING_LIST_INIT_NODUP;
|
2007-12-02 17:14:13 +03:00
|
|
|
struct commit *commit;
|
2008-06-11 15:17:04 +04:00
|
|
|
char *export_filename = NULL, *import_filename = NULL;
|
2007-12-02 17:14:13 +03:00
|
|
|
struct option options[] = {
|
|
|
|
OPT_INTEGER(0, "progress", &progress,
|
2012-08-20 16:32:08 +04:00
|
|
|
N_("show progress after <n> objects")),
|
|
|
|
OPT_CALLBACK(0, "signed-tags", &signed_tag_mode, N_("mode"),
|
|
|
|
N_("select handling of signed tags"),
|
2007-12-02 17:14:13 +03:00
|
|
|
parse_opt_signed_tag_mode),
|
2012-08-20 16:32:08 +04:00
|
|
|
OPT_CALLBACK(0, "tag-of-filtered-object", &tag_of_filtered_mode, N_("mode"),
|
|
|
|
N_("select handling of tags that tag filtered objects"),
|
2009-06-26 08:48:31 +04:00
|
|
|
parse_opt_tag_of_filtered_mode),
|
2012-08-20 16:32:08 +04:00
|
|
|
OPT_STRING(0, "export-marks", &export_filename, N_("file"),
|
|
|
|
N_("Dump marks to this file")),
|
|
|
|
OPT_STRING(0, "import-marks", &import_filename, N_("file"),
|
|
|
|
N_("Import marks from this file")),
|
2008-12-20 03:00:27 +03:00
|
|
|
OPT_BOOLEAN(0, "fake-missing-tagger", &fake_missing_tagger,
|
2012-08-20 16:32:08 +04:00
|
|
|
N_("Fake a tagger when tags lack one")),
|
2010-07-17 21:00:51 +04:00
|
|
|
OPT_BOOLEAN(0, "full-tree", &full_tree,
|
2012-08-20 16:32:08 +04:00
|
|
|
N_("Output full tree for each commit")),
|
2011-07-16 17:03:33 +04:00
|
|
|
OPT_BOOLEAN(0, "use-done-feature", &use_done_feature,
|
2012-08-20 16:32:08 +04:00
|
|
|
N_("Use the done feature to terminate the stream")),
|
|
|
|
OPT_BOOL(0, "no-data", &no_data, N_("Skip output of blob data")),
|
2007-12-02 17:14:13 +03:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
2009-01-03 06:59:12 +03:00
|
|
|
if (argc == 1)
|
|
|
|
usage_with_options (fast_export_usage, options);
|
|
|
|
|
2007-12-02 17:14:13 +03:00
|
|
|
/* we handle encodings */
|
2008-05-14 21:46:53 +04:00
|
|
|
git_config(git_default_config, NULL);
|
2007-12-02 17:14:13 +03:00
|
|
|
|
|
|
|
init_revisions(&revs, prefix);
|
2009-06-26 08:48:27 +04:00
|
|
|
revs.topo_order = 1;
|
2009-06-26 08:48:29 +04:00
|
|
|
revs.show_source = 1;
|
2009-06-26 08:48:30 +04:00
|
|
|
revs.rewrite_parents = 1;
|
2007-12-02 17:14:13 +03:00
|
|
|
argc = setup_revisions(argc, argv, &revs, NULL);
|
2009-05-23 22:53:12 +04:00
|
|
|
argc = parse_options(argc, argv, prefix, options, fast_export_usage, 0);
|
2007-12-02 17:14:13 +03:00
|
|
|
if (argc > 1)
|
|
|
|
usage_with_options (fast_export_usage, options);
|
|
|
|
|
2011-07-16 17:03:33 +04:00
|
|
|
if (use_done_feature)
|
|
|
|
printf("feature done\n");
|
|
|
|
|
2008-06-11 15:17:04 +04:00
|
|
|
if (import_filename)
|
|
|
|
import_marks(import_filename);
|
|
|
|
|
2010-12-17 15:43:06 +03:00
|
|
|
if (import_filename && revs.prune_data.nr)
|
2010-07-17 21:00:50 +04:00
|
|
|
full_tree = 1;
|
|
|
|
|
fast-export: don't handle uninteresting refs
They have been marked as UNINTERESTING for a reason, lets respect
that. Currently the first ref is handled properly, but not the
rest. Assuming that all the refs point at the same commit in the
following example:
% git fast-export master ^uninteresting ^foo ^bar
reset refs/heads/bar
from :0
reset refs/heads/foo
from :0
reset refs/heads/uninteresting
from :0
% git fast-export ^uninteresting ^foo ^bar master
reset refs/heads/master
from :0
reset refs/heads/bar
from :0
reset refs/heads/foo
from :0
Clearly this is wrong; the negative refs should be ignored.
After this patch:
% git fast-export ^uninteresting ^foo ^bar master
# nothing
% git fast-export master ^uninteresting ^foo ^bar
# nothing
And even more, it would only happen if the ref is pointing to exactly
the same commit, but not otherwise:
% git fast-export ^next next
reset refs/heads/next
from :0
% git fast-export ^next next^{commit}
# nothing
% git fast-export ^next next~0
# nothing
% git fast-export ^next next~1
# nothing
% git fast-export ^next next~2
# nothing
The reason this happens is that before traversing the commits,
fast-export checks if any of the refs point to the same object, and any
duplicated ref gets added to a list in order to issue 'reset' commands
after the traversing. Unfortunately, it's not even checking if the
commit is flagged as UNINTERESTING. The fix of course, is to check it.
However, in order to do it properly we need to get the UNINTERESTING
flag from the command line, not from the commit object, because
"^foo bar" will mark the commit 'bar' uninteresting if foo and bar
points at the same commit. rev_cmdline_info, which was introduced
exactly to handle this situation, contains all the information we
need for get_tags_and_duplicates(), plus the ref flag. This way the
rest of the positive refs will remain untouched; it's only the
negative ones that change in behavior.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-11-29 02:23:59 +04:00
|
|
|
get_tags_and_duplicates(&revs.cmdline, &extra_refs);
|
2007-12-02 17:14:13 +03:00
|
|
|
|
2008-02-18 10:31:56 +03:00
|
|
|
if (prepare_revision_walk(&revs))
|
|
|
|
die("revision walk setup failed");
|
2007-12-02 17:14:13 +03:00
|
|
|
revs.diffopt.format_callback = show_filemodify;
|
|
|
|
DIFF_OPT_SET(&revs.diffopt, RECURSIVE);
|
|
|
|
while ((commit = get_revision(&revs))) {
|
|
|
|
if (has_unshown_parent(commit)) {
|
|
|
|
add_object_array(&commit->object, NULL, &commits);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
handle_commit(commit, &revs);
|
|
|
|
handle_tail(&commits, &revs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handle_tags_and_duplicates(&extra_refs);
|
|
|
|
|
2008-06-11 15:17:04 +04:00
|
|
|
if (export_filename)
|
|
|
|
export_marks(export_filename);
|
|
|
|
|
2011-07-16 17:03:33 +04:00
|
|
|
if (use_done_feature)
|
|
|
|
printf("done\n");
|
|
|
|
|
2007-12-02 17:14:13 +03:00
|
|
|
return 0;
|
|
|
|
}
|