git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Bertin Philippe via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Bertin Philippe <tumata.codes@gmail.com>,
	tumata <tumata.codes@gmail.com>
Subject: [PATCH] git-p4: properly initialize the largefiles
Date: Tue, 26 Apr 2022 18:59:29 +0000	[thread overview]
Message-ID: <pull.1253.git.git.1650999569737.gitgitgadget@gmail.com> (raw)

From: tumata <tumata.codes@gmail.com>

This commit takes care of initializing the largeFiles
with the already existing files referenced in the .gitattributes
instead of initializing with an empty set by default.

This makes it so that the 'git p4 sync' command works as
expected with git-lfs.

Signed-off-by: tumata <tumata.codes@gmail.com>
---
    git-p4: Properly initialize the largeFiles set so that it includes the
    already existing large files
    
    git-p4 sync isn't taking into account existing files that are managed by
    git-lfs. This is fine when doing git p4 clone but doing git p4 sync
    needs to take into account the files that are already managed by
    git-lfs.
    
    This change reads-in the .gitattributes and re-generate the data so that
    sync can iteratively add files to the git-lfs. It takes care of
    initializing the largeFiles with the already existing files referenced
    in the .gitattributes instead of initializing with an empty set by
    default.
    
    We had issues cloning the first commit, then syncing the remaining
    commits of a really large Perforce repo (making hundreds of smaller sync
    instead of one massive sync). The sync was deleting the git-lfs each
    time. We were able to fix this issue by first reading the current
    content of git-lfs instead of initializing to an empty set.
    
    Signed-off-by: tumata 5684571+tumata@users.noreply.github.com

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1253%2Ftumata%2Fgit-p4-initialize-large-files-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1253/tumata/git-p4-initialize-large-files-v1
Pull-Request: https://github.com/git/git/pull/1253

 git-p4.py | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/git-p4.py b/git-p4.py
index a9b1f904410..576e923a1de 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -1195,9 +1195,28 @@ class LargeFileSystem(object):
     """Base class for large file system support."""
 
     def __init__(self, writeToGitStream):
-        self.largeFiles = set()
+        self.largeFiles = self.parseLargeFiles()
         self.writeToGitStream = writeToGitStream
 
+    def parseLargeFiles(self):
+        """Parse large files in order to initially populate 'largeFiles'"""
+        paths = set()
+        try:
+            cmd = ['git', 'show', 'p4/master:.gitattributes']
+            p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
+            if p.returncode:
+                print("Failed to read .gitattributed - error code: " + p.returncode)
+                raise
+            out = p.stdout.readlines()
+            for line in out:
+                if line.startswith('/'):
+                    path = line[1:].split(' ', 1)[0]
+                    path = path.replace('[[:space:]]', ' ')
+                    paths.add(path)
+        except:
+            print("parseLargeFiles: .gitattributes does not appear to exist.")
+        return paths
+
     def generatePointer(self, cloneDestination, contentFile):
         """Return the content of a pointer file that is stored in Git instead of
            the actual content."""

base-commit: 6cd33dceed60949e2dbc32e3f0f5e67c4c882e1e
-- 
gitgitgadget

             reply	other threads:[~2022-04-26 19:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-26 18:59 Bertin Philippe via GitGitGadget [this message]
2022-04-26 20:40 ` [PATCH] git-p4: properly initialize the largefiles Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.1253.git.git.1650999569737.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=tumata.codes@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).