From b240558a7fe81614170879d32392627420acf515 Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Sat, 29 Sep 2018 18:59:11 +0000 Subject: [PATCH] rewrite git-slurp in perl --- git-slurp | 58 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 21 deletions(-) mode change 100644 => 100755 git-slurp diff --git a/git-slurp b/git-slurp old mode 100644 new mode 100755 index a21539a..6022b65 --- a/git-slurp +++ b/git-slurp @@ -1,28 +1,44 @@ -#!/bin/sh +#!/usr/bin/perl -# suck in a pile of files, commit based on timestamp, -# set author +use File::Find; +use File::Find::Closures qw(find_regular_files); +use Git::Repository; +use Time::Stamp qw(gmstamp); -: ${AUTHOR:="Unknown <>"} +my ($want, $files) = find_regular_files(); -base="$1" +my $author = shift; +$author = 'Unknown' unless defined $author; +my $email = shift; +$email = '<>' unless defined $email; -test -d "$base/.git" || git init "$base" +my $dir = shift; +$dir = '.' unless $dir; -cd $base +File::Find::find($want, $dir); -set -x -prevts= -find . -name .git -prune -o -type f -printf '%T@ %P\n' | sort -n | while read ts fn; do - if [ -n "$prevts" ] && [ "$prevts" != "$ts" ]; then - git commit --date="$prevts" --author="$AUTHOR" -m 'auto commit for import' - printf '\n' "$ts" - fi - git add "$fn" - printf '%s\n' "$fn" - prevts="$ts" -done +my %ts; -find . -name .git -prune -o -type f -printf '%T@ %P\n' | sort -n | tail -1 | while read ts fn; do - git commit --date="$ts" --author="$AUTHOR" -m 'auto commit for import' -done +foreach ($files->()) { + next if m|^\.git/|; + next if m|^git-slurp$|; + my $ts = gmstamp((stat $_)[9]); + push @{$ts{$ts}}, $_; +} + +my $git = Git::Repository->new({ + env => { + GIT_AUTHOR_EMAIL => $email, + GIT_AUTHOR_NAME => $author, + }, + } +); + +print $git->work_tree, "\n"; +foreach my $ts (sort { $a cmp $b } keys %ts) { + print "$ts @{$ts{$ts}}\n"; + foreach my $file (@{$ts{$ts}}) { + $git->run('add', $file); + } + $git->run('commit', '--date', $ts, '-m', "add files for $ts"); +} -- 2.40.0