From b8524eb4574ac8f0d340ed4e9c4607634c4758af Mon Sep 17 00:00:00 2001 From: Jed Brown Date: Thu, 14 Feb 2013 19:17:49 -0600 Subject: 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. --- git-fat | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'git-fat') 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() -- cgit v1.2.1