Skip to contentSkip to conversation

git-p4: add support for large file systems

PATCH Superseded [email protected] 2 participants 9 messages Jun 15, 2016 Documentation

v4 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v4 cover git-p4: add support for large file systems

From: Lars Schneider <[email protected]>

Diff to v3:
* add large file system mock class for testing (Thanks Luke!)
* add early exit for compressed threshold: If a file is smaller then the threshold then we don't need to compress it.

Thanks,
Lars

Lars Schneider (5):
git-p4: add optional type specifier to gitConfig reader
git-p4: add gitConfigInt reader
git-p4: return an empty list if a list config has no values
git-p4: add support for large file systems
git-p4: add Git LFS backend for large file system

 Documentation/git-p4.txt   |  28 +++++
 git-p4.py                  | 223 +++++++++++++++++++++++++++++++++++++---
 t/t9823-git-p4-mock-lfs.sh | 106 +++++++++++++++++++
 t/t9824-git-p4-git-lfs.sh  | 249 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 593 insertions(+), 13 deletions(-)
 create mode 100755 t/t9823-git-p4-mock-lfs.sh
 create mode 100755 t/t9824-git-p4-git-lfs.sh

--
2.5.1

#1 lore raw

PATCH v4 1/5 git-p4: add optional type specifier to gitConfig reader

From: Lars Schneider <[email protected]>

The functions “gitConfig” and “gitConfigBool” are almost identical. Make “gitConfig” more generic by adding an optional type specifier. Use the type specifier “—bool” with “gitConfig” to implement “gitConfigBool. This prepares the implementation of other type specifiers such as “—int”.

---
 git-p4.py | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
git-p4.py +6 -6
index 073f87b..c139cab 100755
@@ -604,9 +604,12 @@ def gitBranchExists(branch):
 
 _gitConfig = {}
 
-def gitConfig(key):
+def gitConfig(key, typeSpecifier=None):
     if not _gitConfig.has_key(key):
-        cmd = [ "git", "config", key ]
+        cmd = [ "git", "config" ]
+        if typeSpecifier:
+            cmd += [ typeSpecifier ]
+        cmd += [ key ]
         s = read_pipe(cmd, ignore_error=True)
         _gitConfig[key] = s.strip()
     return _gitConfig[key]
@@ -617,10 +620,7 @@ def gitConfigBool(key):
        in the config."""
 
     if not _gitConfig.has_key(key):
-        cmd = [ "git", "config", "--bool", key ]
-        s = read_pipe(cmd, ignore_error=True)
-        v = s.strip()
-        _gitConfig[key] = v == "true"
+        _gitConfig[key] = gitConfig(key, '--bool') == "true"
     return _gitConfig[key]
 
 def gitConfigList(key):
Signature · 1 line
2.5.1
#2 lore raw

PATCH v4 2/5 git-p4: add gitConfigInt reader

In reply to [email protected]

From: Lars Schneider <[email protected]>

Add a git config reader for integer variables. Please note that the git config implementation automatically supports k, m, and g suffixes.

---
 git-p4.py | 11 +++++++++++
 1 file changed, 11 insertions(+)
git-p4.py +11 -0
index c139cab..40ad4ae 100755
@@ -623,6 +623,17 @@ def gitConfigBool(key):
         _gitConfig[key] = gitConfig(key, '--bool') == "true"
     return _gitConfig[key]
 
+def gitConfigInt(key):
+    if not _gitConfig.has_key(key):
+        cmd = [ "git", "config", "--int", key ]
+        s = read_pipe(cmd, ignore_error=True)
+        v = s.strip()
+        try:
+            _gitConfig[key] = int(gitConfig(key, '--int'))
+        except ValueError:
+            _gitConfig[key] = None
+    return _gitConfig[key]
+
 def gitConfigList(key):
     if not _gitConfig.has_key(key):
         s = read_pipe(["git", "config", "--get-all", key], ignore_error=True)
Signature · 1 line
2.5.1
#3 lore raw

PATCH v4 3/5 git-p4: return an empty list if a list config has no values

In reply to [email protected]

From: Lars Schneider <[email protected]>

---
 git-p4.py | 2 ++
 1 file changed, 2 insertions(+)
git-p4.py +2 -0
index 40ad4ae..90d3b90 100755
@@ -638,6 +638,8 @@ def gitConfigList(key):
     if not _gitConfig.has_key(key):
         s = read_pipe(["git", "config", "--get-all", key], ignore_error=True)
         _gitConfig[key] = s.strip().split(os.linesep)
+        if _gitConfig[key] == ['']:
+            _gitConfig[key] = []
     return _gitConfig[key]
 
 def p4BranchesInGit(branchesAreInRemotes=True):
Signature · 1 line
2.5.1
#4 lore raw

PATCH v4 4/5 git-p4: add support for large file systems

In reply to [email protected]

From: Lars Schneider <[email protected]>

Perforce repositories can contain large (binary) files. Migrating these repositories to Git generates very large local clones. External storage systems such as Git LFS [1], Git Fat [2], or Git Media [2] try to address this problem.

Add a generic mechanism to detect large files based on extension, uncompressed size, and/or compressed size.

[1] https://git-lfs.github.com/
[2] https://github.com/jedbrown/git-fat
[3] https://github.com/alebedev/git-media

---
 Documentation/git-p4.txt   |  26 ++++++++
 git-p4.py                  | 150 ++++++++++++++++++++++++++++++++++++++++++---
 t/t9823-git-p4-mock-lfs.sh | 106 ++++++++++++++++++++++++++++++++
 3 files changed, 273 insertions(+), 9 deletions(-)
 create mode 100755 t/t9823-git-p4-mock-lfs.sh
Documentation/git-p4.txt +26 -0
index 82aa5d6..e0d0239 100644
@@ -510,6 +510,32 @@ git-p4.useClientSpec::
 	option '--use-client-spec'.  See the "CLIENT SPEC" section above.
 	This variable is a boolean, not the name of a p4 client.
 
+git-p4.largeFileSystem::
+	Specify the system that is used used for large (binary) files.
+	Please note that most of these large file systems depend on the
+	Git clean/smudge filters. These filters are not applied through
+	git-p4. You need to create a fresh clone of the repository after
+	running git-p4.
+
+git-p4.largeFileExtensions::
+	All files matching a file extension in the list will be processed
+	by the large file system. Do not prefix the extensions with '.'.
+
+git-p4.largeFileThreshold::
+	All files with an uncompressed size exceeding the threshold will be
+	processed by the large file system. By default the threshold is
+	defined in bytes. Add the suffix k, m, or g to change the unit.
+
+git-p4.largeFileCompressedThreshold::
+	All files with a compressed size exceeding the threshold will be
+	processed by the large file system. This option might significantly
+	slow down your clone/sync process. By default the threshold is
+	defined in bytes. Add the suffix k, m, or g to change the unit.
+
+git-p4.pushLargeFiles::
+	Boolean variable which defines if large files are automatically
+	pushed to a server.
+
 Submit variables
 ~~~~~~~~~~~~~~~~
 git-p4.detectRenames::
git-p4.py +141 -9

188 lines not on this page · raw message

t/t9823-git-p4-mock-lfs.sh new file +106 -0

106 lines not on this page · raw message

Signature · 1 line
2.5.1
#5 lore raw

git-p4.py class P4Sync(Command, P4UserMap): · line 2359

Quoted 7 lines · [email protected] writes:
git-p4.py +2 -1
@@ -2226,17 +2355,16 @@ class P4Sync(Command, P4UserMap):
             text = regexp.sub(r'$\1$', text)
             contents = [ text ]
 
-        self.gitStream.write("M %s inline %s\n" % (git_mode, relPath))
+        if relPath == '.gitattributes':
+            die('.gitattributes already exists in P4.')

This looks like an unfortunate limitation to me.

Is it really necessary that you need to reject unrelated attributes the user has (presumably for a good reason)? It seems to me that you only need to _add_ entries to make file extension based decision to send paths selectively to LFS?

Also the exact format of these attributes entries looks like very closely tied to GitHub LFS and not generic (for example, there is no reason to expect that any large-file support would always use the "filter" mechanism or the gitattributes mechanism for that matter), ...

+ def writeGitAttributesToStream(self):
+ self.writeToGitStream(

+            '100644',
+            '.gitattributes',
+            [
+                '\n',
+                '#\n',
+                '# %s\n' % largeFileSystem().attributeDescription(),
+                '#\n',

+ ] +
+ ['*.' + f.replace(' ', '[:space:]') + ' filter=%s -text\n'
+ % largeFileSystem().attributeFilter()
+ for f in sorted(gitConfigList("git-p4.largeFileExtensions"))
+ ] +
+ ['/' + f.replace(' ', '[:space:]') + ' filter=%s -text\n'
+ % largeFileSystem().attributeFilter()
+ for f in sorted(self.largeFiles) if not self.hasLargeFileExtension(f)
+ ]
+ )
+

... so while I can see the code like the above needs to exist somewhere in "git p4" to support GitHub LFS, I am not sure if it belongs to the generic part of the code. For the same reason, I do not know if these replacements with largeFileSystem().getters() are really adding much value.

How is collaboration between those who talk to the same p4 depot backed by GitHub LFS expected to work? You use config to set size limits and list of file extensions in your repository, and grab new changes from p4 and turn them into Git commits (with pointers to LFS and the .gitattributes file that records your choice of the config). I as a new member to the same project come, clone the resulting Git repository from you and then what do I do before talking to the same p4 depot to further update the Git history? Are the values recorded in .gitattributes (which essentially were derived from your configuration) somehow reflected back automatically to my config so that our world view would become consistent? Perhaps you added 'iso' to largeFileExtensions before I cloned from you, and that would be present in the copy of .gitattributes I obtained from you. I may be trying to add a new ".iso" file, and I presume that an existing .gitattributes entry you created based on the file extension automatically covers it from the LFS side, but does my "git p4 submit" also know what to do, or would it be broken until I add a set of configrations that matches yours?

#6 lore raw
Quoted 12 lines · Junio C Hamano

git-p4.py class P4Sync(Command, P4UserMap): · line 2359

Quoted 7 lines · [email protected] writes:
git-p4.py +2 -1
@@ -2226,17 +2355,16 @@ class P4Sync(Command, P4UserMap):
            text = regexp.sub(r'$\1$', text)
            contents = [ text ]
 
-        self.gitStream.write("M %s inline %s\n" % (git_mode, relPath))
+        if relPath == '.gitattributes':
+            die('.gitattributes already exists in P4.')

This looks like an unfortunate limitation to me.

Quoted 4 lines

Is it really necessary that you need to reject unrelated attributes the user has (presumably for a good reason)? It seems to me that you only need to _add_ entries to make file extension based decision to send paths selectively to LFS?

No, it is not necessary. I will remove this limitation.

Quoted 6 lines

Also the exact format of these attributes entries looks like very closely tied to GitHub LFS and not generic (for example, there is no reason to expect that any large-file support would always use the "filter" mechanism or the gitattributes mechanism for that matter), …

Agreed. Instead of just the filter name I will replace everything after the pathname with a single git-p4 config value:

['*.' + f.replace(' ', '[:space:]') + ' %s\n' % largeFileSystem().attributes()
for f in sorted(gitConfigList("git-p4.largeFileExtensions"))
] +
['/' + f.replace(' ', '[:space:]') + ' %s\n' % largeFileSystem().attributes()
for f in sorted(self.largeFiles) if not self.hasLargeFileExtension(f)
]

This, of course, would only work for gitattributes based solutions.

Quoted 22 lines
git-p4.py +20 -0
+    def writeGitAttributesToStream(self):
+        self.writeToGitStream(
+            '100644',
+            '.gitattributes',
+            [
+                '\n',
+                '#\n',
+                '# %s\n' % largeFileSystem().attributeDescription(),
+                '#\n',
+            ] +
+            ['*.' + f.replace(' ', '[:space:]') + ' filter=%s -text\n'
+                % largeFileSystem().attributeFilter()
+                for f in sorted(gitConfigList("git-p4.largeFileExtensions"))
+            ] +
+            ['/' + f.replace(' ', '[:space:]') + ' filter=%s -text\n'
+                % largeFileSystem().attributeFilter()
+                for f in sorted(self.largeFiles) if not self.hasLargeFileExtension(f)
+            ]
+        )
+
Quoted 5 lines

... so while I can see the code like the above needs to exist somewhere in "git p4" to support GitHub LFS, I am not sure if it belongs to the generic part of the code. For the same reason, I do not know if these replacements with largeFileSystem().getters() are really adding much value.

I have the impression you would prefer to move all the attributes code from the generic code to the GitLFS code? I will explore that solution and see if I can come up with a nice generic interface.

Quoted 11 lines

How is collaboration between those who talk to the same p4 depot backed by GitHub LFS expected to work? You use config to set size limits and list of file extensions in your repository, and grab new changes from p4 and turn them into Git commits (with pointers to LFS and the .gitattributes file that records your choice of the config). I as a new member to the same project come, clone the resulting Git repository from you and then what do I do before talking to the same p4 depot to further update the Git history? Are the values recorded in .gitattributes (which essentially were derived from your configuration) somehow reflected back automatically to my config so

Quoted 8 lines

that our world view would become consistent? Perhaps you added 'iso' to largeFileExtensions before I cloned from you, and that would be present in the copy of .gitattributes I obtained from you. I may be trying to add a new ".iso" file, and I presume that an existing .gitattributes entry you created based on the file extension automatically covers it from the LFS side, but does my "git p4 submit" also know what to do, or would it be broken until I add a set of configrations that matches yours?

Well, you have a very good point here. From my point of view you can use git-p4 in two ways:

_Way 1_: Your project is stored in Perforce and it will stay in Perforce. You use git-p4 on a regular basis to interact with the Perforce repository. _Way 2_: Your project is stored in Perforce and you want to migrate it to Git. You use git-p4 once to perform the migration. Afterwards you never touch git-p4 or Perforce again.

My large file system feature is intended to be used only for _Way 2_ for exactly the reasons you mentioned. Would it still be OK to add this feature to git-p4? Maybe with a appropriate warning in the docs?

Thanks,
Lars

#7 lore raw
Quoted 7 lines · Lars Schneider
Quoted 5 lines

Also the exact format of these attributes entries looks like very closely tied to GitHub LFS and not generic (for example, there is no reason to expect that any large-file support would always use the "filter" mechanism or the gitattributes mechanism for that matter), …

Agreed. Instead of just the filter name I will replace everything after the pathname with a single git-p4 config value:

I actually was going to suggest not doing any such replacing.

You obviously need to cutomize the extensions list and specific paths that hold large contents, but having .attributeDescription() and .attributeFilter() that appear to be customizable sends a message to the reader that the code aims to support things other than GitHub LFS. I somehow doubt that really is the case (as you later mention, this would not work at all for solutions that are not based on gitattributes in the first place). It would be less misleading if it is made painfully obvious that this part of the code is about one specific backend.

Quoted 10 lines

Well, you have a very good point here. From my point of view you can use git-p4 in two ways:

_Way 1_: Your project is stored in Perforce and it will stay in Perforce. You use git-p4 on a regular basis to interact with the Perforce repository.
_Way 2_: Your project is stored in Perforce and you want to migrate it to Git. You use git-p4 once to perform the migration. Afterwards you never touch git-p4 or Perforce again.

Quoted 3 lines

My large file system feature is intended to be used only for _Way 2_ for exactly the reasons you mentioned. Would it still be OK to add this feature to git-p4? Maybe with a appropriate warning in the docs?

I could not tell, from the documentation that came in the patch, which one between the above two ways is supported, which made me assume that it aimed to support #1, as the desire to have a bidi bridge seems to be fairly common.

It is a valid use case to migrate away and not looking back. But that is the only workflow that is supported, that fact needs to be documented more clearly, I would think.

Otherwise those who expected a bidirectional bridge by reading the documentation would be disappointed, possibly after wasting a lot of time trying to figure out why their "git p4 submit" is not sending the full large blob contents back to the depot.

Thanks.

#8 lore raw

PATCH v4 5/5 git-p4: add Git LFS backend for large file system

In reply to [email protected]

From: Lars Schneider <[email protected]>

Add example implementation including test cases for the large file system using Git LFS.

Pushing files to the Git LFS server is not tested.

---
 Documentation/git-p4.txt  |   4 +-
 git-p4.py                 |  52 ++++++++++
 t/t9824-git-p4-git-lfs.sh | 249 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 304 insertions(+), 1 deletion(-)
 create mode 100755 t/t9824-git-p4-git-lfs.sh
Documentation/git-p4.txt +3 -1
index e0d0239..3168a64 100644
@@ -515,7 +515,9 @@ git-p4.largeFileSystem::
 	Please note that most of these large file systems depend on the
 	Git clean/smudge filters. These filters are not applied through
 	git-p4. You need to create a fresh clone of the repository after
-	running git-p4.
+	running git-p4. Only Git LFS [1] is supported right now. Download
+	and install the Git LFS command line extension to use this option.
+	[1] https://git-lfs.github.com/
 
 git-p4.largeFileExtensions::
 	All files matching a file extension in the list will be processed
git-p4.py +52 -0

58 lines not on this page · raw message

t/t9824-git-p4-git-lfs.sh new file +249 -0

249 lines not on this page · raw message

Signature · 1 line
2.5.1