# [PATCH] git-p4: Fix support for symlinks.

4 messages from 2007-08-07 to 2007-08-08. Participants: Simon Hausmann, Junio C Hamano, Brian Swetland, Scott Lamb.
Thread: https://gitlist.dev/t/9421

## Simon Hausmann, 2007-08-07 08:25

Subject: [PATCH] git-p4: Fix support for symlinks.
Message-ID: <200708071025.47965.simon@lst.de>
URL: https://gitlist.dev/e/200708071025.47965.simon%40lst.de

```
Detect symlinks as file type, set the git file mode accordingly and strip off the trailing newline in the p4 print output.

Signed-off-by: Simon Hausmann <simon@lst.de>
---
 contrib/fast-import/git-p4 |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index 41e86e7..9c6f911 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -839,11 +839,15 @@ class P4Sync(Command):
             if file["action"] == "delete":
                 self.gitStream.write("D %s\n" % relPath)
             else:
+                data = file['data']
+
                 mode = 644
                 if file["type"].startswith("x"):
                     mode = 755
-
-                data = file['data']
+                elif file["type"] == "symlink":
+                    mode = 120000
+                    # p4 print on a symlink contains "target\n", so strip it off
+                    data = data[:-1]
 
                 if self.isWindows and file["type"].endswith("text"):
                     data = data.replace("\r\n", "\n")
-- 
1.5.3.rc3.91.g5c75


```

## Junio C Hamano, 2007-08-07 08:40

Subject: Re: [PATCH] git-p4: Fix support for symlinks.
Message-ID: <7vtzrb68kq.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vtzrb68kq.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <200708071025.47965.simon@lst.de>

```
Simon Hausmann <simon@lst.de> writes:

> Detect symlinks as file type, set the git file mode accordingly and strip off the trailing newline in the p4 print output.
>
> Signed-off-by: Simon Hausmann <simon@lst.de>
> ---
>  contrib/fast-import/git-p4 |    8 ++++++--
>  1 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
> index 41e86e7..9c6f911 100755
> --- a/contrib/fast-import/git-p4
> +++ b/contrib/fast-import/git-p4
> @@ -839,11 +839,15 @@ class P4Sync(Command):
>              if file["action"] == "delete":
>                  self.gitStream.write("D %s\n" % relPath)
>              else:
> +                data = file['data']
> +
>                  mode = 644
>                  if file["type"].startswith("x"):
>                      mode = 755
> -
> -                data = file['data']
> +                elif file["type"] == "symlink":
> +                    mode = 120000
> +                    # p4 print on a symlink contains "target\n", so strip it off
> +                    data = data[:-1]
>  
>                  if self.isWindows and file["type"].endswith("text"):
>                      data = data.replace("\r\n", "\n")

Thanks for a quick fix.

Brian, does this resolve the issue for you?  I do not have an
access to p4 myself so I won't make a good judge in this area
myself.  An Ack is appreciated.

Simon, just a style nit.

Every time I see decimal integers 644 and/or 755, it interrupts
my flow of thought and forces me to read the change and its
surrounding text needlessly carefully.

If you read the code, you can see that this "mode" variable is
formatted with ("%d" % mode) for writing out, and is not used as
permission bit pattern in any bitwise operations, so you can
tell that these constants _are_ safe.  But it takes extra
efforts to convince yourself that they indeed are.

I would prefer this kind of thing to be written as either:

	mode = 0644
        "%o" % mode

or

	mode = "644"
        "%s" % mode

to make it clear that the author knew what he was doing when he
wrote the code.

```

## Brian Swetland, 2007-08-07 09:10

Subject: Re: [PATCH] git-p4: Fix support for symlinks.
Message-ID: <20070807091049.GA13308@bulgaria>
URL: https://gitlist.dev/e/20070807091049.GA13308%40bulgaria
In-Reply-To: <7vtzrb68kq.fsf@assigned-by-dhcp.cox.net>

```
[Junio C Hamano <gitster@pobox.com>]
> Simon Hausmann <simon@lst.de> writes:
> 
> [ patch for correct symlink handling ]
> 
> Thanks for a quick fix.
> 
> Brian, does this resolve the issue for you?  I do not have an
> access to p4 myself so I won't make a good judge in this area
> myself.  An Ack is appreciated.

Ack.

Looks good here.  I can now sync from the p4 tree into git, check out
from git and do a clean build, and everything's happy.

Thanks for the quick fix, Simon!

One observation on git-p4 -- it's a little memory hungry when processing
large syncs.  I haven't tried incremental syncs on top of the initial
one though -- if it's only the initial that's expensive it's not that
big a deal.

It seemed to top out around 988MB resident.  The branch I was importing
is about 562MB when checked out and the resulting git repository is
about 175MB.

Brian

```

## Scott Lamb, 2007-08-08 01:36

Subject: Re: [PATCH] git-p4: Fix support for symlinks.
Message-ID: <46B91E19.9010005@slamb.org>
URL: https://gitlist.dev/e/46B91E19.9010005%40slamb.org
In-Reply-To: <20070807091049.GA13308@bulgaria>

```
Brian Swetland wrote:
> One observation on git-p4 -- it's a little memory hungry when processing
> large syncs.  I haven't tried incremental syncs on top of the initial
> one though -- if it's only the initial that's expensive it's not that
> big a deal.
> 
> It seemed to top out around 988MB resident.  The branch I was importing
> is about 562MB when checked out and the resulting git repository is
> about 175MB.

While importing each change, I think git-p4 puts into memory two copies 
of the contents of all changed files, one in p4CmdList and one in 
readP4Files. (That's the raw contents, not just the delta.) I don't 
think there's any fundamental reason it couldn't stream them instead.

So incremental syncs may or may not take less memory. If the first 
change imports a huge project and no subsequent change ever touches all 
those files at once, then yeah. But if, say, you periodically change the 
copyright dates in all files in the repository, you'll have this memory 
usage whenever syncing such a change.

As long as we're listing git-p4 complaints, here are a couple of mine:

1) coding style. *self-nag* Simon Hausmann mentioned he was happy to 
accept patches...and I made one up a while ago; I just need to do a 
merge and final check that I haven't broken anything before sending it off.

2) it breaks on tempfile purges. My previous employer has these in their 
repository, and I think for the moment they're working around it by 
treating a "purge" as a "delete". If I read the Perforce documentation 
right, though, only the latest version of a tempfile's contents is kept 
in the repository anyway. Their history can't be captured accurately, so 
the proper thing is probably to omit tempfiles entirely. (And deleting 
files when they become tempfiles and creating files when they become a 
normal type.)

Best regards,
Scott

-- 
Scott Lamb <http://www.slamb.org/>

```
