git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/5] git-commit-tree: add support for prior

From
Sam Vilain <sam.vilain@catalyst.net.nz>
Date
Apr 25, 2006, 04:31 UTC
Message-ID
<20060425043107.18382.21313.stgit@localhost.localdomain>
In-Reply-To
<20060425035421.18382.51677.stgit@localhost.localdomain>
From: Sam Vilain <sam.vilain@catalyst.net.nz>

Add support in git-commit-tree for -r as well as associated documentation. ---

 Documentation/git-commit-tree.txt |    6 ++++++
 commit-tree.c                     |   26 +++++++++++++++++++++-----
 2 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-commit-tree.txt b/Documentation/git-commit-tree.txt
index 27b3d12..e11ba1f 100644
--- a/Documentation/git-commit-tree.txt
+++ b/Documentation/git-commit-tree.txt
@@ -20,6 +20,9 @@ A commit object usually has 1 parent (a 
 to 16 parents.  More than one parent represents a merge of branches
 that led to them.
 
+A commit object can have 1 prior commit.  This represents the previous
+commit that this one replaces (including history).
+
 While a tree represents a particular directory state of a working
 directory, a commit represents that state in "time", and explains how
 to get there.
@@ -38,6 +41,8 @@ OPTIONS
 -p <parent commit>::
 	Each '-p' indicates the id of a parent commit object.
 	
+-r <other commit>::
+	One '-r' indicates the id of a prior commit object.
 
 Commit Information
 ------------------
@@ -45,6 +50,7 @@ Commit Information
 A commit encapsulates:
 
 - all parent object ids
+- a prior object id (optional)
 - author name, email and date
 - committer name and email and the commit time.
 
diff --git a/commit-tree.c b/commit-tree.c
index 2d86518..6660b01 100644
--- a/commit-tree.c
+++ b/commit-tree.c
@@ -61,8 +61,9 @@ static void check_valid(unsigned char *s
  */
 #define MAXPARENT (16)
 static unsigned char parent_sha1[MAXPARENT][20];
+static unsigned char prior_sha1[21] = "\0";
 
-static const char commit_tree_usage[] = "git-commit-tree <sha1> [-p <sha1>]* < changelog";
+static const char commit_tree_usage[] = "git-commit-tree <sha1> [-p <sha1>]* [-r <sha1>] < changelog";
 
 static int new_parent(int idx)
 {
@@ -99,11 +100,22 @@ int main(int argc, char **argv)
 	for (i = 2; i < argc; i += 2) {
 		char *a, *b;
 		a = argv[i]; b = argv[i+1];
-		if (!b || strcmp(a, "-p") || get_sha1(b, parent_sha1[parents]))
+		if (!b)
 			usage(commit_tree_usage);
-		check_valid(parent_sha1[parents], commit_type);
-		if (new_parent(parents))
-			parents++;
+		if (!strcmp(a, "-p")) {
+			if (get_sha1(b, parent_sha1[parents]) < 0)
+				usage(commit_tree_usage);
+			check_valid(parent_sha1[parents], commit_type);
+			if (new_parent(parents))
+				parents++;
+		}
+		else if (!strcmp(a, "-r")) {
+			if (strcmp(&prior_sha1, "") || get_sha1(b, &prior_sha1) < 0)
+				usage(commit_tree_usage);
+		}
+		else {
+			usage(commit_tree_usage);
+		}
 	}
 	if (!parents)
 		fprintf(stderr, "Committing initial tree %s\n", argv[1]);
@@ -118,6 +130,10 @@ int main(int argc, char **argv)
 	 */
 	for (i = 0; i < parents; i++)
 		add_buffer(&buffer, &size, "parent %s\n", sha1_to_hex(parent_sha1[i]));
+	if (strcmp(&prior_sha1, "")) {
+		fprintf(stderr, "Setting prior to %s\n", sha1_to_hex(&prior_sha1));
+		add_buffer(&buffer, &size, "prior %s\n", sha1_to_hex(&prior_sha1));
+	}
 
 	/* Person/date information */
 	add_buffer(&buffer, &size, "author %s\n", git_author_info(1));
Previous: Junio C HamanoNext: Sam Vilain
Message 6 of 63 in “Implement 'prior' commit object links”
  1. Sam VilainApr 25, 2006
  2. 1/5 add 'prior' link in commit structureSam Vilain, Apr 25, 2006
  3. Junio C HamanoApr 25, 2006
  4. 2/5 git-merge-base: follow 'prior' links to find merge basesSam Vilain, Apr 25, 2006
  5. Junio C HamanoApr 25, 2006
  6. 4/5 git-commit-tree: add support for priorSam Vilain, Apr 25, 2006
  7. 5/5 git-commit: add --prior to set prior linkSam Vilain, Apr 25, 2006
  8. 3/5 commit.c: parse 'prior' linkSam Vilain, Apr 25, 2006
  9. Sam VilainApr 25, 2006
  10. Junio C HamanoApr 25, 2006
  11. Sam VilainApr 25, 2006
  12. Jakub NarebskiApr 26, 2006
  13. Jakub NarebskiApr 26, 2006
  14. [OT] Re: [RFC] [PATCH 0/5] Implement 'prior' commit object linksJunio C Hamano, Apr 26, 2006
  15. Jakub NarebskiApr 26, 2006
  16. Junio C HamanoApr 26, 2006
  17. Jakub NarebskiApr 26, 2006
  18. Junio C HamanoApr 26, 2006
  19. Jakub NarebskiApr 26, 2006
  20. Junio C HamanoApr 26, 2006
  21. Jakub NarebskiApr 26, 2006
  22. Sam VilainApr 26, 2006
  23. Jakub NarebskiApr 25, 2006
  24. Junio C HamanoApr 25, 2006
  25. Jakub NarebskiApr 25, 2006
  26. seanApr 25, 2006
  27. Linus TorvaldsApr 25, 2006
  28. Linus TorvaldsApr 25, 2006
  29. seanApr 25, 2006
  30. Linus TorvaldsApr 25, 2006
  31. Andreas EricssonApr 26, 2006
  32. Jakub NarebskiApr 26, 2006
  33. Jakub NarebskiApr 25, 2006
  34. Linus TorvaldsApr 25, 2006
  35. Jakub NarebskiApr 25, 2006
  36. Linus TorvaldsApr 25, 2006
  37. Linus TorvaldsApr 25, 2006
  38. Jakub NarebskiApr 25, 2006
  39. seanApr 25, 2006
  40. Linus TorvaldsApr 25, 2006
  41. seanApr 25, 2006
  42. Linus TorvaldsApr 25, 2006
  43. Jakub NarebskiApr 25, 2006
  44. Linus TorvaldsApr 25, 2006
  45. Jakub NarebskiApr 25, 2006
  46. Jason RiedyApr 25, 2006
  47. seanApr 25, 2006
  48. Linus TorvaldsApr 25, 2006
  49. Junio C HamanoApr 25, 2006
  50. Linus TorvaldsApr 25, 2006
  51. Junio C HamanoApr 25, 2006
  52. Linus TorvaldsApr 25, 2006
  53. Jakub NarebskiApr 26, 2006
  54. Junio C HamanoApr 25, 2006
  55. Linus TorvaldsApr 25, 2006
  56. Jakub NarebskiApr 25, 2006
  57. Sam VilainApr 25, 2006
  58. Linus TorvaldsApr 25, 2006
  59. seanApr 25, 2006
  60. Jakub NarebskiApr 25, 2006
  61. Junio C HamanoApr 25, 2006
  62. Jakub NarebskiApr 25, 2006
  63. Jakub NarebskiApr 29, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.