{"thread":{"id":"3412","subject":"[PATCH] git-mktree: reverse of git-ls-tree.","startedAt":"2006-02-21T06:37:05Z","lastAt":"2006-02-21T18:00:30Z","messageCount":10,"participants":["Junio C Hamano","Keith Packard","Andreas Ericsson","Martin Langhoff","Linus Torvalds"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"16490","messageId":"7vk6bp43qm.fsf@assigned-by-dhcp.cox.net","threadId":"3412","inReplyTo":null,"subject":"[PATCH] git-mktree: reverse of git-ls-tree.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-02-21T06:37:05Z","receivedAt":"2006-02-21T06:37:05Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This reads data in the format a (non recursive) ls-tree outputs\nand writes a tree object to the object database.  The created\ntree object name is output to the standard output.\n\nFor convenience, the input data does not need to be sorted; the\ncommand sorts the input lines internally.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n\n---\n\n * For the purposes of filesystem backend, I think completely\n   bypassing the index and having a way to handcraft a tree\n   object, especially if you are writing things in Python, would\n   be much easier to use.  Hence this command.\n\n   Comments?\n\n Makefile |    2 -\n mktree.c |  137 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 138 insertions(+), 1 deletions(-)\n create mode 100644 mktree.c\n\n7e37266ced5edd9a70b03ea07b5eca0d7ee82039\ndiff --git a/Makefile b/Makefile\nindex 317be3c..2f73b86 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -143,7 +143,7 @@ PROGRAMS = \\\n \tgit-diff-tree$X git-fetch-pack$X git-fsck-objects$X \\\n \tgit-hash-object$X git-index-pack$X git-init-db$X \\\n \tgit-local-fetch$X git-ls-files$X git-ls-tree$X git-merge-base$X \\\n-\tgit-merge-index$X git-mktag$X git-pack-objects$X git-patch-id$X \\\n+\tgit-merge-index$X git-mktag$X git-mktree$X git-pack-objects$X git-patch-id$X \\\n \tgit-peek-remote$X git-prune-packed$X git-read-tree$X \\\n \tgit-receive-pack$X git-rev-list$X git-rev-parse$X \\\n \tgit-send-pack$X git-show-branch$X git-shell$X \\\ndiff --git a/mktree.c b/mktree.c\nnew file mode 100644\nindex 0000000..f853585\n--- /dev/null\n+++ b/mktree.c\n@@ -0,0 +1,137 @@\n+/*\n+ * GIT - the stupid content tracker\n+ *\n+ * Copyright (c) Junio C Hamano, 2006\n+ */\n+#include \"cache.h\"\n+#include \"strbuf.h\"\n+#include \"quote.h\"\n+\n+static struct treeent {\n+\tunsigned mode;\n+\tunsigned char sha1[20];\n+\tint len;\n+\tchar name[FLEX_ARRAY];\n+} **entries;\n+static int alloc, used;\n+\n+static void append_to_tree(unsigned mode, unsigned char *sha1, char *path)\n+{\n+\tstruct treeent *ent;\n+\tint len = strlen(path);\n+\tif (strchr(path, '/'))\n+\t\tdie(\"path %s contains slash\", path);\n+\n+\tif (alloc <= used) {\n+\t\talloc = alloc_nr(used);\n+\t\tentries = xrealloc(entries, sizeof(*entries) * alloc);\n+\t}\n+\tent = entries[used++] = xmalloc(sizeof(**entries) + len + 1);\n+\tent->mode = mode;\n+\tent->len = len;\n+\tmemcpy(ent->sha1, sha1, 20);\n+\tmemcpy(ent->name, path, len+1);\n+}\n+\n+static int ent_compare(const void *a_, const void *b_)\n+{\n+\tstruct treeent *a = *(struct treeent **)a_;\n+\tstruct treeent *b = *(struct treeent **)b_;\n+\treturn base_name_compare(a->name, a->len, a->mode,\n+\t\t\t\t b->name, b->len, b->mode);\n+}\n+\n+static void write_tree(unsigned char *sha1)\n+{\n+\tchar *buffer;\n+\tunsigned long size, offset;\n+\tint i;\n+\n+\tqsort(entries, used, sizeof(*entries), ent_compare);\n+\tsize = 100;\n+\tfor (size = i = 0; i < used; i++)\n+\t\tsize += 32 + entries[i]->len;\n+\tbuffer = xmalloc(size);\n+\toffset = 0;\n+\n+\tfor (i = 0; i < used; i++) {\n+\t\tstruct treeent *ent = entries[i];\n+\n+\t\tif (offset + ent->len + 100 < size) {\n+\t\t\tsize = alloc_nr(offset + ent->len + 100);\n+\t\t\tbuffer = xrealloc(buffer, size);\n+\t\t}\n+\t\toffset += sprintf(buffer + offset, \"%o \", ent->mode);\n+\t\toffset += sprintf(buffer + offset, \"%s\", ent->name);\n+\t\tbuffer[offset++] = 0;\n+\t\tmemcpy(buffer + offset, ent->sha1, 20);\n+\t\toffset += 20;\n+\t}\n+\twrite_sha1_file(buffer, offset, \"tree\", sha1);\n+}\n+\n+static const char mktree_usage[] = \"mktree [-z]\";\n+\n+int main(int ac, char **av)\n+{\n+\tstruct strbuf sb;\n+\tunsigned char sha1[20];\n+\tint line_termination = '\\n';\n+\n+\tsetup_git_directory();\n+\n+\twhile ((1 < ac) && av[1][0] == '-') {\n+\t\tchar *arg = av[1];\n+\t\tif (!strcmp(\"-z\", arg))\n+\t\t\tline_termination = 0;\n+\t\telse\n+\t\t\tusage(mktree_usage);\n+\t\tac--;\n+\t\tav++;\n+\t}\n+\n+\tstrbuf_init(&sb);\n+\twhile (1) {\n+\t\tint len;\n+\t\tchar *ptr, *ntr;\n+\t\tunsigned mode;\n+\t\tchar type[20];\n+\t\tchar *path;\n+\n+\t\tread_line(&sb, stdin, line_termination);\n+\t\tif (sb.eof)\n+\t\t\tbreak;\n+\t\tlen = sb.len;\n+\t\tptr = sb.buf;\n+\t\t/* Input is non-recursive ls-tree output format\n+\t\t * mode SP type SP sha1 TAB name\n+\t\t */\n+\t\tmode = strtoul(ptr, &ntr, 8);\n+\t\tif (ptr == ntr || !ntr || *ntr != ' ')\n+\t\t\tdie(\"input format error: %s\", sb.buf);\n+\t\tptr = ntr + 1; /* type */\n+\t\tntr = strchr(ptr, ' ');\n+\t\tif (!ntr || sb.buf + len <= ntr + 41 ||\n+\t\t    ntr[41] != '\\t' ||\n+\t\t    get_sha1_hex(ntr + 1, sha1))\n+\t\t\tdie(\"input format error: %s\", sb.buf);\n+\t\tif (sha1_object_info(sha1, type, NULL))\n+\t\t\tdie(\"object %s unavailable\", sha1_to_hex(sha1));\n+\t\t*ntr++ = 0; /* now at the beginning of SHA1 */\n+\t\tif (strcmp(ptr, type))\n+\t\t\tdie(\"object type %s mismatch (%s)\", ptr, type);\n+\t\tntr += 41; /* at the beginning of name */\n+\t\tif (line_termination && ntr[0] == '\"')\n+\t\t\tpath = unquote_c_style(ntr, NULL);\n+\t\telse\n+\t\t\tpath = ntr;\n+\n+\t\tappend_to_tree(mode, sha1, path);\n+\n+\t\tif (path != ntr)\n+\t\t\tfree(path);\n+\t}\n+\twrite_tree(sha1);\n+\tputs(sha1_to_hex(sha1));\n+\texit(0);\n+}\n-- \n1.2.2.g9896\n"},{"id":"16491","messageId":"1140504750.16926.111.camel@evo.keithp.com","threadId":"3412","inReplyTo":"7vk6bp43qm.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] git-mktree: reverse of git-ls-tree.","fromName":"Keith Packard","fromEmail":"keithp@keithp.com","sentAt":"2006-02-21T06:52:30Z","receivedAt":"2006-02-21T06:52:30Z","isPatch":true,"sender":{"key":"keithp@keithp.com","avatar":"https://gravatar.com/avatar/fa1f479cdd51322fe86215c955a81d296bbf66a1fe625f8a12d87a8ec7faf648?d=mp&s=160"},"body":"<internationalization-pedant-mode>\nOn Mon, 2006-02-20 at 22:37 -0800, Junio C Hamano wrote:\n\n> + * Copyright (c) Junio C Hamano, 2006\n\nI've been told by at least two lawyers that the string '(c)' has no\nlegal meaning in the US. If you want to indicate copyright, the only\nsymbol which does carry legal weight is the c-in-a-circle mark '©'. \n\nOf course, this does force the issue of what encoding to present source\nfiles in. I suggest that sources should be UTF-8, which also provides\nopportunities to encode author names correctly, rather than\ntransliterating them to Latin. X.org uses UTF-8 for source files now\nwithout difficulty across a wide range of compilers. Of course,\nnon-ascii glyphs are present only in comments.\n\n</internationalization-pedant-mode>\n-- \nkeith.packard@intel.com\n"},{"id":"16497","messageId":"43FAD35E.5080401@op5.se","threadId":"3412","inReplyTo":"1140504750.16926.111.camel@evo.keithp.com","subject":"Re: [PATCH] git-mktree: reverse of git-ls-tree.","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2006-02-21T08:46:22Z","receivedAt":"2006-02-21T08:46:22Z","isPatch":true,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"Keith Packard wrote:\n> <internationalization-pedant-mode>\n> On Mon, 2006-02-20 at 22:37 -0800, Junio C Hamano wrote:\n> \n> \n>>+ * Copyright (c) Junio C Hamano, 2006\n> \n> \n> I've been told by at least two lawyers that the string '(c)' has no\n> legal meaning in the US. If you want to indicate copyright, the only\n> symbol which does carry legal weight is the c-in-a-circle mark 'Â©'. \n> \n> Of course, this does force the issue of what encoding to present source\n> files in. I suggest that sources should be UTF-8, which also provides\n> opportunities to encode author names correctly, rather than\n> transliterating them to Latin. X.org uses UTF-8 for source files now\n> without difficulty across a wide range of compilers. Of course,\n> non-ascii glyphs are present only in comments.\n> \n> </internationalization-pedant-mode>\n\n\nIn most countries the copyright is implied unless explicitly void by the \nauthor.\n\nIn other sane countries (I don't argue that USA is necessarily any such \ncountry), the law is such that if the copier understands that there is a \ncopyright and violates it, he or she is in error and thus liable.\n\nI'm not sure how mad such a law can be written, but what you describe go \nagainst both common sense and common practice since it puts the burden \nof protection on the victim-to-be before the crime is even committed. It \nwould be like a rapist being let off because his victims were where he \nhappened to be.\n\n-- \nAndreas Ericsson                   andreas.ericsson@op5.se\nOP5 AB                             www.op5.se\nTel: +46 8-230225                  Fax: +46 8-230231\n"},{"id":"16498","messageId":"7vr75x11or.fsf@assigned-by-dhcp.cox.net","threadId":"3412","inReplyTo":"43FAD35E.5080401@op5.se","subject":"Re: [PATCH] git-mktree: reverse of git-ls-tree.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-02-21T09:49:40Z","receivedAt":"2006-02-21T09:49:40Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andreas Ericsson <ae@op5.se> writes:\n\n> Keith Packard wrote:\n>> <internationalization-pedant-mode>\n>> On Mon, 2006-02-20 at 22:37 -0800, Junio C Hamano wrote:\n>>\n>>>+ * Copyright (c) Junio C Hamano, 2006\n>> I've been told by at least two lawyers that the string '(c)' has no\n>> legal meaning in the US. If you want to indicate copyright, the only\n>> symbol which does carry legal weight is the c-in-a-circle mark\n>...\n> I'm not sure how mad such a law can be written, but what you describe\n> go against both common sense and common practice since it puts the\n> burden of protection on the victim-to-be before the crime is even\n> committed...\n\nKeith is saying that unlike ciecle-c, (c) is meaningless.  While\nhe is right about that, it does not matter, as long as he is\ntalking about \"legal meaning in the US\".  It is my understanding\nthat spelled out \"Copyright\" (or its abbreviation, \"Copr.\")\nweighs as much as the circle-c mark.\n\nAnd it matters even less these days.  US law traditionally\nrequired copyright notice to be protected, but after 1989 US\nCopyright Act, made in line with Berne convention, the notice is\nnot even necessary.  It used to be that you would want circle-c,\nCopyright and \"All Rights Reserved\", if you really wanted to be\nanal.  Buenos Aires signatories are all Berne members these\ndays, it became just obsolete inertia.\n"},{"id":"16499","messageId":"46a038f90602210220w68edb71aq9f9f54ac278cb9e0@mail.gmail.com","threadId":"3412","inReplyTo":"7vr75x11or.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] git-mktree: reverse of git-ls-tree.","fromName":"Martin Langhoff","fromEmail":"martin.langhoff@gmail.com","sentAt":"2006-02-21T10:20:40Z","receivedAt":"2006-02-21T10:20:40Z","isPatch":true,"sender":{"key":"martin.langhoff@gmail.com","avatar":"https://gravatar.com/avatar/1e3f311b6c4c15836501901ca58f8c0b0667246488084ba524d8bc9867e22fd9?d=mp&s=160"},"body":"On 2/21/06, Junio C Hamano <junkio@cox.net> wrote:\n> Keith is saying that unlike ciecle-c, (c) is meaningless.  While\n> he is right about that, it does not matter, as long as he is\n> talking about \"legal meaning in the US\".  It is my understanding\n> that spelled out \"Copyright\" (or its abbreviation, \"Copr.\")\n> weighs as much as the circle-c mark.\n>\n> And it matters even less these days.  US law traditionally\n> required copyright notice to be protected, but after 1989 US\n> Copyright Act, made in line with Berne convention, the notice is\n> not even necessary.  It used to be that you would want circle-c,\n> Copyright and \"All Rights Reserved\", if you really wanted to be\n> anal.  Buenos Aires signatories are all Berne members these\n> days, it became just obsolete inertia.\n\nNot entirely useless though. It serves as an indication of who to\ncontact for permission to copy. It's not as good as it should be\n(\"which of the 35 L.Torvalds in the phonebook does this mean?\").\nCopyright law reform proponents do sometimes talk of a central\ndatabase with contact details for copyright owners and other measures\nto facilitate brokerage of licenses.\n\nIt also serves as a reminder of the need for a license, though legally\nit's not required. Just like a lock in the door, while often easy to\npick or crack open and definitely not required, reminds people that\ntrespassing is a crime.\n\nBah, social mores, laws and other vices of humanity...\n\n\nmartin\n"},{"id":"16505","messageId":"1140542628.16926.125.camel@evo.keithp.com","threadId":"3412","inReplyTo":"7vr75x11or.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] git-mktree: reverse of git-ls-tree.","fromName":"Keith Packard","fromEmail":"keithp@keithp.com","sentAt":"2006-02-21T17:23:48Z","receivedAt":"2006-02-21T17:23:48Z","isPatch":true,"sender":{"key":"keithp@keithp.com","avatar":"https://gravatar.com/avatar/fa1f479cdd51322fe86215c955a81d296bbf66a1fe625f8a12d87a8ec7faf648?d=mp&s=160"},"body":"On Tue, 2006-02-21 at 01:49 -0800, Junio C Hamano wrote:\n\n> Keith is saying that unlike ciecle-c, (c) is meaningless.  While\n> he is right about that, it does not matter, as long as he is\n> talking about \"legal meaning in the US\".  It is my understanding\n> that spelled out \"Copyright\" (or its abbreviation, \"Copr.\")\n> weighs as much as the circle-c mark.\n\nPrecisely. I'd say either remove the (c) or replace it with the correct\nsymbol. As including the correct symbol requires selecting between an\n8859 and 10646 encoding, one shows one's i18n-fu by including the © in\nUTF-8.\n\nOnce this choice is firmly in place, the opportunties for excessive\ncharacter usage really flourish:\n\nhttp://gitweb.freedesktop.org/?p=cairo;a=blobdiff;h=1c63adec9b6547c6446548dc3a877e1e4ba29bfd;hp=a6ebc5e04773c8b544cfb721b635ef5534be235f;hb=cc890b9cf4d2a38e13ae48e16589c4fd02678f99;f=src/cairo-pen.c\n  \n-- \nkeith.packard@intel.com\n"},{"id":"16507","messageId":"Pine.LNX.4.64.0602210915320.30245@g5.osdl.org","threadId":"3412","inReplyTo":"1140504750.16926.111.camel@evo.keithp.com","subject":"Re: [PATCH] git-mktree: reverse of git-ls-tree.","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-02-21T17:40:06Z","receivedAt":"2006-02-21T17:40:06Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Mon, 20 Feb 2006, Keith Packard wrote:\n> \n> > + * Copyright (c) Junio C Hamano, 2006\n> \n> I've been told by at least two lawyers that the string '(c)' has no\n> legal meaning in the US. If you want to indicate copyright, the only\n> symbol which does carry legal weight is the c-in-a-circle mark '©'. \n\nYou should change lawyers, methinks.\n\nThe thing is, once the same line says \"Copyright\", the string '(c)' may be \nmeaningless, but more importantly, your lawyers are wasting your time with \npointless and mindless \"punktknulleri\" (literal meaning: \"the f*cking of \npoints\", aka being anal retentive).\n\nOf course, they are probably also charging you for that time they are \nwasting, which is why you should fire them and find somebody who tells you \nanything relevant.\n\nThe FACT is that\n (a) You can write out the word \"copyright\" in its entirety.\n (b) the US legal system very much takes intent into account, so even if \n     you don't, if the meaning is clear, it's not like it matters. This\n     is even more true on most of the rest of the civilized world, btw (ie \n     Europe in general gives authors _more_ rights than the US, since they \n     recognize the notion of \"moral rights\")\n (c) you own the copyright anyway ever since 1988, when the US ratified \n     the Berne convention. In fact, even before then, the US had adopted \n     the notion of automatic copyrights, and any work created after 1978 \n     falls under this.\n\nAnyway, for more details if you _really_ care, look up \"Circular 3\" by the \nUnited States Copyright Office. The very first sentence of that paper \ntalks about how the notice isn't even required any more, but if you want \nto talk to your punktknullande lawyers, point them to the section called \n\"form of notice\". Which mentions the © letter, but makes it very very \nclear that \"Copyright\" or the abbreviation \"Copr.\" are totally \ninterchangeable in the US.\n\nNow, in some _other_ countries, the © mark may be special, but quite \nfrankly, you won't really care. If it matters, those countries haven't \nratified the Berne convention, and you'll never ever in a million years \ncare about them. It's absolutely certainly not the case in any relevant \ncountry.\n\nAny country where \"©\" matters likely has many bigger problems wrt \ncopyrights, like not honoring them at all.\n\nSo: if you care about the copyright law in Ulan Bator, you may have to use \nthe © character. But the likelihood is that it's not an issue even there.\n\nSo tell your lawyers to f*ck the hell off.\n\n\t\tLinus"},{"id":"16508","messageId":"1140543982.16926.145.camel@evo.keithp.com","threadId":"3412","inReplyTo":"Pine.LNX.4.64.0602210915320.30245@g5.osdl.org","subject":"Re: [PATCH] git-mktree: reverse of git-ls-tree.","fromName":"Keith Packard","fromEmail":"keithp@keithp.com","sentAt":"2006-02-21T17:46:22Z","receivedAt":"2006-02-21T17:46:22Z","isPatch":true,"sender":{"key":"keithp@keithp.com","avatar":"https://gravatar.com/avatar/fa1f479cdd51322fe86215c955a81d296bbf66a1fe625f8a12d87a8ec7faf648?d=mp&s=160"},"body":"On Tue, 2006-02-21 at 09:40 -0800, Linus Torvalds wrote:\n\n> Which mentions the © letter, but makes it very very \n> clear that \"Copyright\" or the abbreviation \"Copr.\" are totally \n> interchangeable in the US.\n\nYes, all three are equivalent, my only point was that '(c)' is\nmeaningless. Which, as I noted is just pedantry.\n\n-- \nkeith.packard@intel.com\n"},{"id":"16509","messageId":"Pine.LNX.4.64.0602210952321.30245@g5.osdl.org","threadId":"3412","inReplyTo":"1140542628.16926.125.camel@evo.keithp.com","subject":"Re: [PATCH] git-mktree: reverse of git-ls-tree.","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-02-21T17:57:14Z","receivedAt":"2006-02-21T17:57:14Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Tue, 21 Feb 2006, Keith Packard wrote:\n> \n> Precisely. I'd say either remove the (c) or replace it with the correct\n> symbol.\n\nTaking that to its logical conclusion, you should remove the whole line, \nsince none of it is in any way required and it's all unnecessary.\n\nThe thing is, the string \"(c)\" is a _lot_ more readable than the sanest \nalternative for © (\\c2\\a9, ie the appropriate UTF8 string). Because even \nthat sane representation will actually show up as something else in a \n_lot_ of editors, and is often hard to type for people. \n\nThere's a reason people use \"(c)\" rather \"©\".\n\n\t\tLinus"},{"id":"16510","messageId":"Pine.LNX.4.64.0602210959130.30245@g5.osdl.org","threadId":"3412","inReplyTo":"1140543982.16926.145.camel@evo.keithp.com","subject":"Re: [PATCH] git-mktree: reverse of git-ls-tree.","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-02-21T18:00:30Z","receivedAt":"2006-02-21T18:00:30Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Tue, 21 Feb 2006, Keith Packard wrote:\n>\n> Yes, all three are equivalent, my only point was that '(c)' is\n> meaningless. Which, as I noted is just pedantry.\n\nPedantry is fine on a mailing list. But meaningless pedantry in a lawyer \nis bad. My point was that your _lawyers_ are bad. Tell them to concentrate \non something that matters.\n\n\t\tLinus\n"}]}