git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/5] git-tar-tree: add get_record()
@ 2005-05-06 20:55 Rene Scharfe
  0 siblings, 0 replies; only message in thread
From: Rene Scharfe @ 2005-05-06 20:55 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: git

Add get_record() which returns a pointer to the next record in the block.

---
commit 487c69a1df2a28471e1cefc1ae592cb61a57530e
tree 2179101bba7891ba96b070265068edeb9233d435
parent e0965d83c533e8b6a51f1c6c1be12f5edee5ca65
author Rene Scharfe <rene.scharfe@lsrfire.ath.cx> 1115304529 +0200
committer Rene Scharfe <rene.scharfe@lsrfire.ath.cx> 1115304529 +0200

Index: tar-tree.c
===================================================================
--- c5ee2c11b8d4214dd6fde6388a12060e5d86b06c/tar-tree.c  (mode:100644 sha1:2c64f690e52093af13585521de4df478ac6e85e5)
+++ 2179101bba7891ba96b070265068edeb9233d435/tar-tree.c  (mode:100644 sha1:06f4ca480e0d212b51970debdbf97a3379225330)
@@ -45,6 +45,15 @@
 	}
 }
 
+/* acquire the next record from the buffer; user must call write_if_needed() */
+static char *get_record(void)
+{
+	char *p = block + offset;
+	memset(p, 0, RECORDSIZE);
+	offset += RECORDSIZE;
+	return p;
+}
+
 /*
  * The end of tar archives is marked by 1024 nul bytes and after that
  * follows the rest of the block (if any).
@@ -178,9 +187,7 @@
 	if (size > RECORDSIZE)
 		die("tar-tree: extended header too big, wtf?");
 	write_header(NULL, 'x', NULL, NULL, headerfilename, 0100600, size);
-	p = block + offset;
-	memset(p, 0, RECORDSIZE);
-	offset += RECORDSIZE;
+	p = get_record();
 	append_long(&p, size);
 	append_string(&p, " path=");
 	append_path(&p, is_dir, basepath, prefix, path);
@@ -192,9 +199,7 @@
 {
 	char *p;
 	write_header(NULL, 'g', NULL, NULL, "pax_global_header", 0, 52);
-	p = block + offset;
-	memset(p, 0, RECORDSIZE);
-	offset += RECORDSIZE;
+	p = get_record();
 	append_long(&p, 52);	/* 2 + 9 + 40 + 1 */
 	append_string(&p, " comment=");
 	append_string(&p, sha1_to_hex(sha1));
@@ -223,15 +228,10 @@
 		write_extended_header(headerfilename, S_ISDIR(mode), basepath,
 				      prefix, path, namelen);
 
-		header = block + offset;
-		memset(header, 0, RECORDSIZE);
-		offset += RECORDSIZE;
+		header = get_record();
 		sprintf(header, "%s.data", sha1_hex);
 	} else {
-		header = block + offset;
-		memset(header, 0, RECORDSIZE);
-		offset += RECORDSIZE;
-		p = header;
+		p = header = get_record();
 		append_path(&p, S_ISDIR(mode), basepath, prefix, path);
 	}
 


\f
!-------------------------------------------------------------flip-



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-05-06 20:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-06 20:55 [PATCH 1/5] git-tar-tree: add get_record() Rene Scharfe

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 NNTP newsgroup(s).