-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadd
executable file
·29 lines (25 loc) · 992 Bytes
/
add
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/python
# update-index.c:add_file_to_cache
import os
import subprocess
import sys
import index
filenames = subprocess.check_output(['find'] + sys.argv[1:] + ['!', '-type', 'd']).splitlines() # for directories
entries = index.read_index()
for filename in filenames:
entries = [e for e in entries if e[0] != filename]
if os.path.exists(filename):
if os.path.islink(filename): # for symlinks
mode = 0120000
with open('.zit/blob.tmp', 'w') as f:
f.write(os.readlink(filename))
sha1 = subprocess.check_output(['hash-object', 'blob', '.zit/blob.tmp']).strip()
else:
if os.access(filename, os.X_OK): # for executable files
mode = 0100755
else:
mode = 0100644
sha1 = subprocess.check_output(['hash-object', 'blob', filename]).strip()
entries.append((filename, mode, bytearray.fromhex(sha1)))
entries.sort()
index.write_index(entries)