Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hasChanged function using Git log #80

Open
CraigChamberlain opened this issue Oct 12, 2020 · 2 comments
Open

hasChanged function using Git log #80

CraigChamberlain opened this issue Oct 12, 2020 · 2 comments

Comments

@CraigChamberlain
Copy link

I guess this is a feature request but I'll try and implement myself. Want to document use case and my progress, see if anyone else has ideas, suggestions or is interested.

If I store binary files, such as images in Git LFS. When I checkout the files they all get a modified/created date of the time the files are checked out.

Two solutions:

  1. Update the timestamp.
git ls-tree -r --name-only HEAD | while read filename; do 
  unixtime=$(git log -1 --format="%at" -- "${filename}")
  touchtime=$(date -d @$unixtime +'%Y%m%d%H%M.%S')
  touch -t ${touchtime} "${filename}"
done
  1. Use gulp-git in git-changed.

I think the second option might be worth perusing and profiling for relative performance? There is potential for half the read I/O none of the write I/O.

@CraigChamberlain
Copy link
Author

CraigChamberlain commented Oct 12, 2020

Early indications suggest the following will work pretty quickly. If a file exists in the destination but has not yet been committed it is forwarded for processing again.

gulp-git does not support git log but gulp-exec might be a better match anyway.

const {promisify} = require('util');
const fileSystem = require('fs')
const stat = promisify(fileSystem.stat);
const exec = require('child_process').exec;
const execProm = promisify(exec);

async function getTimeStamp(filename){
  let result;
  try{
    result = (await execProm(`git log -1 --format="%at" -- "${filename}"`)).stdout.trim()
    
  } catch(ex){
    result = ex;
  }

  if ( Error[Symbol.hasInstance](result) )
       return ;

  return result
}

async function compareLastModifiedTimeGit(stream,sourceFile, targetPath) {
        if(targetPath == "/home/craig/Documents/src/a-tent-with-a-view-LFS/processedimages/images/02-horombo-hut-marangu-route-3 copy.jpg"){
          var x = "sdfsdf";
        }
        const targetStat = await stat(targetPath);
        if (targetStat === undefined) {
            stream.push(sourceFile);
        } else {
            var sourceMTime = await getTimeStamp(sourceFile.path)
            var targetMTime = await getTimeStamp(targetPath)

            if (sourceMTime > targetMTime) {
                stream.push(sourceFile);
            }
        }
};

@CraigChamberlain
Copy link
Author

Together with another function to selectively pull the requested lfs files, I have a pretty usable solution. It's certainly not gulp ready and is probably pretty ugly code but it's a proof of concept if anyone has an interest contributing to make if more idiomatic or otherwise more fit for production.

async function pullFile(filename) {
  await execProm(`git lfs fetch -I "${filename}"`)
    
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant