git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: git@vger.kernel.org
Cc: "Antoine Beaupré" <anarcat@debian.org>,
	"Phillip Wood" <phillip.wood@dunelm.org.uk>,
	"Felipe Contreras" <felipe.contreras@gmail.com>
Subject: [RFC PATCH 1/3] branch: add new 'tail' concept
Date: Fri, 10 Mar 2023 15:45:13 -0600	[thread overview]
Message-ID: <20230310214515.39154-2-felipe.contreras@gmail.com> (raw)
In-Reply-To: <20230310214515.39154-1-felipe.contreras@gmail.com>

The 'tail' of a branch points to the first parent commit of the branch
when it was created.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 branch.c                  | 12 ++++++++++++
 branch.h                  |  1 +
 builtin/clone.c           |  1 +
 t/t1514-rev-parse-tail.sh | 23 +++++++++++++++++++++++
 4 files changed, 37 insertions(+)
 create mode 100755 t/t1514-rev-parse-tail.sh

diff --git a/branch.c b/branch.c
index e5614b53b3..e43a164ddb 100644
--- a/branch.c
+++ b/branch.c
@@ -234,6 +234,16 @@ static int inherit_tracking(struct tracking *tracking, const char *orig_ref)
 	return 0;
 }
 
+void install_branch_base(const char *local, const struct object_id *tail)
+{
+	struct strbuf ref = STRBUF_INIT;
+
+	strbuf_addf(&ref, "refs/tails/%s", local);
+	update_ref(NULL, ref.buf, tail, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
+
+	strbuf_release(&ref);
+}
+
 /*
  * Used internally to set the branch.<new_ref>.{remote,merge} config
  * settings so that branch 'new_ref' tracks 'orig_ref'. Unlike
@@ -623,6 +633,8 @@ void create_branch(struct repository *r,
 	if (real_ref && track)
 		setup_tracking(ref.buf + 11, real_ref, track, quiet);
 
+	install_branch_base(ref.buf + 11, &oid);
+
 cleanup:
 	strbuf_release(&ref);
 	free(real_ref);
diff --git a/branch.h b/branch.h
index ef56103c05..f020d5be5d 100644
--- a/branch.h
+++ b/branch.h
@@ -142,6 +142,7 @@ void remove_branch_state(struct repository *r, int verbose);
  */
 #define BRANCH_CONFIG_VERBOSE 01
 int install_branch_config(int flag, const char *local, const char *origin, const char *remote);
+void install_branch_base(const char *local, const struct object_id *tail);
 
 /*
  * Read branch description
diff --git a/builtin/clone.c b/builtin/clone.c
index 65b5b7db6d..62afcff2ba 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -624,6 +624,7 @@ static void update_head(const struct ref *our, const struct ref *remote,
 			update_ref(msg, "HEAD", &our->old_oid, NULL, 0,
 				   UPDATE_REFS_DIE_ON_ERR);
 			install_branch_config(0, head, remote_name, our->name);
+			install_branch_base(head, &our->old_oid);
 		}
 	} else if (our) {
 		struct commit *c = lookup_commit_reference(the_repository,
diff --git a/t/t1514-rev-parse-tail.sh b/t/t1514-rev-parse-tail.sh
new file mode 100755
index 0000000000..da8e9ceef1
--- /dev/null
+++ b/t/t1514-rev-parse-tail.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+test_description='test <branch>@{upstream} syntax'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+	echo one > content &&
+	git add content &&
+	git commit -m one &&
+	git checkout -b test master &&
+	echo two > new &&
+	git add new &&
+	git commit -a -m two
+'
+
+test_expect_success 'test tail creation' '
+	git rev-parse refs/tails/test > actual &&
+	git rev-parse master > expect &&
+	test_cmp expect actual
+'
+
+test_done
-- 
2.40.0.rc2.1.gf652911b76.dirty


  reply	other threads:[~2023-03-10 21:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-10 21:45 [RFC PATCH 0/3] Support for tail (branch point) experiment Felipe Contreras
2023-03-10 21:45 ` Felipe Contreras [this message]
2023-03-10 21:45 ` [RFC PATCH 2/3] sha1-name: add @{tail} helpers Felipe Contreras
2023-03-10 21:45 ` [RFC PATCH 3/3] rebase: update branch tail after rebasing Felipe Contreras
2023-03-11  0:04 ` [RFC PATCH 0/3] Support for tail (branch point) experiment Junio C Hamano
2023-03-11  3:26   ` Felipe Contreras

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230310214515.39154-2-felipe.contreras@gmail.com \
    --to=felipe.contreras@gmail.com \
    --cc=anarcat@debian.org \
    --cc=git@vger.kernel.org \
    --cc=phillip.wood@dunelm.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).