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

[PATCH 1/3] Refactoring: Split up diff_tree_stdin

From
Karl Hasselström <kha@treskal.com>
Date
Aug 8, 2008, 20:48 UTC
Message-ID
<20080808204823.7744.57203.stgit@yoghurt>
In-Reply-To
<20080808204348.7744.46006.stgit@yoghurt>

Into a first half that determines what operation to do, and a second half that does it.

Currently the only operation is diffing one or more commits, but a later patch will add diffing of trees, at which point this refactoring will pay off.

Signed-off-by: Karl Hasselström <kha@treskal.com>
---
 builtin-diff-tree.c |   31 +++++++++++++++++++------------
 1 files changed, 19 insertions(+), 12 deletions(-)
diff --git a/builtin-diff-tree.c b/builtin-diff-tree.c
index 415cb16..ebbd631 100644
--- a/builtin-diff-tree.c
+++ b/builtin-diff-tree.c
@@ -14,20 +14,10 @@ static int diff_tree_commit_sha1(const unsigned char *sha1)
 	return log_tree_commit(&log_tree_opt, commit);
 }
 
-static int diff_tree_stdin(char *line)
+/* Diff one or more commits. */
+static int stdin_diff_commit(struct commit *commit, char *line, int len)
 {
-	int len = strlen(line);
 	unsigned char sha1[20];
-	struct commit *commit;
-
-	if (!len || line[len-1] != '\n')
-		return -1;
-	line[len-1] = 0;
-	if (get_sha1_hex(line, sha1))
-		return -1;
-	commit = lookup_commit(sha1);
-	if (!commit || parse_commit(commit))
-		return -1;
 	if (isspace(line[40]) && !get_sha1_hex(line+41, sha1)) {
 		/* Graft the fake parents locally to the commit */
 		int pos = 41;
@@ -52,6 +42,23 @@ static int diff_tree_stdin(char *line)
 	return log_tree_commit(&log_tree_opt, commit);
 }
 
+static int diff_tree_stdin(char *line)
+{
+	int len = strlen(line);
+	unsigned char sha1[20];
+	struct commit *commit;
+
+	if (!len || line[len-1] != '\n')
+		return -1;
+	line[len-1] = 0;
+	if (get_sha1_hex(line, sha1))
+		return -1;
+	commit = lookup_commit(sha1);
+	if (!commit || parse_commit(commit))
+		return -1;
+	return stdin_diff_commit(commit, line, len);
+}
+
 static const char diff_tree_usage[] =
 "git diff-tree [--stdin] [-m] [-c] [--cc] [-s] [-v] [--pretty] [-t] [-r] [--root] "
 "[<common diff options>] <tree-ish> [<tree-ish>] [<path>...]\n"
Previous: Karl HasselströmNext: Karl Hasselström
Message 2 of 14 in “Teach git diff-tree --stdin to diff trees”
  1. 0/3 Teach git diff-tree --stdin to diff treesKarl Hasselström, Aug 8, 2008
  2. 1/3 Refactoring: Split up diff_tree_stdinKarl Hasselström, Aug 8, 2008
  3. 2/3 Teach git diff-tree --stdin to diff treesKarl Hasselström, Aug 8, 2008
  4. Junio C HamanoAug 8, 2008
  5. Karl HasselströmAug 9, 2008
  6. 2/3 Teach git diff-tree --stdin to diff treesKarl Hasselström, Aug 9, 2008
  7. Junio C HamanoAug 9, 2008
  8. Karl HasselströmAug 10, 2008
  9. Junio C HamanoAug 9, 2008
  10. Karl HasselströmAug 9, 2008
  11. Jeff KingAug 8, 2008
  12. Karl HasselströmAug 9, 2008
  13. Jeff KingAug 11, 2008
  14. 3/3 Add test for diff-tree --stdin with two treesKarl Hasselström, Aug 8, 2008

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.