commit d9bdc4ac0462b69b536ef2b9434538ab75b6c519
parent c9eccc08cabb24150972c5966955ee0f0979a8cd
Author: Remy Noulin (Spartatek) <remy.noulin@spartatek.se>
Date: Thu, 24 Nov 2016 13:37:23 +0100
add copyTo clearStore|cs commands
git off copyTo [copy|scp]
copy cache to store for specified mode
git off clearStore|cs
delete store
README.md | 6 ++++
src/gitoff.coffee | 84 +++++++++++++++++++++++++++++++++++++++++++++++++------
2 files changed, 81 insertions(+), 9 deletions(-)
Diffstat:
2 files changed, 81 insertions(+), 9 deletions(-)
diff --git a/README.md b/README.md
@@ -151,6 +151,8 @@ git off pre-push
git off smudge
internal filter
dont use directly
+git off copyTo [copy|scp]
+ copy cache to store for specified mode
git off clearAll
delete store, cache and log
git off ca
@@ -159,6 +161,10 @@ git off clearCache
delete cache in current git
git off cc
delete cache in current git
+git off clearStore
+ delete store
+git off cs
+ delete store
git off defaults
shows first time config
git off env
diff --git a/src/gitoff.coffee b/src/gitoff.coffee
@@ -1,10 +1,9 @@
#! /usr/bin/env coffee
# TODO
+# use the path function
# handle wrong config like getLog
-# add a command to copy stores
# check parameters from CLI
-# define an empty value that is not empty in config because when the value is empty it searches in other configs
#
# parse params
# use logger
@@ -258,6 +257,17 @@ copy = (src, dst) ->
fs.createReadStream(src).pipe(fs.createWriteStream(dst))
return
+# List all files in a directory recursively in a synchronous fashion
+walkSync = (dir, filelist = []) ->
+ files = fs.readdirSync(dir)
+ files.forEach (file) ->
+ if fs.statSync(dir + '/' + file).isDirectory()
+ filelist = walkSync(dir + '/' + file, filelist)
+ else
+ filelist.push dir+ '/' + file
+ return
+ filelist
+
# git-off helpers
# gitRepoRoot: sets and returns runtimeConfig.currentRepoRoot
# objectPath: sets and returns runtimeConfig.objectPath
@@ -422,6 +432,23 @@ offHelpers =
exec 'ssh', [offHelpers.offSshOptions(), pem, '-p ' + h_l[2], h_l[0], sshCmd], true
return
+ 'copyTo': ->
+ # list file in cache
+ # copy to store
+
+ # list file in cache
+
+ tfiles = walkSync(offHelpers.objectPath())
+ files = []
+ for f in tfiles
+ files.push f.replace(offHelpers.objectPath() + '/' , '')
+
+ # copy to store
+
+ for f in files
+ transport.send f
+ return
+
'checkIntegrity': (path) ->
# check integrity of files coming from the store
@@ -443,11 +470,15 @@ offHelpers =
result
- 'setTransport': ->
+ 'setTransport': (mode = 'config') ->
# set send and receive functions for transport
# copy, scp
- if offHelpers.offMode() == 'copy'
+ # use mode from config or from parameter
+ if mode == 'config'
+ mode = offHelpers.offMode()
+
+ if mode == 'copy'
transport['send'] = (file) ->
# create file directories in store
f_l = file.split '/'
@@ -463,7 +494,7 @@ offHelpers =
readStream.pipe(process.stdout)
return
- else if offHelpers.offMode() == 'scp'
+ else if mode == 'scp'
transport['send'] = (file) ->
# create file directories in store
@@ -505,6 +536,7 @@ offHelpers =
readStream.pipe(process.stdout)
return
return
+
'getOffFilePath': (offFile) ->
[offFile.slice(0,2) + '/' + offFile.slice(2,4) + '/' + offFile, offFile.slice(0,2) + '/' + offFile.slice(2,4)]
@@ -538,6 +570,7 @@ transport =
# smudge: copy objects from off.store for files handled by git off
# clearAll: delete store, cache in current git and log
# clearCache: delete cache in current git
+# clearStore: delete store
# defaults: show first time config (offDEFAULTS)
# env: show config
offCommands =
@@ -860,12 +893,19 @@ offCommands =
return)
return
+ 'copyTo': ->
+ # copy cache to store for process.argv[3] mode
+ if process.argv[3] == undefined
+ console.log 'Choose a mode where to copy the cache'.red.bold
+ return
+
+ offHelpers.setTransport(process.argv[3])
+ offHelpers.copyTo()
+ return
+
'clearAll': ->
# delete store, cache in current git and log
- if offHelpers.offMode() == 'copy'
- rmAll offHelpers.offStore()
- if offHelpers.offMode() == 'scp'
- offHelpers.rmAllStore ''
+ offCommands.clearStore()
rmAll offHelpers.objectPath()
rmAll offHelpers.getLog()
return
@@ -875,6 +915,14 @@ offCommands =
rmAll offHelpers.objectPath()
return
+ 'clearStore': ->
+ # delete store
+ if offHelpers.offMode() == 'copy'
+ rmAll offHelpers.offStore()
+ if offHelpers.offMode() == 'scp'
+ offHelpers.rmAllStore ''
+ return
+
'defaults': ->
# show first time config (offDEFAULTS)
for k in Object.keys(offDEFAULTS)
@@ -1028,6 +1076,12 @@ COMMAND_MAP =
return
h: 'git off smudge\n internal filter\n dont use directly'
+ 'copyTo':
+ f: ->
+ offCommands.copyTo()
+ return
+ h: 'git off copyTo [copy|scp]\n copy cache to store for specified mode'
+
'clearAll':
f: ->
offCommands.clearAll()
@@ -1052,6 +1106,18 @@ COMMAND_MAP =
return
h: 'git off cc\n delete cache in current git'
+ 'clearStore':
+ f: ->
+ offCommands.clearStore()
+ return
+ h: 'git off clearStore\n delete store'
+
+ 'cs':
+ f: ->
+ offCommands.clearStore()
+ return
+ h: 'git off cs\n delete store'
+
'defaults':
f: ->
offCommands.defaults()