summaryrefslogtreecommitdiff
path: root/contrib/examples
diff options
context:
space:
mode:
authorLibravatar Ævar Arnfjörð Bjarmason <avarab@gmail.com>2018-03-25 20:46:53 +0000
committerLibravatar Junio C Hamano <gitster@pobox.com>2018-03-26 13:48:50 -0700
commit49eb8d39c78f161231e63293df60f343d208f409 (patch)
tree877abb15a47d8f0185fffa0103f78a66382a02e9 /contrib/examples
parentSync with Git 2.16.3 (diff)
downloadtgif-49eb8d39c78f161231e63293df60f343d208f409.tar.xz
Remove contrib/examples/*
There were some side discussions at Git Merge this year about how we should just update the README to tell users they can dig these up from the history if the need them, do that. Looking at the "git log" for this directory we get quite a bit more patch churn than we should here, mainly from things fixing various tree-wide issues. There's also confusion on the list occasionally about how these should be treated, "Re: [PATCH 1/4] stash: convert apply to builtin" (<CA+CzEk9QpmHK_TSBwQfEedNqrcVSBp3xY7bdv1YA_KxePiFeXw@mail.gmail.com>) being the latest example of that. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib/examples')
-rw-r--r--contrib/examples/README23
-rw-r--r--contrib/examples/builtin-fetch--tool.c575
-rwxr-xr-xcontrib/examples/git-am.sh975
-rwxr-xr-xcontrib/examples/git-checkout.sh302
-rwxr-xr-xcontrib/examples/git-clean.sh118
-rwxr-xr-xcontrib/examples/git-clone.sh525
-rwxr-xr-xcontrib/examples/git-commit.sh639
-rwxr-xr-xcontrib/examples/git-difftool.perl481
-rwxr-xr-xcontrib/examples/git-fetch.sh379
-rwxr-xr-xcontrib/examples/git-gc.sh37
-rwxr-xr-xcontrib/examples/git-log.sh15
-rwxr-xr-xcontrib/examples/git-ls-remote.sh142
-rwxr-xr-xcontrib/examples/git-merge-ours.sh14
-rwxr-xr-xcontrib/examples/git-merge.sh620
-rwxr-xr-xcontrib/examples/git-notes.sh121
-rwxr-xr-xcontrib/examples/git-pull.sh381
-rwxr-xr-xcontrib/examples/git-remote.perl474
-rwxr-xr-xcontrib/examples/git-repack.sh194
-rwxr-xr-xcontrib/examples/git-rerere.perl284
-rwxr-xr-xcontrib/examples/git-reset.sh106
-rwxr-xr-xcontrib/examples/git-resolve.sh112
-rwxr-xr-xcontrib/examples/git-revert.sh207
-rwxr-xr-xcontrib/examples/git-svnimport.perl976
-rw-r--r--contrib/examples/git-svnimport.txt179
-rwxr-xr-xcontrib/examples/git-tag.sh205
-rwxr-xr-xcontrib/examples/git-verify-tag.sh45
-rwxr-xr-xcontrib/examples/git-whatchanged.sh28
27 files changed, 20 insertions, 8137 deletions
diff --git a/contrib/examples/README b/contrib/examples/README
index 6946f3dd2a..18bc60b021 100644
--- a/contrib/examples/README
+++ b/contrib/examples/README
@@ -1,3 +1,20 @@
-These are original scripted implementations, kept primarily for their
-reference value to any aspiring plumbing users who want to learn how
-pieces can be fit together.
+This directory used to contain scripted implementations of builtins
+that have since been rewritten in C.
+
+They have now been removed, but can be retrieved from an older commit
+that removed them from this directory.
+
+They're interesting for their reference value to any aspiring plumbing
+users who want to learn how pieces can be fit together, but in many
+cases have drifted enough from the actual implementations Git uses to
+be instructive.
+
+Other things that can be useful:
+
+ * Some commands such as git-gc wrap other commands, and what they're
+ doing behind the scenes can be seen by running them under
+ GIT_TRACE=1
+
+ * Doing `git log` on paths matching '*--helper.c' will show
+ incremental effort in the direction of moving existing shell
+ scripts to C.
diff --git a/contrib/examples/builtin-fetch--tool.c b/contrib/examples/builtin-fetch--tool.c
deleted file mode 100644
index 22648c3afb..0000000000
--- a/contrib/examples/builtin-fetch--tool.c
+++ /dev/null
@@ -1,575 +0,0 @@
-#include "builtin.h"
-#include "cache.h"
-#include "refs.h"
-#include "commit.h"
-#include "sigchain.h"
-
-static char *get_stdin(void)
-{
- struct strbuf buf = STRBUF_INIT;
- if (strbuf_read(&buf, 0, 1024) < 0) {
- die_errno("error reading standard input");
- }
- return strbuf_detach(&buf, NULL);
-}
-
-static void show_new(enum object_type type, unsigned char *sha1_new)
-{
- fprintf(stderr, " %s: %s\n", type_name(type),
- find_unique_abbrev(sha1_new, DEFAULT_ABBREV));
-}
-
-static int update_ref_env(const char *action,
- const char *refname,
- unsigned char *sha1,
- unsigned char *oldval)
-{
- char msg[1024];
- const char *rla = getenv("GIT_REFLOG_ACTION");
-
- if (!rla)
- rla = "(reflog update)";
- if (snprintf(msg, sizeof(msg), "%s: %s", rla, action) >= sizeof(msg))
- warning("reflog message too long: %.*s...", 50, msg);
- return update_ref(msg, refname, sha1, oldval, 0,
- UPDATE_REFS_QUIET_ON_ERR);
-}
-
-static int update_local_ref(const char *name,
- const char *new_head,
- const char *note,
- int verbose, int force)
-{
- unsigned char sha1_old[20], sha1_new[20];
- char oldh[41], newh[41];
- struct commit *current, *updated;
- enum object_type type;
-
- if (get_sha1_hex(new_head, sha1_new))
- die("malformed object name %s", new_head);
-
- type = sha1_object_info(sha1_new, NULL);
- if (type < 0)
- die("object %s not found", new_head);
-
- if (!*name) {
- /* Not storing */
- if (verbose) {
- fprintf(stderr, "* fetched %s\n", note);
- show_new(type, sha1_new);
- }
- return 0;
- }
-
- if (get_sha1(name, sha1_old)) {
- const char *msg;
- just_store:
- /* new ref */
- if (!strncmp(name, "refs/tags/", 10))
- msg = "storing tag";
- else
- msg = "storing head";
- fprintf(stderr, "* %s: storing %s\n",
- name, note);
- show_new(type, sha1_new);
- return update_ref_env(msg, name, sha1_new, NULL);
- }
-
- if (!hashcmp(sha1_old, sha1_new)) {
- if (verbose) {
- fprintf(stderr, "* %s: same as %s\n", name, note);
- show_new(type, sha1_new);
- }
- return 0;
- }
-
- if (!strncmp(name, "refs/tags/", 10)) {
- fprintf(stderr, "* %s: updating with %s\n", name, note);
- show_new(type, sha1_new);
- return update_ref_env("updating tag", name, sha1_new, NULL);
- }
-
- current = lookup_commit_reference(sha1_old);
- updated = lookup_commit_reference(sha1_new);
- if (!current || !updated)
- goto just_store;
-
- strcpy(oldh, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));
- strcpy(newh, find_unique_abbrev(sha1_new, DEFAULT_ABBREV));
-
- if (in_merge_bases(current, updated)) {
- fprintf(stderr, "* %s: fast-forward to %s\n",
- name, note);
- fprintf(stderr, " old..new: %s..%s\n", oldh, newh);
- return update_ref_env("fast-forward", name, sha1_new, sha1_old);
- }
- if (!force) {
- fprintf(stderr,
- "* %s: not updating to non-fast-forward %s\n",
- name, note);
- fprintf(stderr,
- " old...new: %s...%s\n", oldh, newh);
- return 1;
- }
- fprintf(stderr,
- "* %s: forcing update to non-fast-forward %s\n",
- name, note);
- fprintf(stderr, " old...new: %s...%s\n", oldh, newh);
- return update_ref_env("forced-update", name, sha1_new, sha1_old);
-}
-
-static int append_fetch_head(FILE *fp,
- const char *head, const char *remote,
- const char *remote_name, const char *remote_nick,
- const char *local_name, int not_for_merge,
- int verbose, int force)
-{
- struct commit *commit;
- int remote_len, i, note_len;
- unsigned char sha1[20];
- char note[1024];
- const char *what, *kind;
-
- if (get_sha1(head, sha1))
- return error("Not a valid object name: %s", head);
- commit = lookup_commit_reference_gently(sha1, 1);
- if (!commit)
- not_for_merge = 1;
-
- if (!strcmp(remote_name, "HEAD")) {
- kind = "";
- what = "";
- }
- else if (!strncmp(remote_name, "refs/heads/", 11)) {
- kind = "branch";
- what = remote_name + 11;
- }
- else if (!strncmp(remote_name, "refs/tags/", 10)) {
- kind = "tag";
- what = remote_name + 10;
- }
- else if (!strncmp(remote_name, "refs/remotes/", 13)) {
- kind = "remote-tracking branch";
- what = remote_name + 13;
- }
- else {
- kind = "";
- what = remote_name;
- }
-
- remote_len = strlen(remote);
- for (i = remote_len - 1; remote[i] == '/' && 0 <= i; i--)
- ;
- remote_len = i + 1;
- if (4 < i && !strncmp(".git", remote + i - 3, 4))
- remote_len = i - 3;
-
- note_len = 0;
- if (*what) {
- if (*kind)
- note_len += sprintf(note + note_len, "%s ", kind);
- note_len += sprintf(note + note_len, "'%s' of ", what);
- }
- note_len += sprintf(note + note_len, "%.*s", remote_len, remote);
- fprintf(fp, "%s\t%s\t%s\n",
- sha1_to_hex(commit ? commit->object.sha1 : sha1),
- not_for_merge ? "not-for-merge" : "",
- note);
- return update_local_ref(local_name, head, note, verbose, force);
-}
-
-static char *keep;
-static void remove_keep(void)
-{
- if (keep && *keep)
- unlink(keep);
-}
-
-static void remove_keep_on_signal(int signo)
-{
- remove_keep();
- sigchain_pop(signo);
- raise(signo);
-}
-
-static char *find_local_name(const char *remote_name, const char *refs,
- int *force_p, int *not_for_merge_p)
-{
- const char *ref = refs;
- int len = strlen(remote_name);
-
- while (ref) {
- const char *next;
- int single_force, not_for_merge;
-
- while (*ref == '\n')
- ref++;
- if (!*ref)
- break;
- next = strchr(ref, '\n');
-
- single_force = not_for_merge = 0;
- if (*ref == '+') {
- single_force = 1;
- ref++;
- }
- if (*ref == '.') {
- not_for_merge = 1;
- ref++;
- if (*ref == '+') {
- single_force = 1;
- ref++;
- }
- }
- if (!strncmp(remote_name, ref, len) && ref[len] == ':') {
- const char *local_part = ref + len + 1;
- int retlen;
-
- if (!next)
- retlen = strlen(local_part);
- else
- retlen = next - local_part;
- *force_p = single_force;
- *not_for_merge_p = not_for_merge;
- return xmemdupz(local_part, retlen);
- }
- ref = next;
- }
- return NULL;
-}
-
-static int fetch_native_store(FILE *fp,
- const char *remote,
- const char *remote_nick,
- const char *refs,
- int verbose, int force)
-{
- char buffer[1024];
- int err = 0;
-
- sigchain_push_common(remove_keep_on_signal);
- atexit(remove_keep);
-
- while (fgets(buffer, sizeof(buffer), stdin)) {
- int len;
- char *cp;
- char *local_name;
- int single_force, not_for_merge;
-
- for (cp = buffer; *cp && !isspace(*cp); cp++)
- ;
- if (*cp)
- *cp++ = 0;
- len = strlen(cp);
- if (len && cp[len-1] == '\n')
- cp[--len] = 0;
- if (!strcmp(buffer, "failed"))
- die("Fetch failure: %s", remote);
- if (!strcmp(buffer, "pack"))
- continue;
- if (!strcmp(buffer, "keep")) {
- char *od = get_object_directory();
- int len = strlen(od) + strlen(cp) + 50;
- keep = xmalloc(len);
- sprintf(keep, "%s/pack/pack-%s.keep", od, cp);
- continue;
- }
-
- local_name = find_local_name(cp, refs,
- &single_force, &not_for_merge);
- if (!local_name)
- continue;
- err |= append_fetch_head(fp,
- buffer, remote, cp, remote_nick,
- local_name, not_for_merge,
- verbose, force || single_force);
- }
- return err;
-}
-
-static int parse_reflist(const char *reflist)
-{
- const char *ref;
-
- printf("refs='");
- for (ref = reflist; ref; ) {
- const char *next;
- while (*ref && isspace(*ref))
- ref++;
- if (!*ref)
- break;
- for (next = ref; *next && !isspace(*next); next++)
- ;
- printf("\n%.*s", (int)(next - ref), ref);
- ref = next;
- }
- printf("'\n");
-
- printf("rref='");
- for (ref = reflist; ref; ) {
- const char *next, *colon;
- while (*ref && isspace(*ref))
- ref++;
- if (!*ref)
- break;
- for (next = ref; *next && !isspace(*next); next++)
- ;
- if (*ref == '.')
- ref++;
- if (*ref == '+')
- ref++;
- colon = strchr(ref, ':');
- putchar('\n');
- printf("%.*s", (int)((colon ? colon : next) - ref), ref);
- ref = next;
- }
- printf("'\n");
- return 0;
-}
-
-static int expand_refs_wildcard(const char *ls_remote_result, int numrefs,
- const char **refs)
-{
- int i, matchlen, replacelen;
- int found_one = 0;
- const char *remote = *refs++;
- numrefs--;
-
- if (numrefs == 0) {
- fprintf(stderr, "Nothing specified for fetching with remote.%s.fetch\n",
- remote);
- printf("empty\n");
- }
-
- for (i = 0; i < numrefs; i++) {
- const char *ref = refs[i];
- const char *lref = ref;
- const char *colon;
- const char *tail;
- const char *ls;
- const char *next;
-
- if (*lref == '+')
- lref++;
- colon = strchr(lref, ':');
- tail = lref + strlen(lref);
- if (!(colon &&
- 2 < colon - lref &&
- colon[-1] == '*' &&
- colon[-2] == '/' &&
- 2 < tail - (colon + 1) &&
- tail[-1] == '*' &&
- tail[-2] == '/')) {
- /* not a glob */
- if (!found_one++)
- printf("explicit\n");
- printf("%s\n", ref);
- continue;
- }
-
- /* glob */
- if (!found_one++)
- printf("glob\n");
-
- /* lref to colon-2 is remote hierarchy name;
- * colon+1 to tail-2 is local.
- */
- matchlen = (colon-1) - lref;
- replacelen = (tail-1) - (colon+1);
- for (ls = ls_remote_result; ls; ls = next) {
- const char *eol;
- unsigned char sha1[20];
- int namelen;
-
- while (*ls && isspace(*ls))
- ls++;
- next = strchr(ls, '\n');
- eol = !next ? (ls + strlen(ls)) : next;
- if (!memcmp("^{}", eol-3, 3))
- continue;
- if (eol - ls < 40)
- continue;
- if (get_sha1_hex(ls, sha1))
- continue;
- ls += 40;
- while (ls < eol && isspace(*ls))
- ls++;
- /* ls to next (or eol) is the name.
- * is it identical to lref to colon-2?
- */
- if ((eol - ls) <= matchlen ||
- strncmp(ls, lref, matchlen))
- continue;
-
- /* Yes, it is a match */
- namelen = eol - ls;
- if (lref != ref)
- putchar('+');
- printf("%.*s:%.*s%.*s\n",
- namelen, ls,
- replacelen, colon + 1,
- namelen - matchlen, ls + matchlen);
- }
- }
- return 0;
-}
-
-static int pick_rref(int sha1_only, const char *rref, const char *ls_remote_result)
-{
- int err = 0;
- int lrr_count = lrr_count, i, pass;
- const char *cp;
- struct lrr {
- const char *line;
- const char *name;
- int namelen;
- int shown;
- } *lrr_list = lrr_list;
-
- for (pass = 0; pass < 2; pass++) {
- /* pass 0 counts and allocates, pass 1 fills... */
- cp = ls_remote_result;
- i = 0;
- while (1) {
- const char *np;
- while (*cp && isspace(*cp))
- cp++;
- if (!*cp)
- break;
- np = strchrnul(cp, '\n');
- if (pass) {
- lrr_list[i].line = cp;
- lrr_list[i].name = cp + 41;
- lrr_list[i].namelen = np - (cp + 41);
- }
- i++;
- cp = np;
- }
- if (!pass) {
- lrr_count = i;
- lrr_list = xcalloc(lrr_count, sizeof(*lrr_list));
- }
- }
-
- while (1) {
- const char *next;
- int rreflen;
- int i;
-
- while (*rref && isspace(*rref))
- rref++;
- if (!*rref)
- break;
- next = strchrnul(rref, '\n');
- rreflen = next - rref;
-
- for (i = 0; i < lrr_count; i++) {
- struct lrr *lrr = &(lrr_list[i]);
-
- if (rreflen == lrr->namelen &&
- !memcmp(lrr->name, rref, rreflen)) {
- if (!lrr->shown)
- printf("%.*s\n",
- sha1_only ? 40 : lrr->namelen + 41,
- lrr->line);
- lrr->shown = 1;
- break;
- }
- }
- if (lrr_count <= i) {
- error("pick-rref: %.*s not found", rreflen, rref);
- err = 1;
- }
- rref = next;
- }
- free(lrr_list);
- return err;
-}
-
-int cmd_fetch__tool(int argc, const char **argv, const char *prefix)
-{
- int verbose = 0;
- int force = 0;
- int sopt = 0;
-
- while (1 < argc) {
- const char *arg = argv[1];
- if (!strcmp("-v", arg))
- verbose = 1;
- else if (!strcmp("-f", arg))
- force = 1;
- else if (!strcmp("-s", arg))
- sopt = 1;
- else
- break;
- argc--;
- argv++;
- }
-
- if (argc <= 1)
- return error("Missing subcommand");
-
- if (!strcmp("append-fetch-head", argv[1])) {
- int result;
- FILE *fp;
- char *filename;
-
- if (argc != 8)
- return error("append-fetch-head takes 6 args");
- filename = git_path_fetch_head();
- fp = fopen(filename, "a");
- if (!fp)
- return error("cannot open %s: %s", filename, strerror(errno));
- result = append_fetch_head(fp, argv[2], argv[3],
- argv[4], argv[5],
- argv[6], !!argv[7][0],
- verbose, force);
- fclose(fp);
- return result;
- }
- if (!strcmp("native-store", argv[1])) {
- int result;
- FILE *fp;
- char *filename;
-
- if (argc != 5)
- return error("fetch-native-store takes 3 args");
- filename = git_path_fetch_head();
- fp = fopen(filename, "a");
- if (!fp)
- return error("cannot open %s: %s", filename, strerror(errno));
- result = fetch_native_store(fp, argv[2], argv[3], argv[4],
- verbose, force);
- fclose(fp);
- return result;
- }
- if (!strcmp("parse-reflist", argv[1])) {
- const char *reflist;
- if (argc != 3)
- return error("parse-reflist takes 1 arg");
- reflist = argv[2];
- if (!strcmp(reflist, "-"))
- reflist = get_stdin();
- return parse_reflist(reflist);
- }
- if (!strcmp("pick-rref", argv[1])) {
- const char *ls_remote_result;
- if (argc != 4)
- return error("pick-rref takes 2 args");
- ls_remote_result = argv[3];
- if (!strcmp(ls_remote_result, "-"))
- ls_remote_result = get_stdin();
- return pick_rref(sopt, argv[2], ls_remote_result);
- }
- if (!strcmp("expand-refs-wildcard", argv[1])) {
- const char *reflist;
- if (argc < 4)
- return error("expand-refs-wildcard takes at least 2 args");
- reflist = argv[2];
- if (!strcmp(reflist, "-"))
- reflist = get_stdin();
- return expand_refs_wildcard(reflist, argc - 3, argv + 3);
- }
-
- return error("Unknown subcommand: %s", argv[1]);
-}
diff --git a/contrib/examples/git-am.sh b/contrib/examples/git-am.sh
deleted file mode 100755
index dd539f1a8a..0000000000
--- a/contrib/examples/git-am.sh
+++ /dev/null
@@ -1,975 +0,0 @@
-#!/bin/sh
-#
-# Copyright (c) 2005, 2006 Junio C Hamano
-
-SUBDIRECTORY_OK=Yes
-OPTIONS_KEEPDASHDASH=
-OPTIONS_STUCKLONG=t
-OPTIONS_SPEC="\
-git am [options] [(<mbox>|<Maildir>)...]
-git am [options] (--continue | --skip | --abort)
---
-i,interactive run interactively
-b,binary* (historical option -- no-op)
-3,3way allow fall back on 3way merging if needed
-q,quiet be quiet
-s,signoff add a Signed-off-by line to the commit message
-u,utf8 recode into utf8 (default)
-k,keep pass -k flag to git-mailinfo
-keep-non-patch pass -b flag to git-mailinfo
-m,message-id pass -m flag to git-mailinfo
-keep-cr pass --keep-cr flag to git-mailsplit for mbox format
-no-keep-cr do not pass --keep-cr flag to git-mailsplit independent of am.keepcr
-c,scissors strip everything before a scissors line
-whitespace= pass it through git-apply
-ignore-space-change pass it through git-apply
-ignore-whitespace pass it through git-apply
-directory= pass it through git-apply
-exclude= pass it through git-apply
-include= pass it through git-apply
-C= pass it through git-apply
-p= pass it through git-apply
-patch-format= format the patch(es) are in
-reject pass it through git-apply
-resolvemsg= override error message when patch failure occurs
-continue continue applying patches after resolving a conflict
-r,resolved synonyms for --continue
-skip skip the current patch
-abort restore the original branch and abort the patching operation.
-committer-date-is-author-date lie about committer date
-ignore-date use current timestamp for author date
-rerere-autoupdate update the index with reused conflict resolution if possible
-S,gpg-sign? GPG-sign commits
-rebasing* (internal use for git-rebase)"
-
-. git-sh-setup
-. git-sh-i18n
-prefix=$(git rev-parse --show-prefix)
-set_reflog_action am
-require_work_tree
-cd_to_toplevel
-
-git var GIT_COMMITTER_IDENT >/dev/null ||
- die "$(gettext "You need to set your committer info first")"
-
-if git rev-parse --verify -q HEAD >/dev/null
-then
- HAS_HEAD=yes
-else
- HAS_HEAD=
-fi
-
-cmdline="git am"
-if test '' != "$interactive"
-then
- cmdline="$cmdline -i"
-fi
-if test '' != "$threeway"
-then
- cmdline="$cmdline -3"
-fi
-
-empty_tree=4b825dc642cb6eb9a060e54bf8d69288fbee4904
-
-sq () {
- git rev-parse --sq-quote "$@"
-}
-
-stop_here () {
- echo "$1" >"$dotest/next"
- git rev-parse --verify -q HEAD >"$dotest/abort-safety"
- exit 1
-}
-
-safe_to_abort () {
- if test -f "$dotest/dirtyindex"
- then
- return 1
- fi
-
- if ! test -f "$dotest/abort-safety"
- then
- return 0
- fi
-
- abort_safety=$(cat "$dotest/abort-safety")
- if test "z$(git rev-parse --verify -q HEAD)" = "z$abort_safety"
- then
- return 0
- fi
- gettextln "You seem to have moved HEAD since the last 'am' failure.
-Not rewinding to ORIG_HEAD" >&2
- return 1
-}
-
-stop_here_user_resolve () {
- if [ -n "$resolvemsg" ]; then
- printf '%s\n' "$resolvemsg"
- stop_here $1
- fi
- eval_gettextln "When you have resolved this problem, run \"\$cmdline --continue\".
-If you prefer to skip this patch, run \"\$cmdline --skip\" instead.
-To restore the original branch and stop patching, run \"\$cmdline --abort\"."
-
- stop_here $1
-}
-
-go_next () {
- rm -f "$dotest/$msgnum" "$dotest/msg" "$dotest/msg-clean" \
- "$dotest/patch" "$dotest/info"
- echo "$next" >"$dotest/next"
- this=$next
-}
-
-cannot_fallback () {
- echo "$1"
- gettextln "Cannot fall back to three-way merge."
- exit 1
-}
-
-fall_back_3way () {
- O_OBJECT=$(cd "$GIT_OBJECT_DIRECTORY" && pwd)
-
- rm -fr "$dotest"/patch-merge-*
- mkdir "$dotest/patch-merge-tmp-dir"
-
- # First see if the patch records the index info that we can use.
- cmd="git apply $git_apply_opt --build-fake-ancestor" &&
- cmd="$cmd "'"$dotest/patch-merge-tmp-index" "$dotest/patch"' &&
- eval "$cmd" &&
- GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
- git write-tree >"$dotest/patch-merge-base+" ||
- cannot_fallback "$(gettext "Repository lacks necessary blobs to fall back on 3-way merge.")"
-
- say "$(gettext "Using index info to reconstruct a base tree...")"
-
- cmd='GIT_INDEX_FILE="$dotest/patch-merge-tmp-index"'
-
- if test -z "$GIT_QUIET"
- then
- eval "$cmd git diff-index --cached --diff-filter=AM --name-status HEAD"
- fi
-
- cmd="$cmd git apply --cached $git_apply_opt"' <"$dotest/patch"'
- if eval "$cmd"
- then
- mv "$dotest/patch-merge-base+" "$dotest/patch-merge-base"
- mv "$dotest/patch-merge-tmp-index" "$dotest/patch-merge-index"
- else
- cannot_fallback "$(gettext "Did you hand edit your patch?
-It does not apply to blobs recorded in its index.")"
- fi
-
- test -f "$dotest/patch-merge-index" &&
- his_tree=$(GIT_INDEX_FILE="$dotest/patch-merge-index" git write-tree) &&
- orig_tree=$(cat "$dotest/patch-merge-base") &&
- rm -fr "$dotest"/patch-merge-* || exit 1
-
- say "$(gettext "Falling back to patching base and 3-way merge...")"
-
- # This is not so wrong. Depending on which base we picked,
- # orig_tree may be wildly different from ours, but his_tree
- # has the same set of wildly different changes in parts the
- # patch did not touch, so recursive ends up canceling them,
- # saying that we reverted all those changes.
-
- eval GITHEAD_$his_tree='"$FIRSTLINE"'
- export GITHEAD_$his_tree
- if test -n "$GIT_QUIET"
- then
- GIT_MERGE_VERBOSITY=0 && export GIT_MERGE_VERBOSITY
- fi
- our_tree=$(git rev-parse --verify -q HEAD || echo $empty_tree)
- git-merge-recursive $orig_tree -- $our_tree $his_tree || {
- git rerere $allow_rerere_autoupdate
- die "$(gettext "Failed to merge in the changes.")"
- }
- unset GITHEAD_$his_tree
-}
-
-clean_abort () {
- test $# = 0 || echo >&2 "$@"
- rm -fr "$dotest"
- exit 1
-}
-
-patch_format=
-
-check_patch_format () {
- # early return if patch_format was set from the command line
- if test -n "$patch_format"
- then
- return 0
- fi
-
- # we default to mbox format if input is from stdin and for
- # directories
- if test $# = 0 || test "x$1" = "x-" || test -d "$1"
- then
- patch_format=mbox
- return 0
- fi
-
- # otherwise, check the first few non-blank lines of the first
- # patch to try to detect its format
- {
- # Start from first line containing non-whitespace
- l1=
- while test -z "$l1"
- do
- read l1 || break
- done
- read l2
- read l3
- case "$l1" in
- "From "* | "From: "*)
- patch_format=mbox
- ;;
- '# This series applies on GIT commit'*)
- patch_format=stgit-series
- ;;
- "# HG changeset patch")
- patch_format=hg
- ;;
- *)
- # if the second line is empty and the third is
- # a From, Author or Date entry, this is very
- # likely an StGIT patch
- case "$l2,$l3" in
- ,"From: "* | ,"Author: "* | ,"Date: "*)
- patch_format=stgit
- ;;
- *)
- ;;
- esac
- ;;
- esac
- if test -z "$patch_format" &&
- test -n "$l1" &&
- test -n "$l2" &&
- test -n "$l3"
- then
- # This begins with three non-empty lines. Is this a
- # piece of e-mail a-la RFC2822? Grab all the headers,
- # discarding the indented remainder of folded lines,
- # and see if it looks like that they all begin with the
- # header field names...
- tr -d '\015' <"$1" |
- sed -n -e '/^$/q' -e '/^[ ]/d' -e p |
- sane_egrep -v '^[!-9;-~]+:' >/dev/null ||
- patch_format=mbox
- fi
- } < "$1" || clean_abort
-}
-
-split_patches () {
- case "$patch_format" in
- mbox)
- if test t = "$keepcr"
- then
- keep_cr=--keep-cr
- else
- keep_cr=
- fi
- git mailsplit -d"$prec" -o"$dotest" -b $keep_cr -- "$@" > "$dotest/last" ||
- clean_abort
- ;;
- stgit-series)
- if test $# -ne 1
- then
- clean_abort "$(gettext "Only one StGIT patch series can be applied at once")"
- fi
- series_dir=$(dirname "$1")
- series_file="$1"
- shift
- {
- set x
- while read filename
- do
- set "$@" "$series_dir/$filename"
- done
- # remove the safety x
- shift
- # remove the arg coming from the first-line comment
- shift
- } < "$series_file" || clean_abort
- # set the patch format appropriately
- patch_format=stgit
- # now handle the actual StGIT patches
- split_patches "$@"
- ;;
- stgit)
- this=0
- test 0 -eq "$#" && set -- -
- for stgit in "$@"
- do
- this=$(expr "$this" + 1)
- msgnum=$(printf "%0${prec}d" $this)
- # Perl version of StGIT parse_patch. The first nonemptyline
- # not starting with Author, From or Date is the
- # subject, and the body starts with the next nonempty
- # line not starting with Author, From or Date
- @@PERL@@ -ne 'BEGIN { $subject = 0 }
- if ($subject > 1) { print ; }
- elsif (/^\s+$/) { next ; }
- elsif (/^Author:/) { s/Author/From/ ; print ;}
- elsif (/^(From|Date)/) { print ; }
- elsif ($subject) {
- $subject = 2 ;
- print "\n" ;
- print ;
- } else {
- print "Subject: ", $_ ;
- $subject = 1;
- }
- ' -- "$stgit" >"$dotest/$msgnum" || clean_abort
- done
- echo "$this" > "$dotest/last"
- this=
- msgnum=
- ;;
- hg)
- this=0
- test 0 -eq "$#" && set -- -
- for hg in "$@"
- do
- this=$(( $this + 1 ))
- msgnum=$(printf "%0${prec}d" $this)
- # hg stores changeset metadata in #-commented lines preceding
- # the commit message and diff(s). The only metadata we care about
- # are the User and Date (Node ID and Parent are hashes which are
- # only relevant to the hg repository and thus not useful to us)
- # Since we cannot guarantee that the commit message is in
- # g