summaryrefslogtreecommitdiff
path: root/git-fat
diff options
context:
space:
mode:
authorJed Brown <jed@59A2.org>2013-02-14 19:17:49 -0600
committerJed Brown <jed@59A2.org>2013-02-14 19:21:26 -0600
commitb8524eb4574ac8f0d340ed4e9c4607634c4758af (patch)
tree5639331520f6ca77f5733ff7d1e3901b90c40604 /git-fat
parent63afe8a8cb64d3eeb5ef2b35cf660436518ec41c (diff)
downloadgit-fat-b8524eb4574ac8f0d340ed4e9c4607634c4758af.tar.gz
Add 'git fat index-filter .. --manage-gitattributes'
This writes a .gitattributes file for every commit in the history, appending rules for all the now-managed fat files.
Diffstat (limited to 'git-fat')
-rwxr-xr-xgit-fat12
1 files changed, 12 insertions, 0 deletions
diff --git a/git-fat b/git-fat
index 1fd43b1..6afa017 100755
--- a/git-fat
+++ b/git-fat
@@ -399,6 +399,7 @@ class GitFat(object):
revlist.wait()
difftree.wait()
def cmd_index_filter(self, args):
+ manage_gitattributes = '--manage-gitattributes' in args
filelist = set(f.strip() for f in open(args[0]).readlines())
lsfiles = subprocess.Popen(['git', 'ls-files', '-s'], stdout=subprocess.PIPE)
updateindex = subprocess.Popen(['git', 'update-index', '--index-info'], stdin=subprocess.PIPE)
@@ -428,6 +429,17 @@ class GitFat(object):
mkdir_p(os.path.dirname(hashfile))
open(hashfile, 'w').write(cleanedobj + '\n')
updateindex.stdin.write('%s %s %s\t%s\n' % (mode, cleanedobj, stageno, filename))
+ if manage_gitattributes:
+ try:
+ mode, blobsha1, stageno, filename = subprocess.check_output(['git', 'ls-files', '-s', '.gitattributes']).split()
+ gitattributes_lines = subprocess.check_output(['git', 'cat-file', 'blob', blobsha1]).splitlines()
+ except ValueError: # Nothing to unpack, thus no file
+ mode, stageno = '100644', '0'
+ gitattributes_lines = []
+ gitattributes_extra = ['%s filter=fat -text' % line.split()[0] for line in filelist]
+ hashobject = subprocess.Popen(['git', 'hash-object', '-w', '--stdin'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+ stdout, stderr = hashobject.communicate('\n'.join(gitattributes_lines + gitattributes_extra) + '\n')
+ updateindex.stdin.write('%s %s %s\t%s\n' % (mode, stdout.strip(), stageno, '.gitattributes'))
updateindex.stdin.close()
lsfiles.wait()
updateindex.wait()