]> git.donarmstrong.com Git - bin.git/commitdiff
use git to locate files
authorDon Armstrong <don@donarmstrong.com>
Thu, 5 Jun 2014 18:34:19 +0000 (11:34 -0700)
committerDon Armstrong <don@donarmstrong.com>
Thu, 5 Jun 2014 18:34:19 +0000 (11:34 -0700)
bibtex_to_paper

index eee5f0a28c6ea95c96e1097777aa8a5d2f2baba2..f7ba6cc300e5f842af28bcb2704c95d0bf6c74d4 100755 (executable)
@@ -91,6 +91,7 @@ my %options = (debug           => 0,
                man             => 0,
                only_print      => 0,
                search_by_pmid  => 0,
+               use_git         => 1,
                'bibtex_cache'  => File::Spec->catfile(User->Home,'.bibtex_to_paper_cache'),
               );
 
@@ -99,6 +100,7 @@ GetOptions(\%options,
            'bibtex|b=s@',
            'bibtex_cache|bibtex-cache|c=s',
            'pdfviewer|p=s',
+           'use_git|use-git!',
            'only_print|only-print!',
            'search_by_pmid|search-by-pmid!',
            'clear_cache|clear-cache!',
@@ -187,21 +189,26 @@ sub load_papers_into_database {
 
     my @dirs = ref($dir)?@{$dir}:$dir;
 
-    my $actually_load_it = sub {
-        if (/\.git/) {
-            $File::Find::prune = 1;
-            return;
-        }
-        return unless /\.pdf$/;
-        my $xoj = 0;
-        if (-e "${_}.xoj") {
-            $xoj = 1;
+    if ($options{use_git}) {
+        my @files = grep /\.pdf$/, split /\n/, qx(git ls-tree HEAD -r --full-name --name-only);
+        for my $file  (@files) {
+            insert_or_replace_papers($dbh,$sth,basename($file),File::Spec->rel2abs($file), -e "${file}.xoj");
         }
-        insert_or_replace_papers($dbh,$sth,basename($File::Find::name),File::Spec->rel2abs($_),$xoj);
-    };
-
-    my @pdfs;
-    find($actually_load_it,@dirs);
+    } else {
+        my $actually_load_it = sub {
+            if (/\.git/) {
+                $File::Find::prune = 1;
+                return;
+            }
+            return unless /\.pdf$/;
+            my $xoj = 0;
+            if (-e "${_}.xoj") {
+                $xoj = 1;
+            }
+            insert_or_replace_papers($dbh,$sth,basename($File::Find::name),File::Spec->rel2abs($_),$xoj);
+        };
+        find($actually_load_it,@dirs);
+    }
 }
 
 sub insert_or_replace_papers {