{"thread":{"id":"6019","subject":"[PATCH] Make git-branch a builtin","startedAt":"2006-10-23T21:40:26Z","lastAt":"2006-10-24T17:00:51Z","messageCount":11,"participants":["Lars Hjemli","Shawn Pearce","Junio C Hamano","Petr Baudis"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"29770","messageId":"11616396262982-git-send-email-hjemli@gmail.com","threadId":"6019","inReplyTo":null,"subject":"[PATCH] Make git-branch a builtin","fromName":"Lars Hjemli","fromEmail":"hjemli@gmail.com","sentAt":"2006-10-23T21:40:26Z","receivedAt":"2006-10-23T21:40:26Z","isPatch":true,"sender":{"key":"hjemli@gmail.com","avatar":null},"body":"This replaces git-branch.sh with builtin-branch.c\n\nThe changes is basically a patch from Kristian Høgsberg, updated\nto apply onto current 'next'\n\nSigned-off-by: Lars Hjemli <hjemli@gmail.com>\n---\n Makefile         |    3 +-\n builtin-branch.c |  217 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n builtin.h        |    1 +\n git-branch.sh    |  131 --------------------------------\n git.c            |    1 +\n 5 files changed, 221 insertions(+), 132 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 36b9e06..e249d34 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -158,7 +158,7 @@ BASIC_CFLAGS =\n BASIC_LDFLAGS =\n \n SCRIPT_SH = \\\n-\tgit-bisect.sh git-branch.sh git-checkout.sh \\\n+\tgit-bisect.sh git-checkout.sh \\\n \tgit-cherry.sh git-clean.sh git-clone.sh git-commit.sh \\\n \tgit-fetch.sh \\\n \tgit-ls-remote.sh \\\n@@ -270,6 +270,7 @@ BUILTIN_OBJS = \\\n \tbuiltin-annotate.o \\\n \tbuiltin-apply.o \\\n \tbuiltin-archive.o \\\n+\tbuiltin-branch.o \\\n \tbuiltin-cat-file.o \\\n \tbuiltin-checkout-index.o \\\n \tbuiltin-check-ref-format.o \\\ndiff --git a/builtin-branch.c b/builtin-branch.c\nnew file mode 100755\nindex 0000000..3105efd\n--- /dev/null\n+++ b/builtin-branch.c\n@@ -0,0 +1,217 @@\n+/*\n+ * Builtin \"git branch\"\n+ *\n+ * Copyright (c) 2006 Kristian Høgsberg <krh@redhat.com>\n+ * Based on git-branch.sh by Junio C Hamano.\n+ */\n+\n+#include \"cache.h\"\n+#include \"refs.h\"\n+#include \"commit.h\"\n+#include \"builtin.h\"\n+\n+static const char builtin_branch_usage[] =\n+\"git-branch [(-d | -D) <branchname>] | [[-f] <branchname> [<start-point>]] | -r\";\n+\n+\n+static const char *head;\n+static unsigned char head_sha1[20];\n+\n+static int in_merge_bases(const unsigned char *sha1,\n+\t\t\t  struct commit *rev1,\n+\t\t\t  struct commit *rev2)\n+{\n+\tstruct commit_list *bases, *b;\n+\tint ret = 0;\n+\n+\tbases = get_merge_bases(rev1, rev2, 1);\n+\tfor (b = bases; b; b = b->next) {\n+\t\tif (!hashcmp(sha1, b->item->object.sha1)) {\n+\t\t\tret = 1;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\tfree_commit_list(bases);\n+\treturn ret;\n+}\n+\n+static void delete_branches(int argc, const char **argv, int force)\n+{\n+\tstruct commit *rev, *head_rev;\n+\tunsigned char sha1[20];\n+\tconst char *name;\n+\tint i;\n+\n+\thead_rev = lookup_commit_reference(head_sha1);\n+\tfor (i = 0; i < argc; i++) {\n+\t\tif (!strcmp(head, argv[i]))\n+\t\t\tdie(\"Cannot delete the branch you are currently on.\");\n+\n+\t\tname = xstrdup(mkpath(\"refs/heads/%s\", argv[i]));\n+\t\tif (!resolve_ref(name, sha1, 1, NULL))\n+\t\t\tdie(\"Branch '%s' not found.\", argv[i]);\n+\n+\t\trev = lookup_commit_reference(sha1);\n+\t\tif (!rev || !head_rev)\n+\t\t\tdie(\"Couldn't look up commit objects.\");\n+\n+\t\t/* This checks whether the merge bases of branch and\n+\t\t * HEAD contains branch -- which means that the HEAD\n+\t\t * contains everything in both.\n+\t\t */\n+\n+\t\tif (!force &&\n+\t\t    !in_merge_bases(sha1, rev, head_rev)) {\n+\t\t\tfprintf(stderr,\n+\t\t\t\t\"The branch '%s' is not a strict subset of your current HEAD.\\n\"\n+\t\t\t\t\"If you are sure you want to delete it, run 'git branch -D %s'.\\n\",\n+\t\t\t\targv[i], argv[i]);\n+\t\t\texit(1);\n+\t\t}\n+\n+\t\tif (delete_ref(name, sha1))\n+\t\t\tprintf(\"Error deleting branch '%s'\\n\", argv[i]);\n+\t\telse\n+\t\t\tprintf(\"Deleted branch %s.\\n\", argv[i]);\n+\t\t\t\n+\t\tfree(name);\n+\t}\n+}\n+\n+static int ref_index, ref_alloc;\n+static char **ref_list;\n+\n+static int append_ref(const char *refname, const unsigned char *sha1, int flags, \n+\t\tvoid *cb_data)\n+{\n+\tif (ref_index >= ref_alloc) {\n+\t\tref_alloc = ref_alloc > 0 ? ref_alloc * 2 : 16;\n+\t\tref_list = xrealloc(ref_list, ref_alloc * sizeof(char *));\n+\t}\n+\n+\tref_list[ref_index++] = xstrdup(refname);\n+\n+\treturn 0;\n+}\n+\n+static int ref_cmp(const void *r1, const void *r2)\n+{\n+\treturn strcmp(*(char **)r1, *(char **)r2);\n+}\n+\n+static void print_ref_list(int remote_only)\n+{\n+\tint i;\n+\n+\tif (remote_only)\n+\t\tfor_each_remote_ref(append_ref, NULL);\n+\telse\n+\t\tfor_each_branch_ref(append_ref, NULL);\n+\n+\tqsort(ref_list, ref_index, sizeof(char *), ref_cmp);\n+\n+\tfor (i = 0; i < ref_index; i++) {\n+\t\tif (!strcmp(ref_list[i], head))\n+\t\t\tprintf(\"* %s\\n\", ref_list[i]);\n+\t\telse\n+\t\t\tprintf(\"  %s\\n\", ref_list[i]);\n+\t}\n+}\n+\n+static void create_branch(const char *name, const char *start,\n+\t\t\t  int force, int reflog)\n+{\n+\tstruct ref_lock *lock;\n+\tunsigned char sha1[20];\n+\tchar ref[PATH_MAX], msg[PATH_MAX + 20];\n+\n+\tsnprintf(ref, sizeof ref, \"refs/heads/%s\", name);\n+\tif (check_ref_format(ref))\n+\t\tdie(\"'%s' is not a valid branch name.\", name);\n+\n+\tif (resolve_ref(ref, sha1, 1, NULL)) {\n+\t\tif (!force)\n+\t\t\tdie(\"A branch named '%s' already exists.\", name);\n+\t\telse if (!strcmp(head, name))\n+\t\t\tdie(\"Cannot force update the current branch.\");\n+\t}\n+\n+\tif (get_sha1(start, sha1))\n+\t\tdie(\"Not a valid branch point: '%s'.\", start);\n+\n+\tlock = lock_any_ref_for_update(ref, NULL);\n+\tif (!lock)\n+\t\tdie(\"Failed to lock ref for update: %s.\", strerror(errno));\n+\t\t\n+\tif (reflog){\n+\t\tlog_all_ref_updates = 1;\n+\t\tsnprintf(msg, sizeof msg, \"branch: Created from %s\", start);\n+\t}\n+\n+\tif (write_ref_sha1(lock, sha1, msg) < 0)\n+\t\tdie(\"Failed to write ref: %s.\", strerror(errno));\n+}\n+\n+int cmd_branch(int argc, const char **argv, const char *prefix)\n+{\n+\tint delete = 0, force_delete = 0, force_create = 0, remote_only = 0;\n+\tint reflog = 0;\n+\tint i, prefix_length;\n+\n+\tgit_config(git_default_config);\n+\n+\tfor (i = 1; i < argc; i++) {\n+\t\tconst char *arg = argv[i];\n+\n+\t\tif (arg[0] != '-')\n+\t\t\tbreak;\n+\t\tif (!strcmp(arg, \"--\")) {\n+\t\t\ti++;\n+\t\t\tbreak;\n+\t\t}\n+\t\tif (!strcmp(arg, \"-d\")) {\n+\t\t\tdelete = 1;\n+\t\t\tcontinue;\n+\t\t}\n+\t\tif (!strcmp(arg, \"-D\")) {\n+\t\t\tdelete = 1;\n+\t\t\tforce_delete = 1;\n+\t\t\tcontinue;\n+\t\t}\n+\t\tif (!strcmp(arg, \"-f\")) {\n+\t\t\tforce_create = 1;\n+\t\t\tcontinue;\n+\t\t}\n+\t\tif (!strcmp(arg, \"-r\")) {\n+\t\t\tremote_only = 1;\n+\t\t\tcontinue;\n+\t\t}\n+\t\tif (!strcmp(arg, \"-l\")) {\n+\t\t\treflog = 1;\n+\t\t\tcontinue;\n+\t\t}\n+\t\tusage(builtin_branch_usage);\n+\t}\n+\n+\thead = xstrdup(resolve_ref(\"HEAD\", head_sha1, 0, NULL));\n+\tif (!head)\n+\t\tdie(\"Failed to resolve HEAD as a valid ref.\");\n+\tif (strncmp(head, \"refs/heads/\", 11))\n+\t\tdie(\"HEAD not found below refs/heads!\");\n+\t\t\n+\thead += 11;\n+\t\n+\tif (delete)\n+\t\tdelete_branches(argc - i, argv + i, force_delete);\n+\telse if (i == argc)\n+\t\tprint_ref_list(remote_only);\n+\telse if (i == argc - 1)\n+\t\tcreate_branch(argv[i], head, force_create, reflog);\n+\telse if (i == argc - 2)\n+\t\tcreate_branch(argv[i], argv[i + 1], force_create, reflog);\n+\telse\n+\t\tusage(builtin_branch_usage);\n+\n+\treturn 0;\n+}\ndiff --git a/builtin.h b/builtin.h\nindex 9683a7c..144d299 100644\n--- a/builtin.h\n+++ b/builtin.h\n@@ -15,6 +15,7 @@ extern int write_tree(unsigned char *sha\n extern int cmd_add(int argc, const char **argv, const char *prefix);\n extern int cmd_annotate(int argc, const char **argv, const char *prefix);\n extern int cmd_apply(int argc, const char **argv, const char *prefix);\n+extern int cmd_branch(int argc, const char **argv, const char *prefix);\n extern int cmd_archive(int argc, const char **argv, const char *prefix);\n extern int cmd_cat_file(int argc, const char **argv, const char *prefix);\n extern int cmd_checkout_index(int argc, const char **argv, const char *prefix);\ndiff --git a/git-branch.sh b/git-branch.sh\ndeleted file mode 100755\nindex 4379a07..0000000\n--- a/git-branch.sh\n+++ /dev/null\n@@ -1,131 +0,0 @@\n-#!/bin/sh\n-\n-USAGE='[-l] [(-d | -D) <branchname>] | [[-f] <branchname> [<start-point>]] | -r'\n-LONG_USAGE='If no arguments, show available branches and mark current branch with a star.\n-If one argument, create a new branch <branchname> based off of current HEAD.\n-If two arguments, create a new branch <branchname> based off of <start-point>.'\n-\n-SUBDIRECTORY_OK='Yes'\n-. git-sh-setup\n-\n-headref=$(git-symbolic-ref HEAD | sed -e 's|^refs/heads/||')\n-\n-delete_branch () {\n-    option=\"$1\"\n-    shift\n-    for branch_name\n-    do\n-\tcase \",$headref,\" in\n-\t\",$branch_name,\")\n-\t    die \"Cannot delete the branch you are on.\" ;;\n-\t,,)\n-\t    die \"What branch are you on anyway?\" ;;\n-\tesac\n-\tbranch=$(git-show-ref --verify --hash -- \"refs/heads/$branch_name\") &&\n-\t    branch=$(git-rev-parse --verify \"$branch^0\") ||\n-\t\tdie \"Seriously, what branch are you talking about?\"\n-\tcase \"$option\" in\n-\t-D)\n-\t    ;;\n-\t*)\n-\t    mbs=$(git-merge-base -a \"$branch\" HEAD | tr '\\012' ' ')\n-\t    case \" $mbs \" in\n-\t    *' '$branch' '*)\n-\t\t# the merge base of branch and HEAD contains branch --\n-\t\t# which means that the HEAD contains everything in both.\n-\t\t;;\n-\t    *)\n-\t\techo >&2 \"The branch '$branch_name' is not a strict subset of your current HEAD.\n-If you are sure you want to delete it, run 'git branch -D $branch_name'.\"\n-\t\texit 1\n-\t\t;;\n-\t    esac\n-\t    ;;\n-\tesac\n-\tgit update-ref -d \"refs/heads/$branch_name\" \"$branch\"\n-\techo \"Deleted branch $branch_name.\"\n-    done\n-    exit 0\n-}\n-\n-ls_remote_branches () {\n-    git-rev-parse --symbolic --all |\n-    sed -ne 's|^refs/\\(remotes/\\)|\\1|p' |\n-    sort\n-}\n-\n-force=\n-create_log=\n-while case \"$#,$1\" in 0,*) break ;; *,-*) ;; *) break ;; esac\n-do\n-\tcase \"$1\" in\n-\t-d | -D)\n-\t\tdelete_branch \"$@\"\n-\t\texit\n-\t\t;;\n-\t-r)\n-\t\tls_remote_branches\n-\t\texit\n-\t\t;;\n-\t-f)\n-\t\tforce=\"$1\"\n-\t\t;;\n-\t-l)\n-\t\tcreate_log=\"yes\"\n-\t\t;;\n-\t--)\n-\t\tshift\n-\t\tbreak\n-\t\t;;\n-\t-*)\n-\t\tusage\n-\t\t;;\n-\tesac\n-\tshift\n-done\n-\n-case \"$#\" in\n-0)\n-\tgit-rev-parse --symbolic --branches |\n-\tsort |\n-\twhile read ref\n-\tdo\n-\t\tif test \"$headref\" = \"$ref\"\n-\t\tthen\n-\t\t\tpfx='*'\n-\t\telse\n-\t\t\tpfx=' '\n-\t\tfi\n-\t\techo \"$pfx $ref\"\n-\tdone\n-\texit 0 ;;\n-1)\n-\thead=HEAD ;;\n-2)\n-\thead=\"$2^0\" ;;\n-esac\n-branchname=\"$1\"\n-\n-rev=$(git-rev-parse --verify \"$head\") || exit\n-\n-git-check-ref-format \"heads/$branchname\" ||\n-\tdie \"we do not like '$branchname' as a branch name.\"\n-\n-prev=''\n-if git-show-ref --verify --quiet -- \"refs/heads/$branchname\"\n-then\n-\tif test '' = \"$force\"\n-\tthen\n-\t\tdie \"$branchname already exists.\"\n-\telif test \"$branchname\" = \"$headref\"\n-\tthen\n-\t\tdie \"cannot force-update the current branch.\"\n-\tfi\n-\tprev=`git rev-parse --verify \"refs/heads/$branchname\"`\n-fi\n-if test \"$create_log\" = 'yes'\n-then\n-\tmkdir -p $(dirname \"$GIT_DIR/logs/refs/heads/$branchname\")\n-\ttouch \"$GIT_DIR/logs/refs/heads/$branchname\"\n-fi\n-git update-ref -m \"branch: Created from $head\" \"refs/heads/$branchname\" \"$rev\" \"$prev\"\ndiff --git a/git.c b/git.c\nindex 308252a..671b212 100644\n--- a/git.c\n+++ b/git.c\n@@ -222,6 +222,7 @@ static void handle_internal_command(int \n \t\t{ \"annotate\", cmd_annotate, },\n \t\t{ \"apply\", cmd_apply },\n \t\t{ \"archive\", cmd_archive },\n+\t\t{ \"branch\", cmd_branch },\n \t\t{ \"cat-file\", cmd_cat_file, RUN_SETUP },\n \t\t{ \"checkout-index\", cmd_checkout_index, RUN_SETUP },\n \t\t{ \"check-ref-format\", cmd_check_ref_format },\n-- \n1.4.3.1.g9164-dirty\n"},{"id":"29771","messageId":"20061023215506.GB8344@spearce.org","threadId":"6019","inReplyTo":"11616396262982-git-send-email-hjemli@gmail.com","subject":"Re: [PATCH] Make git-branch a builtin","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-10-23T21:55:06Z","receivedAt":"2006-10-23T21:55:06Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Lars Hjemli <hjemli@gmail.com> wrote:\n[snip]\n> ---\n>  Makefile         |    3 +-\n>  builtin-branch.c |  217 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n>  builtin.h        |    1 +\n>  git-branch.sh    |  131 --------------------------------\n>  git.c            |    1 +\n>  5 files changed, 221 insertions(+), 132 deletions(-)\n[snip]\n> diff --git a/git-branch.sh b/git-branch.sh\n> deleted file mode 100755\n> index 4379a07..0000000\n> --- a/git-branch.sh\n> +++ /dev/null\n> @@ -1,131 +0,0 @@\n[snip 131 lines]\n\nAside from compatability with non-Git tools...\n\nWouldn't it make more sense to just include the full SHA1 of the\nfile we are deleting rather than the entire 131 line negative diff?\n\n-- \nShawn.\n"},{"id":"29776","messageId":"7vk62qwtk7.fsf@assigned-by-dhcp.cox.net","threadId":"6019","inReplyTo":"11616396262982-git-send-email-hjemli@gmail.com","subject":"Re: [PATCH] Make git-branch a builtin","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-10-23T22:34:00Z","receivedAt":"2006-10-23T22:34:00Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Lars Hjemli <hjemli@gmail.com> writes:\n\n> This replaces git-branch.sh with builtin-branch.c\n\n> +static const char builtin_branch_usage[] =\n> +\"git-branch [(-d | -D) <branchname>] | [[-f] <branchname> [<start-point>]] | -r\";\n\nProbably needs a matching change to your recent clean-up here.\n\n> +static int append_ref(const char *refname, const unsigned char *sha1, int flags, \n> +\t\tvoid *cb_data)\n> +{\n> +\tif (ref_index >= ref_alloc) {\n> +\t\tref_alloc = ref_alloc > 0 ? ref_alloc * 2 : 16;\n> +\t\tref_list = xrealloc(ref_list, ref_alloc * sizeof(char *));\n> +\t}\n\nIt would be more consistent to use alloc_nr() from cache.h here\nunless you have a specific need for allocation growing pattern,\nwhich you don't.  Other parts of the system even just grows by\none and let xrealloc() (and in turn underlying realloc()) take\ncare of the optimization of repeated reallocations, which may\nalso be fine.\n\n> +static void create_branch(const char *name, const char *start,\n> +\t\t\t  int force, int reflog)\n> +{\n> +\tstruct ref_lock *lock;\n> +\tunsigned char sha1[20];\n> +\tchar ref[PATH_MAX], msg[PATH_MAX + 20];\n> +\n> +\tsnprintf(ref, sizeof ref, \"refs/heads/%s\", name);\n> +\tif (check_ref_format(ref))\n> +\t\tdie(\"'%s' is not a valid branch name.\", name);\n> +\n> +\tif (resolve_ref(ref, sha1, 1, NULL)) {\n> +\t\tif (!force)\n> +\t\t\tdie(\"A branch named '%s' already exists.\", name);\n> +\t\telse if (!strcmp(head, name))\n> +\t\t\tdie(\"Cannot force update the current branch.\");\n> +\t}\n> +\n> +\tif (get_sha1(start, sha1))\n> +\t\tdie(\"Not a valid branch point: '%s'.\", start);\n> +\n> +\tlock = lock_any_ref_for_update(ref, NULL);\n> +\tif (!lock)\n> +\t\tdie(\"Failed to lock ref for update: %s.\", strerror(errno));\n\nThis is not enough.  \"$2^0\" in git-branch.sh makes sure the\n\"start\" specified dereferences to a commit object, and object\nname we use to initialize the new branch is of the commit object\n(IOW, test your code with \"git branch new v1.0.0\" and make sure\n\"git rev-parse new\" returns the commit object not the tag that\npoints at it).\n\n> +\t\t\n> +\tif (reflog){\n\nStyle; (1) remove trailing TAB on the empty line; (2) one SP\nbetween ')' and '{' please.\n\n> diff --git a/builtin.h b/builtin.h\n> index 9683a7c..144d299 100644\n> --- a/builtin.h\n> +++ b/builtin.h\n> @@ -15,6 +15,7 @@ extern int write_tree(unsigned char *sha\n>  extern int cmd_add(int argc, const char **argv, const char *prefix);\n>  extern int cmd_annotate(int argc, const char **argv, const char *prefix);\n>  extern int cmd_apply(int argc, const char **argv, const char *prefix);\n> +extern int cmd_branch(int argc, const char **argv, const char *prefix);\n>  extern int cmd_archive(int argc, const char **argv, const char *prefix);\n>  extern int cmd_cat_file(int argc, const char **argv, const char *prefix);\n>  extern int cmd_checkout_index(int argc, const char **argv, const char *prefix);\n\nStyle; order them alphabetically please...\n\n> diff --git a/git.c b/git.c\n> index 308252a..671b212 100644\n> --- a/git.c\n> +++ b/git.c\n> @@ -222,6 +222,7 @@ static void handle_internal_command(int \n>  \t\t{ \"annotate\", cmd_annotate, },\n>  \t\t{ \"apply\", cmd_apply },\n>  \t\t{ \"archive\", cmd_archive },\n> +\t\t{ \"branch\", cmd_branch },\n>  \t\t{ \"cat-file\", cmd_cat_file, RUN_SETUP },\n>  \t\t{ \"checkout-index\", cmd_checkout_index, RUN_SETUP },\n>  \t\t{ \"check-ref-format\", cmd_check_ref_format },\n\nIn other words, match this.\n\nWe may someday want to do binary search into the command list,\nand before that happens we should make sure this list is really\nordered.\n"},{"id":"29782","messageId":"20061023231940.GU20017@pasky.or.cz","threadId":"6019","inReplyTo":"20061023215506.GB8344@spearce.org","subject":"Re: [PATCH] Make git-branch a builtin","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-10-23T23:19:40Z","receivedAt":"2006-10-23T23:19:40Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Mon, Oct 23, 2006 at 11:55:06PM CEST, I got a letter\nwhere Shawn Pearce <spearce@spearce.org> said that...\n> Lars Hjemli <hjemli@gmail.com> wrote:\n> [snip]\n> > ---\n> >  Makefile         |    3 +-\n> >  builtin-branch.c |  217 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n> >  builtin.h        |    1 +\n> >  git-branch.sh    |  131 --------------------------------\n> >  git.c            |    1 +\n> >  5 files changed, 221 insertions(+), 132 deletions(-)\n> [snip]\n> > diff --git a/git-branch.sh b/git-branch.sh\n> > deleted file mode 100755\n> > index 4379a07..0000000\n> > --- a/git-branch.sh\n> > +++ /dev/null\n> > @@ -1,131 +0,0 @@\n> [snip 131 lines]\n> \n> Aside from compatability with non-Git tools...\n> \n> Wouldn't it make more sense to just include the full SHA1 of the\n> file we are deleting rather than the entire 131 line negative diff?\n\nI think this way it's easier to review since you can check what is going\naway with the new stuff you introduce instead.\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\n#!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj\n$/=unpack('H*',$_);$_=`echo 16dio\\U$k\"SK$/SM$n\\EsN0p[lN*1\nlK[d2%Sa2/d0$^Ixp\"|dc`;s/\\W//g;$_=pack('H*',/((..)*)$/)\n"},{"id":"29785","messageId":"7vfydewqbb.fsf@assigned-by-dhcp.cox.net","threadId":"6019","inReplyTo":"20061023215506.GB8344@spearce.org","subject":"Re: [PATCH] Make git-branch a builtin","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-10-23T23:44:08Z","receivedAt":"2006-10-23T23:44:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Shawn Pearce <spearce@spearce.org> writes:\n\n> Lars Hjemli <hjemli@gmail.com> wrote:\n> [snip]\n>> ---\n>>  Makefile         |    3 +-\n>>  builtin-branch.c |  217 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n>>  builtin.h        |    1 +\n>>  git-branch.sh    |  131 --------------------------------\n>>  git.c            |    1 +\n>>  5 files changed, 221 insertions(+), 132 deletions(-)\n> [snip]\n>> diff --git a/git-branch.sh b/git-branch.sh\n>> deleted file mode 100755\n>> index 4379a07..0000000\n>> --- a/git-branch.sh\n>> +++ /dev/null\n>> @@ -1,131 +0,0 @@\n> [snip 131 lines]\n>\n> Aside from compatability with non-Git tools...\n>\n> Wouldn't it make more sense to just include the full SHA1 of the\n> file we are deleting rather than the entire 131 line negative diff?\n\nHow would you do \"git apply -R\" on something like that?\n"},{"id":"29786","messageId":"11616474633074-git-send-email-hjemli@gmail.com","threadId":"6019","inReplyTo":"7vk62qwtk7.fsf@assigned-by-dhcp.cox.net","subject":"[PATCH] Git-branch: fix regression and style issues","fromName":"Lars Hjemli","fromEmail":"hjemli@gmail.com","sentAt":"2006-10-23T23:51:03Z","receivedAt":"2006-10-23T23:51:03Z","isPatch":true,"sender":{"key":"hjemli@gmail.com","avatar":null},"body":"This is on top of my previuos patch to builtin-branch.c\n\nSigned-off-by: Lars Hjemli <hjemli@gmail.com>\n---\n builtin-branch.c |   17 ++++++++---------\n builtin.h        |    2 +-\n 2 files changed, 9 insertions(+), 10 deletions(-)\n\ndiff --git a/builtin-branch.c b/builtin-branch.c\nindex 3105efd..ffc2db0 100755\n--- a/builtin-branch.c\n+++ b/builtin-branch.c\n@@ -11,7 +11,7 @@ #include \"commit.h\"\n #include \"builtin.h\"\n \n static const char builtin_branch_usage[] =\n-\"git-branch [(-d | -D) <branchname>] | [[-f] <branchname> [<start-point>]] | -r\";\n+\"git-branch (-d | -D) <branchname> | [-l] [-f] <branchname> [<start-point>] | [-r]\";\n \n \n static const char *head;\n@@ -74,7 +74,7 @@ static void delete_branches(int argc, co\n \t\t\tprintf(\"Error deleting branch '%s'\\n\", argv[i]);\n \t\telse\n \t\t\tprintf(\"Deleted branch %s.\\n\", argv[i]);\n-\t\t\t\n+\n \t\tfree(name);\n \t}\n }\n@@ -82,11 +82,11 @@ static void delete_branches(int argc, co\n static int ref_index, ref_alloc;\n static char **ref_list;\n \n-static int append_ref(const char *refname, const unsigned char *sha1, int flags, \n+static int append_ref(const char *refname, const unsigned char *sha1, int flags,\n \t\tvoid *cb_data)\n {\n \tif (ref_index >= ref_alloc) {\n-\t\tref_alloc = ref_alloc > 0 ? ref_alloc * 2 : 16;\n+\t\tref_alloc = alloc_nr(ref_alloc);\n \t\tref_list = xrealloc(ref_list, ref_alloc * sizeof(char *));\n \t}\n \n@@ -137,14 +137,14 @@ static void create_branch(const char *na\n \t\t\tdie(\"Cannot force update the current branch.\");\n \t}\n \n-\tif (get_sha1(start, sha1))\n+\tif (get_sha1(mkpath(\"%s^0\", start), sha1))\n \t\tdie(\"Not a valid branch point: '%s'.\", start);\n \n \tlock = lock_any_ref_for_update(ref, NULL);\n \tif (!lock)\n \t\tdie(\"Failed to lock ref for update: %s.\", strerror(errno));\n-\t\t\n-\tif (reflog){\n+\n+\tif (reflog) {\n \t\tlog_all_ref_updates = 1;\n \t\tsnprintf(msg, sizeof msg, \"branch: Created from %s\", start);\n \t}\n@@ -199,9 +199,8 @@ int cmd_branch(int argc, const char **ar\n \t\tdie(\"Failed to resolve HEAD as a valid ref.\");\n \tif (strncmp(head, \"refs/heads/\", 11))\n \t\tdie(\"HEAD not found below refs/heads!\");\n-\t\t\n \thead += 11;\n-\t\n+\n \tif (delete)\n \t\tdelete_branches(argc - i, argv + i, force_delete);\n \telse if (i == argc)\ndiff --git a/builtin.h b/builtin.h\nindex 144d299..9b4749f 100644\n--- a/builtin.h\n+++ b/builtin.h\n@@ -15,8 +15,8 @@ extern int write_tree(unsigned char *sha\n extern int cmd_add(int argc, const char **argv, const char *prefix);\n extern int cmd_annotate(int argc, const char **argv, const char *prefix);\n extern int cmd_apply(int argc, const char **argv, const char *prefix);\n-extern int cmd_branch(int argc, const char **argv, const char *prefix);\n extern int cmd_archive(int argc, const char **argv, const char *prefix);\n+extern int cmd_branch(int argc, const char **argv, const char *prefix);\n extern int cmd_cat_file(int argc, const char **argv, const char *prefix);\n extern int cmd_checkout_index(int argc, const char **argv, const char *prefix);\n extern int cmd_check_ref_format(int argc, const char **argv, const char *prefix);\n-- \n1.4.3.1.g4604-dirty\n"},{"id":"29808","messageId":"20061024054408.GA9724@spearce.org","threadId":"6019","inReplyTo":"7vfydewqbb.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Make git-branch a builtin","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-10-24T05:44:08Z","receivedAt":"2006-10-24T05:44:08Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> Shawn Pearce <spearce@spearce.org> writes:\n> \n> > Lars Hjemli <hjemli@gmail.com> wrote:\n> > [snip]\n> >> ---\n> >>  Makefile         |    3 +-\n> >>  builtin-branch.c |  217 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n> >>  builtin.h        |    1 +\n> >>  git-branch.sh    |  131 --------------------------------\n> >>  git.c            |    1 +\n> >>  5 files changed, 221 insertions(+), 132 deletions(-)\n> > [snip]\n> >> diff --git a/git-branch.sh b/git-branch.sh\n> >> deleted file mode 100755\n> >> index 4379a07..0000000\n> >> --- a/git-branch.sh\n> >> +++ /dev/null\n> >> @@ -1,131 +0,0 @@\n> > [snip 131 lines]\n> >\n> > Aside from compatability with non-Git tools...\n> >\n> > Wouldn't it make more sense to just include the full SHA1 of the\n> > file we are deleting rather than the entire 131 line negative diff?\n> \n> How would you do \"git apply -R\" on something like that?\n\nUh, you have the full SHA1 in the index line.  So you just have to\nreattach that blob to the named path...  pretty simple actually.\n\nOf course this is yet another code path in apply and as Petr pointed\nout on this same thread its nice to know what you are deleting so\nyou can compare it to what else is changing in the same patch... so\nthis suggestion of mine is probably just a waste of bytes.\n\n-- \nShawn.\n"},{"id":"29817","messageId":"7vy7r6qkmg.fsf@assigned-by-dhcp.cox.net","threadId":"6019","inReplyTo":"20061024054408.GA9724@spearce.org","subject":"Re: [PATCH] Make git-branch a builtin","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-10-24T06:43:35Z","receivedAt":"2006-10-24T06:43:35Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Shawn Pearce <spearce@spearce.org> writes:\n\n>> > Wouldn't it make more sense to just include the full SHA1 of the\n>> > file we are deleting rather than the entire 131 line negative diff?\n>> \n>> How would you do \"git apply -R\" on something like that?\n>\n> Uh, you have the full SHA1 in the index line.  So you just have to\n> reattach that blob to the named path...  pretty simple actually.\n\nBzzzt; wrong answer.\n\nThink of a future when you can shallowly clone near the tip of\ngit repository that does not have shell-script git-branch.sh\nanymore.  You cannot expect to already have the preimage of the\npatch in such a case.  You would still want to be able to revert\nthe change with \"git apply -R\".\n"},{"id":"29821","messageId":"20061024065548.GB9947@spearce.org","threadId":"6019","inReplyTo":"7vy7r6qkmg.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Make git-branch a builtin","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-10-24T06:55:48Z","receivedAt":"2006-10-24T06:55:48Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> Shawn Pearce <spearce@spearce.org> writes:\n> \n> >> > Wouldn't it make more sense to just include the full SHA1 of the\n> >> > file we are deleting rather than the entire 131 line negative diff?\n> >> \n> >> How would you do \"git apply -R\" on something like that?\n> >\n> > Uh, you have the full SHA1 in the index line.  So you just have to\n> > reattach that blob to the named path...  pretty simple actually.\n> \n> Bzzzt; wrong answer.\n> \n> Think of a future when you can shallowly clone near the tip of\n> git repository that does not have shell-script git-branch.sh\n> anymore.  You cannot expect to already have the preimage of the\n> patch in such a case.  You would still want to be able to revert\n> the change with \"git apply -R\".\n\nYet another valid argument for having the data needed for the\npreimage available.\n\nI've already agreed with Petr that having the data there is probably\nbetter than not.  Now I'm also agreeing with you.  There is little\nneed to beat a dead horse.  :-)\n\n-- \nShawn.\n"},{"id":"29851","messageId":"20061024113924.GC20017@pasky.or.cz","threadId":"6019","inReplyTo":"7vy7r6qkmg.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Make git-branch a builtin","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-10-24T11:39:24Z","receivedAt":"2006-10-24T11:39:24Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Tue, Oct 24, 2006 at 08:43:35AM CEST, I got a letter\nwhere Junio C Hamano <junkio@cox.net> said that...\n> Shawn Pearce <spearce@spearce.org> writes:\n> \n> >> > Wouldn't it make more sense to just include the full SHA1 of the\n> >> > file we are deleting rather than the entire 131 line negative diff?\n> >> \n> >> How would you do \"git apply -R\" on something like that?\n> >\n> > Uh, you have the full SHA1 in the index line.  So you just have to\n> > reattach that blob to the named path...  pretty simple actually.\n> \n> Bzzzt; wrong answer.\n> \n> Think of a future when you can shallowly clone near the tip of\n> git repository that does not have shell-script git-branch.sh\n> anymore.  You cannot expect to already have the preimage of the\n> patch in such a case.  You would still want to be able to revert\n> the change with \"git apply -R\".\n\nHmm, how is this argument not applying to binary diffs you can't revert\neither?\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\n#!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj\n$/=unpack('H*',$_);$_=`echo 16dio\\U$k\"SK$/SM$n\\EsN0p[lN*1\nlK[d2%Sa2/d0$^Ixp\"|dc`;s/\\W//g;$_=pack('H*',/((..)*)$/)\n"},{"id":"29872","messageId":"7v8xj5ir7g.fsf@assigned-by-dhcp.cox.net","threadId":"6019","inReplyTo":"20061024113924.GC20017@pasky.or.cz","subject":"Re: [PATCH] Make git-branch a builtin","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-10-24T17:00:51Z","receivedAt":"2006-10-24T17:00:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Petr Baudis <pasky@suse.cz> writes:\n\n>> Think of a future when you can shallowly clone near the tip of\n>> git repository that does not have shell-script git-branch.sh\n>> anymore.  You cannot expect to already have the preimage of the\n>> patch in such a case.  You would still want to be able to revert\n>> the change with \"git apply -R\".\n>\n> Hmm, how is this argument not applying to binary diffs you can't revert\n> either?\n\nEarlier you cannot, but because now you can, perhaps? ;-)\n"}]}