+
+ s = lookup_branch(from);
+ if (b == s)
+ die("Can't create a branch from itself: %s", b->name);
+ else if (s) {
+ memcpy(b->sha1, s->sha1, 20);
+ memcpy(b->branch_tree.sha1, s->branch_tree.sha1, 20);
+ } else if (!get_sha1(from, b->sha1)) {
+ if (!memcmp(b->sha1, null_sha1, 20))
+ memcpy(b->branch_tree.sha1, null_sha1, 20);
+ else {
+ unsigned long size;
+ char *buf;
+
+ buf = read_object_with_reference(b->sha1,
+ type_names[OBJ_COMMIT], &size, b->sha1);
+ if (!buf || size < 46)
+ die("Not a valid commit: %s", from);
+ if (memcmp("tree ", buf, 5)
+ || get_sha1_hex(buf + 5, b->branch_tree.sha1))
+ die("The commit %s is corrupt", sha1_to_hex(b->sha1));
+ free(buf);
+ }
+ } else
+ die("Invalid ref name or SHA1 expression: %s", from);
+
+ if (str_uq)
+ free(str_uq);
+ read_next_command();
+ } else {
+ memcpy(b->sha1, null_sha1, 20);
+ memcpy(b->branch_tree.sha1, null_sha1, 20);
+ }
+
+ if (command_buf.eof || command_buf.len > 1)
+ die("An lf did not terminate the branch command as expected.");