From: Sven Verdoolaege <skimo@xxxxxxxxxx> Signed-off-by: Sven Verdoolaege <skimo@xxxxxxxxxx> --- builtin-fetch--tool.c | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 44 insertions(+), 4 deletions(-) diff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c index ed4d5de..3441a4a 100644 --- a/builtin-fetch--tool.c +++ b/builtin-fetch--tool.c @@ -207,6 +207,32 @@ static void remove_keep_on_signal(int signo) raise(signo); } +static char *construct_local_name(const char *remote_ref, const char *remote_nick, + int use_separate_remote) +{ + static char local_ref[PATH_MAX]; + int len = strlen(remote_ref); + + if (len >= 3 && !memcmp(remote_ref+len-3, "^{}", 3)) + return NULL; + if (!strcmp(remote_ref, "HEAD")) + return "REMOTE_HEAD"; + if (!prefixcmp(remote_ref, "refs/heads/")) { + if (snprintf(local_ref, sizeof(local_ref), "refs/%s%s/%s", + use_separate_remote ? "remotes/" : "heads", + use_separate_remote ? remote_nick : "", + remote_ref+11) > sizeof(local_ref)) + die("Local branchname too long"); + } else if (!prefixcmp(remote_ref, "refs/tags/")) { + if (snprintf(local_ref, sizeof(local_ref), "refs/tags/%s", + remote_ref+10) > sizeof(local_ref)) + die("Local branchname too long"); + } else + return NULL; + + return local_ref; +} + static char *find_local_name(const char *remote_name, const char *refs, int *force_p, int *not_for_merge_p) { @@ -261,7 +287,8 @@ static int fetch_native_store(FILE *fp, const char *remote, const char *remote_nick, const char *refs, - int verbose, int force) + int verbose, int force, + int all, int use_separate_remote) { char buffer[1024]; int err = 0; @@ -294,8 +321,12 @@ static int fetch_native_store(FILE *fp, continue; } - local_name = find_local_name(cp, refs, - &single_force, ¬_for_merge); + if (all) + local_name = construct_local_name(cp, remote_nick, + use_separate_remote); + else + local_name = find_local_name(cp, refs, + &single_force, ¬_for_merge); if (!local_name) continue; err |= append_fetch_head(fp, @@ -514,6 +545,8 @@ int cmd_fetch__tool(int argc, const char **argv, const char *prefix) int verbose = 0; int force = 0; int sopt = 0; + int all = 0; + int use_separate_remote = 1; while (1 < argc) { const char *arg = argv[1]; @@ -523,6 +556,12 @@ int cmd_fetch__tool(int argc, const char **argv, const char *prefix) force = 1; else if (!strcmp("-s", arg)) sopt = 1; + else if (!strcmp("--all", arg)) + all = 1; + else if (!strcmp("--use-separate-remote", arg)) + use_separate_remote = 1; + else if (!strcmp("--no-separate-remote", arg)) + use_separate_remote = 0; else break; argc--; @@ -554,7 +593,8 @@ int cmd_fetch__tool(int argc, const char **argv, const char *prefix) return error("fetch-native-store takes 3 args"); fp = fopen(git_path("FETCH_HEAD"), "a"); result = fetch_native_store(fp, argv[2], argv[3], argv[4], - verbose, force); + verbose, force, all, + use_separate_remote); fclose(fp); return result; } -- 1.5.2.rc3.783.gc7476-dirty - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html