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

[PATCH 2/2] checkout: fix attribute handling in checkout all

From
Steffen Prohaska <prohaska@zib.de>
Date
Aug 12, 2007, 20:34 UTC
Message-ID
<118695087531-git-send-email-prohaska@zib.de>
In-Reply-To
<11869508753328-git-send-email-prohaska@zib.de>

We need to check out .gitattributes files first to have them in place when we check out the remaining files. This is needed to get the right attributes during checkout, for example having the right crlf conversion on the first checkout if crlf is controlled by a .gitattribute file.

This works only together with the commit
'attr: fix attribute handling if .gitattributes is involved'

which ensures that .gitattributes files do not trigger the attribute machinery too early.

Signed-off-by: Steffen Prohaska <prohaska@zib.de>
---
 builtin-checkout-index.c |   47 ++++++++++++++++++++++++++++-----------------
 1 files changed, 29 insertions(+), 18 deletions(-)
diff --git a/builtin-checkout-index.c b/builtin-checkout-index.c
index 75377b9..5e87a39 100644
--- a/builtin-checkout-index.c
+++ b/builtin-checkout-index.c
@@ -125,27 +125,38 @@ static int checkout_file(const char *name, int prefix_length)
 
 static void checkout_all(const char *prefix, int prefix_length)
 {
-	int i, errs = 0;
+	int i, pass, errs = 0;
 	struct cache_entry* last_ce = NULL;
 
-	for (i = 0; i < active_nr ; i++) {
-		struct cache_entry *ce = active_cache[i];
-		if (ce_stage(ce) != checkout_stage
-		    && (CHECKOUT_ALL != checkout_stage || !ce_stage(ce)))
-			continue;
-		if (prefix && *prefix &&
-		    (ce_namelen(ce) <= prefix_length ||
-		     memcmp(prefix, ce->name, prefix_length)))
-			continue;
-		if (last_ce && to_tempfile) {
-			if (ce_namelen(last_ce) != ce_namelen(ce)
-			    || memcmp(last_ce->name, ce->name, ce_namelen(ce)))
-				write_tempfile_record(last_ce->name, prefix_length);
+	/* pass 0: check out only .gitattribute files
+	   pass 1: check out every file
+
+	   This is needed to have all .gitattributes in place before
+	   checking out files, and thus do the right conversion.
+	 */
+	for (pass = 0; pass < 2; pass++) {
+		for (i = 0; i < active_nr ; i++) {
+			struct cache_entry *ce = active_cache[i];
+			if (pass == 0 && strstr (ce->name, GITATTRIBUTES_FILE) == 0) {
+			    continue;
+			}
+			if (ce_stage(ce) != checkout_stage
+			    && (CHECKOUT_ALL != checkout_stage || !ce_stage(ce)))
+				continue;
+			if (prefix && *prefix &&
+			    (ce_namelen(ce) <= prefix_length ||
+			     memcmp(prefix, ce->name, prefix_length)))
+				continue;
+			if (last_ce && to_tempfile) {
+				if (ce_namelen(last_ce) != ce_namelen(ce)
+				    || memcmp(last_ce->name, ce->name, ce_namelen(ce)))
+					write_tempfile_record(last_ce->name, prefix_length);
+			}
+			if (checkout_entry(ce, &state,
+			    to_tempfile ? topath[ce_stage(ce)] : NULL) < 0)
+				errs++;
+			last_ce = ce;
 		}
-		if (checkout_entry(ce, &state,
-		    to_tempfile ? topath[ce_stage(ce)] : NULL) < 0)
-			errs++;
-		last_ce = ce;
 	}
 	if (last_ce && to_tempfile)
 		write_tempfile_record(last_ce->name, prefix_length);
-- 
1.5.3.rc4.96.g6ceb
Previous: Steffen ProhaskaNext: Junio C Hamano
Message 2 of 20 in “attr: fix attribute handling if .gitattributes is involved”
  1. 1/2 attr: fix attribute handling if .gitattributes is involvedSteffen Prohaska, Aug 12, 2007
  2. 2/2 checkout: fix attribute handling in checkout allSteffen Prohaska, Aug 12, 2007
  3. Junio C HamanoAug 12, 2007
  4. Steffen ProhaskaAug 12, 2007
  5. Junio C HamanoAug 13, 2007
  6. Marius Storm-OlsenAug 13, 2007
  7. Steffen ProhaskaAug 13, 2007
  8. Marius Storm-OlsenAug 13, 2007
  9. Steffen ProhaskaAug 13, 2007
  10. Marius Storm-OlsenAug 13, 2007
  11. Steffen ProhaskaAug 13, 2007
  12. Dmitry KakurinAug 13, 2007
  13. 1/2 attr.c: refactoringJunio C Hamano, Aug 14, 2007
  14. 2/2 attr.c: read .gitattributes from index as well.Junio C Hamano, Aug 14, 2007
  15. Steffen ProhaskaAug 13, 2007
  16. Johannes SchindelinAug 13, 2007
  17. David KastrupAug 13, 2007
  18. git-update-ref bug? (was: [PATCH 2/2] checkout: fix attribute handling in checkout all)David Kastrup, Aug 13, 2007
  19. Junio C HamanoAug 13, 2007
  20. Brian DowningAug 13, 2007

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.