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

4 messages from 2008-09-22 to 2008-09-23. Participants: Linus Torvalds, Brandon Casey, David Tweed, Petr Baudis.
Thread: https://gitlist.dev/t/15625

## Petr Baudis, 2008-09-22 17:20

Subject: [PATCH] Do not perform cross-directory renames when creating packs
Message-ID: <1222104021-28277-1-git-send-email-pasky@suse.cz>
URL: https://gitlist.dev/e/1222104021-28277-1-git-send-email-pasky%40suse.cz

```
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(-)

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, 2008-09-22 17:31

Subject: Re: [PATCH] Do not perform cross-directory renames when creating packs
Message-ID: <alpine.LFD.1.10.0809221029240.3265@nehalem.linux-foundation.org>
URL: https://gitlist.dev/e/alpine.LFD.1.10.0809221029240.3265%40nehalem.linux-foundation.org
In-Reply-To: <1222104021-28277-1-git-send-email-pasky@suse.cz>

```


On Mon, 22 Sep 2008, Petr Baudis wrote:
>
> 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, 2008-09-22 23:34

Subject: [PATCH] builtin-prune.c: prune temporary packs in <object_dir>/pack directory
Message-ID: <KKSursEoVthEbqc_O82_QIafgU9zgb4bQYP7w6x9ulU85L2Nixe_9g@cipher.nrlssc.navy.mil>
URL: https://gitlist.dev/e/KKSursEoVthEbqc_O82_QIafgU9zgb4bQYP7w6x9ulU85L2Nixe_9g%40cipher.nrlssc.navy.mil
In-Reply-To: <1222104021-28277-1-git-send-email-pasky@suse.cz>

```
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.
  */
-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, 2008-09-23 05:37

Subject: Re: [PATCH] builtin-prune.c: prune temporary packs in <object_dir>/pack directory
Message-ID: <e1dab3980809222237v612bfc82n8865ada7f0e4516d@mail.gmail.com>
URL: https://gitlist.dev/e/e1dab3980809222237v612bfc82n8865ada7f0e4516d%40mail.gmail.com
In-Reply-To: <KKSursEoVthEbqc_O82_QIafgU9zgb4bQYP7w6x9ulU85L2Nixe_9g@cipher.nrlssc.navy.mil>

```
On Tue, Sep 23, 2008 at 12:34 AM, Brandon Casey <casey@nrlssc.navy.mil> wrote:
> 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

```
