threads / patch / 15625

patchRe: [PATCH] Do not perform cross-directory renames when creating packs

Subject: Re: [PATCH] Do not perform cross-directory renames when creating packs

## tl;dr

4 messages between Sep 22, 2008 and Sep 23, 2008. Diffs are folded; open one to read it.

replies: 3people: 4as markdown or json

Petr Baudis· Sep 22, 2008, 17:20 UTC · lore

[PATCH] Do not perform cross-directory renames when creating packs

A comment on top of create_tmpfile() describes caveats ('can have problems on various systems (FAT, NFS, Coda)') that should apply in this situation as well. This in the end did not end up solving any of my personal problems, but it might be a useful cleanup patch nevertheless.

Signed-off-by: Petr Baudis <pasky@suse.cz>
---
If this one gets dropped now, I don't intend pursuing it further.
 builtin-pack-objects.c |    2 +-
 fast-import.c          |    4 ++--
 index-pack.c           |    2 +-
 pack-write.c           |    2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)
Show changes to 4 files +5 −5

builtin-pack-objects.c, fast-import.c, index-pack.c, pack-write.c

diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
index 5fc1b8c..1158e42 100644
--- a/builtin-pack-objects.c
+++ b/builtin-pack-objects.c
@@ -465,7 +465,7 @@ static void write_pack_file(void)
 			char tmpname[PATH_MAX];
 			int fd;
 			snprintf(tmpname, sizeof(tmpname),
-				 "%s/tmp_pack_XXXXXX", get_object_directory());
+				 "%s/pack/tmp_pack_XXXXXX", get_object_directory());
 			fd = xmkstemp(tmpname);
 			pack_tmp_name = xstrdup(tmpname);
 			f = sha1fd(fd, pack_tmp_name);
diff --git a/fast-import.c b/fast-import.c
index ccdf2e5..ab6689a 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -816,7 +816,7 @@ static void start_packfile(void)
 	int pack_fd;
 
 	snprintf(tmpfile, sizeof(tmpfile),
-		"%s/tmp_pack_XXXXXX", get_object_directory());
+		"%s/pack/tmp_pack_XXXXXX", get_object_directory());
 	pack_fd = xmkstemp(tmpfile);
 	p = xcalloc(1, sizeof(*p) + strlen(tmpfile) + 2);
 	strcpy(p->pack_name, tmpfile);
@@ -878,7 +878,7 @@ static char *create_index(void)
 	}
 
 	snprintf(tmpfile, sizeof(tmpfile),
-		"%s/tmp_idx_XXXXXX", get_object_directory());
+		"%s/pack/tmp_idx_XXXXXX", get_object_directory());
 	idx_fd = xmkstemp(tmpfile);
 	f = sha1fd(idx_fd, tmpfile);
 	sha1write(f, array, 256 * sizeof(int));
diff --git a/index-pack.c b/index-pack.c
index a6e91fe..530d820 100644
--- a/index-pack.c
+++ b/index-pack.c
@@ -172,7 +172,7 @@ static char *open_pack_file(char *pack_name)
 		if (!pack_name) {
 			static char tmpfile[PATH_MAX];
 			snprintf(tmpfile, sizeof(tmpfile),
-				 "%s/tmp_pack_XXXXXX", get_object_directory());
+				 "%s/pack/tmp_pack_XXXXXX", get_object_directory());
 			output_fd = xmkstemp(tmpfile);
 			pack_name = xstrdup(tmpfile);
 		} else
diff --git a/pack-write.c b/pack-write.c
index 939ed56..3621f1d 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -45,7 +45,7 @@ char *write_idx_file(char *index_name, struct pack_idx_entry **objects,
 	if (!index_name) {
 		static char tmpfile[PATH_MAX];
 		snprintf(tmpfile, sizeof(tmpfile),
-			 "%s/tmp_idx_XXXXXX", get_object_directory());
+			 "%s/pack/tmp_idx_XXXXXX", get_object_directory());
 		fd = xmkstemp(tmpfile);
 		index_name = xstrdup(tmpfile);
 	} else {
-- 
tg: (fe33b33..) t/pack/crossdir (depends on: vanilla/master)
Linus Torvalds· Sep 22, 2008, 17:31 UTC · re: Petr Baudis · lore
On Mon, 22 Sep 2008, Petr Baudis wrote:
Show 6 quoted lines
>
> A comment on top of create_tmpfile() describes caveats ('can have
> problems on various systems (FAT, NFS, Coda)') that should apply
> in this situation as well.  This in the end did not end up solving
> any of my personal problems, but it might be a useful cleanup patch
> nevertheless.

Side note: the cross-directory avoidance for loose object creation _did_ seem to clear up the original problems reported on NFS, so yes, this is worth doing. Even if pack-file creation is such a heavy event that I suspect that none of the timing/caching/whatever issues that were present for loose objects really ever trigger in practice.

> Signed-off-by: Petr Baudis <pasky@suse.cz>
Looks obvious enough. So:
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
		Linus
Brandon Casey· Sep 22, 2008, 23:34 UTC · re: Petr Baudis · lore

[PATCH] builtin-prune.c: prune temporary packs in <object_dir>/pack directory

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
---
Re: [PATCH] Do not perform cross-directory renames when creating packs
I think something like this should be applied on top.
-brandon
 builtin-prune.c |   18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)
Show changes to builtin-prune.c +10 −8
diff --git a/builtin-prune.c b/builtin-prune.c
index c767a0a..fc8be45 100644
--- a/builtin-prune.c
+++ b/builtin-prune.c
@@ -13,7 +13,7 @@ static const char * const prune_usage[] = {
 static int show_only;
 static unsigned long expire;
 
-static int prune_tmp_object(char *path, const char *filename)
+static int prune_tmp_object(const char *path, const char *filename)
 {
 	const char *fullpath = mkpath("%s/%s", path, filename);
 	if (expire) {
@@ -113,21 +113,19 @@ static void prune_object_dir(const char *path)
  * files begining with "tmp_") accumulating in the
  * object directory.
  */
-static void remove_temporary_files(void)
+static void remove_temporary_files(const char *path)
 {
 	DIR *dir;
 	struct dirent *de;
-	char* dirname=get_object_directory();
 
-	dir = opendir(dirname);
+	dir = opendir(path);
 	if (!dir) {
-		fprintf(stderr, "Unable to open object directory %s\n",
-			dirname);
+		fprintf(stderr, "Unable to open directory %s\n", path);
 		return;
 	}
 	while ((de = readdir(dir)) != NULL)
 		if (!prefixcmp(de->d_name, "tmp_"))
-			prune_tmp_object(dirname, de->d_name);
+			prune_tmp_object(path, de->d_name);
 	closedir(dir);
 }
 
@@ -141,6 +139,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
 			 "expire objects older than <time>"),
 		OPT_END()
 	};
+	char *s;
 
 	save_commit_buffer = 0;
 	init_revisions(&revs, prefix);
@@ -163,6 +162,9 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
 	prune_object_dir(get_object_directory());
 
 	prune_packed_objects(show_only);
-	remove_temporary_files();
+	remove_temporary_files(get_object_directory());
+	s = xstrdup(mkpath("%s/pack", get_object_directory()));
+	remove_temporary_files(s);
+	free(s);
 	return 0;
 }
-- 
1.6.0.1.244.gdc19
David Tweed· Sep 23, 2008, 05:37 UTC · re: Brandon Casey · lore

Re: [PATCH] builtin-prune.c: prune temporary packs in <object_dir>/pack directory

On Tue, Sep 23, 2008 at 12:34 AM, Brandon Casey <casey@nrlssc.navy.mil> wrote:
Show 30 quoted lines
> Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
> ---
>
> Re: [PATCH] Do not perform cross-directory renames when creating packs
>
> I think something like this should be applied on top.
>
> -brandon
>
>
>  builtin-prune.c |   18 ++++++++++--------
>  1 files changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/builtin-prune.c b/builtin-prune.c
> index c767a0a..fc8be45 100644
> --- a/builtin-prune.c
> +++ b/builtin-prune.c
> @@ -13,7 +13,7 @@ static const char * const prune_usage[] = {
>  static int show_only;
>  static unsigned long expire;
>
> -static int prune_tmp_object(char *path, const char *filename)
> +static int prune_tmp_object(const char *path, const char *filename)
>  {
>        const char *fullpath = mkpath("%s/%s", path, filename);
>        if (expire) {
> @@ -113,21 +113,19 @@ static void prune_object_dir(const char *path)
>  * files begining with "tmp_") accumulating in the
>  * object directory.
>  */

Good spotting. I haven't been remotely involved with git recently but for what little it's worth looks the right thing to me. It'd be nice to modify the patch to keep the comment up to date, something like:

* accumulating in the
* object directory (older git versions) or pack directory.
*/
-- 
cheers, dave tweed__________________________
david.tweed@gmail.com
Rm 124, School of Systems Engineering, University of Reading.
"while having code so boring anyone can maintain it, use Python." --
attempted insult seen on slashdot

← back to recent threads