From 43c73ae71d367b8eadf5402ce90c0a573f766710 Mon Sep 17 00:00:00 2001 From: Yu Feng Date: Thu, 12 Mar 2015 12:08:43 -0700 Subject: [PATCH 1/2] 'publish' generates public access urls for files. This is only implemented in the S3 backend. A way to link the stub file to its content would ease integration into repo hosting systems, if that ever happens in the future. eg, adding an url at the end of the stub file? --- git-fat | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/git-fat b/git-fat index f34ab5a..849ae94 100755 --- a/git-fat +++ b/git-fat @@ -78,6 +78,17 @@ try: os.remove(localfile) raise + def publish(self,files): + bkt = self.get_bucket() + for file, realname in files: + localfile = os.path.abspath(os.path.join(self.objdir,file)) + self.verbose('Getting object %s from s3 bucket %s' % (file,self.bucket)) + k = Key(bkt) + k.key = file + k.make_public() + url = k.generate_url(0, query_auth=False) + print('%s => %s' % (realname, url)) + def push(self,files): bkt = self.get_bucket() for file in files: @@ -518,6 +529,22 @@ class GitFat(object): self.backend.pull(files) self.checkout() + def cmd_publish(self, args): + 'query the public URLs for files' + self.setup() + files = [] + for arg in args: + if arg.startswith('-'): + continue + if os.path.exists(arg): + mode, blobsha1, stageno, filename = \ + subprocess.check_output(['git', 'ls-files', '-s', arg]).split() + stub = subprocess.check_output(['git', 'cat-file', 'blob', blobsha1]).splitlines() + digest, bytecount = self.decode(stub[0]) + files.append((digest, arg)) + + self.backend.publish(files) + def parse_pull_patterns(self, args): if '--' not in args: return [''] @@ -677,5 +704,7 @@ if __name__ == '__main__': fat.cmd_find(sys.argv[2:]) elif cmd == 'index-filter': fat.cmd_index_filter(sys.argv[2:]) + elif cmd == 'publish': + fat.cmd_publish(sys.argv[2:]) else: - print('Usage: git fat [init|status|push|pull|gc|checkout|find|index-filter]', file=sys.stderr) + print('Usage: git fat [init|status|push|pull|gc|checkout|find|index-filter|publish]', file=sys.stderr) From 18eebf145f9f61632762cc13b4a4359229ca661b Mon Sep 17 00:00:00 2001 From: Yu Feng Date: Fri, 13 Mar 2015 13:31:45 -0700 Subject: [PATCH 2/2] git fat locate [-p] filenames ... Without -p, locate the SHA-1 blob name of filenames With -p, locate a public-ly access URL of the file from the storage backend (rsync unimplemented yet) --- git-fat | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/git-fat b/git-fat index 849ae94..90067a2 100755 --- a/git-fat +++ b/git-fat @@ -78,7 +78,7 @@ try: os.remove(localfile) raise - def publish(self,files): + def locate_public_url(self,files): bkt = self.get_bucket() for file, realname in files: localfile = os.path.abspath(os.path.join(self.objdir,file)) @@ -529,10 +529,12 @@ class GitFat(object): self.backend.pull(files) self.checkout() - def cmd_publish(self, args): - 'query the public URLs for files' + def cmd_locate(self, args): + 'locate the blob objects for files given in the command line; publish the blob if -p is given' self.setup() files = [] + publish = '-p' in args + for arg in args: if arg.startswith('-'): continue @@ -542,8 +544,11 @@ class GitFat(object): stub = subprocess.check_output(['git', 'cat-file', 'blob', blobsha1]).splitlines() digest, bytecount = self.decode(stub[0]) files.append((digest, arg)) - - self.backend.publish(files) + if not publish: + for file, realname in files: + print('%s => %s' % (realname, file)) + else: + self.backend.locate_public_url(files) def parse_pull_patterns(self, args): if '--' not in args: @@ -704,7 +709,7 @@ if __name__ == '__main__': fat.cmd_find(sys.argv[2:]) elif cmd == 'index-filter': fat.cmd_index_filter(sys.argv[2:]) - elif cmd == 'publish': - fat.cmd_publish(sys.argv[2:]) + elif cmd == 'locate': + fat.cmd_locate(sys.argv[2:]) else: print('Usage: git fat [init|status|push|pull|gc|checkout|find|index-filter|publish]', file=sys.stderr)