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

[PATCH 4/4] save another call to git-update-index

From
Alex Riesen <fork0@t-online.de>
Date
Jun 30, 2006, 00:27 UTC
Message-ID
<20060630002756.GD22618@steel.home>
and a small cleanup
---
 merge-recursive.c |   41 ++++++++++++++++++-----------------------
 1 files changed, 18 insertions(+), 23 deletions(-)
diff --git a/merge-recursive.c b/merge-recursive.c
index 9a18e06..f3f8e7d 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -21,7 +21,7 @@ #include "graph.h"
 #include "path-list.h"
 
 #define HAVE_ALLOCA
-#define DEBUG
+/*#define DEBUG*/
 
 #ifdef DEBUG
 #define debug(args, ...) fprintf(stderr, args, ## __VA_ARGS__)
@@ -629,8 +629,10 @@ static struct rename_entry *get_renames(
 					struct tree *bTree,
 					struct index_entry **entries)
 {
+#ifdef DEBUG
 	time_t t = time(0);
 	debug("getRenames ...\n");
+#endif
 	struct rename_entry *renames = NULL;
 	struct rename_entry **rptr = &renames;
 	struct diff_options opts;
@@ -691,22 +693,16 @@ static int update_stages(FILE *up_index,
 {
 	if ( !up_index )
 		return -1;
-	if ( clear ) {
+	if ( clear )
 		fprintf(up_index, "0 %s\t%s", sha1_to_hex(null_sha1), path);
-		fputc('\0', up_index);
-	}
-	if ( omode ) {
+	if ( omode )
 		fprintf(up_index, "0%o %s 1\t%s", omode, sha1_to_hex(osha), path);
-		fputc('\0', up_index);
-	}
-	if ( amode ) {
+	if ( amode )
 		fprintf(up_index, "0%o %s 2\t%s", amode, sha1_to_hex(asha), path);
-		fputc('\0', up_index);
-	}
-	if ( bmode ) {
+	if ( bmode )
 		fprintf(up_index, "0%o %s 3\t%s", bmode, sha1_to_hex(bsha), path);
+	if ( clear || omode || amode || bmode )
 		fputc('\0', up_index);
-	}
 	return 0;
 }
 
@@ -1080,7 +1076,8 @@ static void conflict_rename_rename_2(FIL
 	free(newPath1);
 }
 
-static int process_renames(struct rename_entry *renamesA,
+static int process_renames(FILE* fp,
+			   struct rename_entry *renamesA,
 			   struct rename_entry *renamesB,
 			   const char *branchNameA,
 			   const char *branchNameB)
@@ -1097,7 +1094,6 @@ static int process_renames(struct rename
 	for (sre = renamesB; sre; sre = sre->next)
 		path_list_insert(sre->pair->one->path, &srcNames);
 
-	FILE *fp = git_update_index_pipe();
 	for_each_path(src,&srcNames) {
 		struct rename_entry *renames1, *renames2, *ren1, *ren2;
 		const char *branchName1, *branchName2;
@@ -1282,9 +1278,6 @@ static int process_renames(struct rename
 		}
 	}
 	path_list_clear(&srcNames, 0);
-	if (pclose(fp)) {
-		die("git update-index --index-info failed");
-	}
 	debug("  processRenames done\n");
 	return cleanMerge;
 }
@@ -1467,24 +1460,26 @@ static struct merge_tree_result merge_tr
 		struct rename_entry *re_head, *re_merge;
 		re_head  = get_renames(head, common, head, merge, &entries);
 		re_merge = get_renames(merge, common, head, merge, &entries);
-		result.clean = process_renames(re_head, re_merge,
+		FILE *up_index = git_update_index_pipe();
+		result.clean = process_renames(up_index,
+					       re_head, re_merge,
 					       branch1Name, branch2Name);
 		debug("\tprocessing entries...\n");
-		FILE *fp = git_update_index_pipe();
 		struct index_entry *e;
 		for (e = entries; e; e = e->next) {
 			if (e->processed)
 				continue;
-			if (!process_entry(fp, e, branch1Name, branch2Name))
+			if (!process_entry(up_index, e,
+					   branch1Name, branch2Name))
 				result.clean = 0;
 		}
+		if (pclose(up_index))
+			die("updating entry failed in git update-index");
+
 		free_rename_entries(&re_merge);
 		free_rename_entries(&re_head);
 		free_index_entries(&entries);
 
-		if (pclose(fp))
-			die("updating entry failed in git update-index");
-
 		if (result.clean || index_only)
 			result.tree = git_write_tree();
 		else
-- 
1.4.1.rc1.g17dc
Next: Johannes Schindelin
Message 1 of 16 in “save another call to git-update-index”
  1. 4/4 save another call to git-update-indexAlex Riesen, Jun 30, 2006
  2. Johannes SchindelinJun 30, 2006
  3. Alex RiesenJun 30, 2006
  4. Johannes SchindelinJun 30, 2006
  5. Alex RiesenJun 30, 2006
  6. Johannes SchindelinJun 30, 2006
  7. 1/3 Add read_cache_from() and discard_cache()Johannes Schindelin, Jun 30, 2006
  8. Junio C HamanoJun 30, 2006
  9. Johannes SchindelinJul 1, 2006
  10. Junio C HamanoJul 1, 2006
  11. Johannes SchindelinJul 2, 2006
  12. Junio C HamanoJul 3, 2006
  13. Johannes SchindelinJul 4, 2006
  14. Junio C HamanoJul 4, 2006
  15. 2/3 Make refresh_cache_entry() publicJohannes Schindelin, Jun 30, 2006
  16. 3/3 merge-recursive: avoid the pipe to update-indexJohannes Schindelin, Jun 30, 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.