From mboxrd@z Thu Jan 1 00:00:00 1970 From: Felipe Contreras Subject: [PATCH v4 05/10] fast-export: add new --refspec option Date: Sun, 27 Oct 2013 01:05:13 -0600 Message-ID: <1382857521-7005-3-git-send-email-felipe.contreras@gmail.com> References: <1382857521-7005-1-git-send-email-felipe.contreras@gmail.com> Cc: Sverre Rabbelier , Richard Hansen , Felipe Contreras To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Sun Oct 27 08:12:18 2013 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VaKWG-0006in-4b for gcvg-git-2@plane.gmane.org; Sun, 27 Oct 2013 08:12:16 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752030Ab3J0HML (ORCPT ); Sun, 27 Oct 2013 03:12:11 -0400 Received: from mail-oa0-f52.google.com ([209.85.219.52]:56783 "EHLO mail-oa0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751207Ab3J0HMH (ORCPT ); Sun, 27 Oct 2013 03:12:07 -0400 Received: by mail-oa0-f52.google.com with SMTP id n10so2440100oag.39 for ; Sun, 27 Oct 2013 00:12:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=84SKOY2/mUBgjrnhI4R7zPeAbr1JyrR6XnPggeWL+c4=; b=KywaoMc1WrMFyC36Kw/XzxP9vWvoloV6ngxZJ2AxnVHNeSuSHrz6atSMCk0uCIu7+f wcOgsqlVbW3SHbBGe3pdVZxZWdDCL1uOHGPo7se1XPypIoStHJpm+dvopWckdjk8bTKk TXYy4pv/zJLCduKhvKz+7xLmYrS+hkA/OXR75Pkbe1WOAoeFVEN0+zt3efkfwp2y37u0 kJFaxyvYS/r7oEeZTX6Q+LihAJa6jYboxXG8xfAqExYCwWUYoawIMIU63tuGoAsZGONy 1UdoyfwhMq0KYzmgZxAD0wzPobOEaFfpbsdK+je3vbXODqc1G430CmEaYtiz1NHi4NQi 7sUg== X-Received: by 10.60.80.8 with SMTP id n8mr9629001oex.33.1382857926064; Sun, 27 Oct 2013 00:12:06 -0700 (PDT) Received: from localhost (187-162-140-241.static.axtel.net. [187.162.140.241]) by mx.google.com with ESMTPSA id m7sm18056580obo.7.2013.10.27.00.12.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 27 Oct 2013 00:12:05 -0700 (PDT) X-Mailer: git-send-email 1.8.4-fc In-Reply-To: <1382857521-7005-1-git-send-email-felipe.contreras@gmail.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: So that we can convert the exported ref names. Signed-off-by: Felipe Contreras --- Documentation/git-fast-export.txt | 4 ++++ builtin/fast-export.c | 30 ++++++++++++++++++++++++++++++ t/t9350-fast-export.sh | 7 +++++++ 3 files changed, 41 insertions(+) diff --git a/Documentation/git-fast-export.txt b/Documentation/git-fast-export.txt index 85f1f30..221506b 100644 --- a/Documentation/git-fast-export.txt +++ b/Documentation/git-fast-export.txt @@ -105,6 +105,10 @@ marks the same across runs. in the commit (as opposed to just listing the files which are different from the commit's first parent). +--refspec:: + Apply the specified refspec to each ref exported. Multiple of them can + be specified. + [...]:: A list of arguments, acceptable to 'git rev-parse' and 'git rev-list', that specifies the specific objects and references diff --git a/builtin/fast-export.c b/builtin/fast-export.c index eea5b8c..b6f623e 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -17,6 +17,7 @@ #include "utf8.h" #include "parse-options.h" #include "quote.h" +#include "remote.h" static const char *fast_export_usage[] = { N_("git fast-export [rev-list-opts]"), @@ -31,6 +32,8 @@ static int use_done_feature; static int no_data; static int full_tree; static struct string_list extra_refs = STRING_LIST_INIT_NODUP; +static struct refspec *refspecs; +static int refspecs_nr; static int parse_opt_signed_tag_mode(const struct option *opt, const char *arg, int unset) @@ -525,6 +528,15 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info) if (dwim_ref(e->name, strlen(e->name), sha1, &full_name) != 1) continue; + if (refspecs) { + char *private; + private = apply_refspecs(refspecs, refspecs_nr, full_name); + if (private) { + free(full_name); + full_name = private; + } + } + commit = get_commit(e, full_name); if (!commit) { warning("%s: Unexpected object of type %s, skipping.", @@ -668,6 +680,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) struct commit *commit; char *export_filename = NULL, *import_filename = NULL; uint32_t lastimportid; + struct string_list refspecs_list = STRING_LIST_INIT_NODUP; struct option options[] = { OPT_INTEGER(0, "progress", &progress, N_("show progress after objects")), @@ -688,6 +701,8 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) OPT_BOOL(0, "use-done-feature", &use_done_feature, N_("Use the done feature to terminate the stream")), OPT_BOOL(0, "no-data", &no_data, N_("Skip output of blob data")), + OPT_STRING_LIST(0, "refspec", &refspecs_list, N_("refspec"), + N_("Apply refspec to exported refs")), OPT_END() }; @@ -707,6 +722,19 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) if (argc > 1) usage_with_options (fast_export_usage, options); + if (refspecs_list.nr) { + const char *refspecs_str[refspecs_list.nr]; + int i; + + for (i = 0; i < refspecs_list.nr; i++) + refspecs_str[i] = refspecs_list.items[i].string; + + refspecs_nr = refspecs_list.nr; + refspecs = parse_fetch_refspec(refspecs_nr, refspecs_str); + + string_list_clear(&refspecs_list, 1); + } + if (use_done_feature) printf("feature done\n"); @@ -741,5 +769,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) if (use_done_feature) printf("done\n"); + free_refspec(refspecs_nr, refspecs); + return 0; } diff --git a/t/t9350-fast-export.sh b/t/t9350-fast-export.sh index 34c2d8f..dc6666f 100755 --- a/t/t9350-fast-export.sh +++ b/t/t9350-fast-export.sh @@ -504,4 +504,11 @@ test_expect_success 'refs are updated even if no commits need to be exported' ' test_cmp expected actual ' +test_expect_success 'use refspec' ' + git fast-export --refspec refs/heads/master:refs/heads/foobar master | \ + grep "^commit " | sort | uniq > actual && + echo "commit refs/heads/foobar" > expected && + test_cmp expected actual +' + test_done -- 1.8.4-fc