setup_revisions: remember whether a ref was positive or not

This will be required by fast-export, when no commits were
exported, but the refs should be set, of course.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Sverre Rabbelier <srabbelier@gmail.com>
This commit is contained in:
Johannes Schindelin
2011-07-23 17:14:47 +02:00
committed by Erik Faye-Lund
parent ab1f43296c
commit 3dcaee328c
2 changed files with 32 additions and 6 deletions

View File

@@ -18,6 +18,8 @@
#include "parse-options.h"
#include "quote.h"
#define REF_HANDLED (ALL_REV_FLAGS + 1)
static const char *fast_export_usage[] = {
N_("git fast-export [rev-list-opts]"),
NULL
@@ -475,6 +477,7 @@ static void handle_tag(const char *name, struct tag *tag)
}
static void get_tags_and_duplicates(struct object_array *pending,
struct string_list *refs,
struct string_list *extra_refs)
{
struct tag *tag;
@@ -526,8 +529,11 @@ static void get_tags_and_duplicates(struct object_array *pending,
if (commit->util)
/* more than one name for the same object */
string_list_append(extra_refs, full_name)->util = commit;
else
else {
commit->util = full_name;
/* we might need to set this ref explicitly */
string_list_append(refs, full_name)->util = commit;
}
}
}
@@ -543,10 +549,29 @@ static void handle_reset(const char *name, struct object *object)
sha1_to_hex(object->sha1));
}
static void handle_tags_and_duplicates(struct string_list *extra_refs)
static void handle_tags_and_duplicates(struct string_list *refs, struct string_list *extra_refs)
{
int i;
/* even if no commits were exported, we need to export the ref */
for (i = refs->nr - 1; i >= 0; i--) {
const char *name = refs->items[i].string;
struct object *object = refs->items[i].util;
if (!(object->flags & REF_HANDLED)) {
if (object->type & OBJ_TAG)
handle_tag(name, (struct tag *)object);
else {
if (!prefixcmp(name, "refs/tags/") &&
(tag_of_filtered_mode != REWRITE ||
!get_object_mark(object)))
continue;
handle_reset(name, object);
object->flags |= REF_HANDLED;
}
}
}
for (i = extra_refs->nr - 1; i >= 0; i--) {
const char *name = extra_refs->items[i].string;
struct object *object = extra_refs->items[i].util;
@@ -636,7 +661,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
{
struct rev_info revs;
struct object_array commits = OBJECT_ARRAY_INIT;
struct string_list extra_refs = STRING_LIST_INIT_NODUP;
struct string_list refs = STRING_LIST_INIT_NODUP, extra_refs = STRING_LIST_INIT_NODUP;
struct commit *commit;
char *export_filename = NULL, *import_filename = NULL;
struct option options[] = {
@@ -686,7 +711,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
if (import_filename && revs.prune_data.nr)
full_tree = 1;
get_tags_and_duplicates(&revs.pending, &extra_refs);
get_tags_and_duplicates(&revs.pending, &refs, &extra_refs);
if (prepare_revision_walk(&revs))
die("revision walk setup failed");
@@ -698,11 +723,12 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
}
else {
handle_commit(commit, &revs);
commit->object.flags |= REF_HANDLED;
handle_tail(&commits, &revs);
}
}
handle_tags_and_duplicates(&extra_refs);
handle_tags_and_duplicates(&refs, &extra_refs);
if (export_filename)
export_marks(export_filename);

View File

@@ -446,7 +446,7 @@ from $(git rev-parse master)
EOF
test_expect_failure 'refs are updated even if no commits need to be exported' '
test_expect_success 'refs are updated even if no commits need to be exported' '
git fast-export master..master > actual &&
test_cmp expected actual
'