threads / patch / 15578

patchMake git archive respect core.autocrlf when creating zip format archives

Subject: [PATCH 1/1] Make git archive respect core.autocrlf when creating zip format archives

## tl;dr

6 messages between Sep 18, 2008 and Sep 18, 2008. Diffs are folded; open one to read it.

replies: 5people: 4as markdown or json

Charles Bailey· Sep 18, 2008, 20:01 UTC · lore

There is currently no call to git_config at the start of cmd_archive. When creating tar archives the core config is read as a side-effect of reading the tar specific config, but this doesn't happen for zip archives.

The consequence is that in a configuration with core.autocrlf set, although files in a tar archive are created with crlf line endings, files in a zip archive retain unix line endings.

Signed-off-by: Charles Bailey <charles@hashpling.org>
---

It took me a while to find the cause of the difference in behaviour between tar and zip format archives when all the crlf fixing code seemed to be in code shared by both archiving processes. I'm 99% sure that creating zip archives from repositories with core.autocrlf set to true should create zip entries with crlf line endings but it would be good to have that confirmed.

 builtin-archive.c       |    2 ++
 t/t0024-crlf-archive.sh |    2 +-
 2 files changed, 3 insertions(+), 1 deletions(-)
Show changes to 2 files +3 −1

builtin-archive.c, t/t0024-crlf-archive.sh

diff --git a/builtin-archive.c b/builtin-archive.c
index 5ceec43..432ce2a 100644
--- a/builtin-archive.c
+++ b/builtin-archive.c
@@ -111,6 +111,8 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
 {
 	const char *remote = NULL;
 
+	git_config(git_default_config, NULL);
+
 	remote = extract_remote_arg(&argc, argv);
 	if (remote)
 		return run_remote_archiver(remote, argc, argv);
diff --git a/t/t0024-crlf-archive.sh b/t/t0024-crlf-archive.sh
index 3511439..e533039 100644
--- a/t/t0024-crlf-archive.sh
+++ b/t/t0024-crlf-archive.sh
@@ -33,7 +33,7 @@ if [ $? -eq 127 ]; then
 	exit
 fi
 
-test_expect_failure 'zip archive' '
+test_expect_success 'zip archive' '
 
 	git archive --format=zip HEAD >test.zip &&
 
-- 
1.6.0.1.309.g4f56
Charles Bailey· Sep 18, 2008, 20:08 UTC · re: Charles Bailey · lore

Re: [PATCH 1/1] Make git archive respect core.autocrlf when creating zip format archives

Apologies for the bad threading headers and the weird characters in the subject.

While I though I'd remembered how git format-patch and my mail client worked together, it's obvious that I hadn't.

I'll make sure that I get it right in the final patch, but in the mean time are there any comments on this?

Charles.
Andreas Ericsson· Sep 18, 2008, 20:21 UTC · re: Charles Bailey · lore

Re: [PATCH 1/1] Make git archive respect core.autocrlf when creating zip format archives

Charles Bailey wrote:
Show 19 quoted lines
> There is currently no call to git_config at the start of cmd_archive.
> When creating tar archives the core config is read as a side-effect of
> reading the tar specific config, but this doesn't happen for zip
> archives.
> 
> The consequence is that in a configuration with core.autocrlf set,
> although files in a tar archive are created with crlf line endings,
> files in a zip archive retain unix line endings.
> 
> Signed-off-by: Charles Bailey <charles@hashpling.org>
> ---
> 
> It took me a while to find the cause of the difference in behaviour
> between tar and zip format archives when all the crlf fixing code
> seemed to be in code shared by both archiving processes. I'm 99% sure
> that creating zip archives from repositories with core.autocrlf set to
> true should create zip entries with crlf line endings but it would be
> good to have that confirmed.
> 

If it fixes the broken test while all the other tests still pass, I can only assume it's doing something right.

The topic is a bit long though. Could you change it to "git archive: respect core.autocrlf when creating zip archives" so that it fits comfortably in one line when running "git log" on 80 char wide terminals?

As a side-note, you needn't put "1/1" in the [PATCH] section. That's usually done to make sure patches are applied in the right order when sending a series, but since a series of 1 is kinda hard to jumble.. ;-)

-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
Charles Bailey· Sep 18, 2008, 20:29 UTC · re: Andreas Ericsson · lore

Re: [PATCH 1/1] Make git archive respect core.autocrlf when creating ...

On Thu, Sep 18, 2008 at 10:21:05PM +0200, Andreas Ericsson wrote:
> If it fixes the broken test while all the other tests still
> pass, I can only assume it's doing something right.
Only if you believe that I added a sensible test in the first place :-)
> The topic is a bit long though. Could you change it to
> "git archive: respect core.autocrlf when creating zip archives"
> so that it fits comfortably in one line when running "git log"
> on 80 char wide terminals?

Sorry, I made it <= 72 chars in my commit message and then forgot that git format-patch adds the [PATCH] tag.

> As a side-note, you needn't put "1/1" in the [PATCH] section.
> That's usually done to make sure patches are applied in the
> right order when sending a series, but since a series of 1
> is kinda hard to jumble.. ;-)

I thought that the patch (a single commit) didn't really warrant a patch series - being a one liner - but I made the test 0 of 1 so that people could see the test failure first before deciding whether my proposed patch was good or not. Sorry for the confusion.

Charles.
Sverre Rabbelier· Sep 18, 2008, 20:53 UTC · re: Charles Bailey · lore

Re: [PATCH 1/1] Make git archive respect core.autocrlf when creating ...

On Thu, Sep 18, 2008 at 22:29, Charles Bailey <charles@hashpling.org> wrote:
> I thought that the patch (a single commit) didn't really warrant a patch
> series - being a one liner - but I made the test 0 of 1 so that people
> could see the test failure first before deciding whether my proposed
> patch was good or not. Sorry for the confusion.

Shouldn't the tests be part of the patch? ;) To prevent it from being broken again that is.

-- 
Cheers,

Sverre Rabbelier
René Scharfe· Sep 18, 2008, 20:41 UTC · re: Charles Bailey · lore

Re: [PATCH 1/1] Make git archive respect core.autocrlf when creating zip format archives

Charles Bailey schrieb:
Show 8 quoted lines
> There is currently no call to git_config at the start of cmd_archive.
> When creating tar archives the core config is read as a side-effect of
> reading the tar specific config, but this doesn't happen for zip
> archives.
> 
> The consequence is that in a configuration with core.autocrlf set,
> although files in a tar archive are created with crlf line endings,
> files in a zip archive retain unix line endings.

The patches look good, but it took me a while to realize that there are two of them (0/1 and 1/1). :)

Thanks, René

← back to recent threads