MCPcopy Create free account
hub / github.com/git/git / generatePointer

Method generatePointer

git-p4.py:1582–1621  ·  view source on GitHub ↗

Generate a Git LFS pointer for the content. Return LFS Pointer file mode and content which is stored in the Git repository instead of the actual content. Return also the new location of the actual content.

(self, contentFile)

Source from the content-addressed store, hash-verified

1580 self.baseGitAttributes = []
1581
1582 def generatePointer(self, contentFile):
1583 """Generate a Git LFS pointer for the content. Return LFS Pointer file
1584 mode and content which is stored in the Git repository instead of
1585 the actual content. Return also the new location of the actual
1586 content.
1587 """
1588 if os.path.getsize(contentFile) == 0:
1589 return (None, '', None)
1590
1591 pointerProcess = subprocess.Popen(
1592 ['git', 'lfs', 'pointer', '--file=' + contentFile],
1593 stdout=subprocess.PIPE
1594 )
1595 pointerFile = decode_text_stream(pointerProcess.stdout.read())
1596 if pointerProcess.wait():
1597 os.remove(contentFile)
1598 die('git-lfs pointer command failed. Did you install the extension?')
1599
1600 # Git LFS removed the preamble in the output of the 'pointer' command
1601 # starting from version 1.2.0. Check for the preamble here to support
1602 # earlier versions.
1603 # c.f. https://github.com/github/git-lfs/commit/da2935d9a739592bc775c98d8ef4df9c72ea3b43
1604 if pointerFile.startswith('Git LFS pointer for'):
1605 pointerFile = re.sub(r'Git LFS pointer for.*\n\n', '', pointerFile)
1606
1607 oid = re.search(r'^oid \w+:(\w+)', pointerFile, re.MULTILINE).group(1)
1608 # if someone use external lfs.storage ( not in local repo git )
1609 lfs_path = gitConfig('lfs.storage')
1610 if not lfs_path:
1611 lfs_path = 'lfs'
1612 if not os.path.isabs(lfs_path):
1613 lfs_path = os.path.join(os.getcwd(), '.git', lfs_path)
1614 localLargeFile = os.path.join(
1615 lfs_path,
1616 'objects', oid[:2], oid[2:4],
1617 oid,
1618 )
1619 # LFS Spec states that pointer files should not have the executable bit set.
1620 gitMode = '100644'
1621 return (gitMode, pointerFile, localLargeFile)
1622
1623 def pushFile(self, localLargeFile):
1624 uploadProcess = subprocess.Popen(

Callers

nothing calls this directly

Calls 3

decode_text_streamFunction · 0.85
gitConfigFunction · 0.85
dieFunction · 0.70

Tested by

no test coverage detected