Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Git on WebApp with Perl

Git on WebApp with Perl

Git リポジトリを表示したり操作したりするアプリケーションをPerlで作成する方法について開設します。

hakobe (Yohei Fushii)

March 17, 2012
Tweet

More Decks by hakobe (Yohei Fushii)

Other Decks in Programming

Transcript

  1. (JUPO8FC"QQ JEIBLPCF XJUI1FSM

  2. ࣗݾ঺հ ⿣ ͸͜΂  JEIBLPCF!IBLPCF  גࣜձࣾ͸ͯͳΤϯδχΞ  IUUQIBLPCFIBUFOBCMPHDPN 

    Ξχϝ࠷଎࣮گΫϥελ wΞχϝؔ܎͋Δͷ͸͜͜·Ͱ
  3. (JUPO8FC"QQ XJUI1FSM

  4. HJU

  5. (JUPO8FC"QQ ⿣ (JUϦϙδτϦϒϥ΢β  HJUIVC  HJUXFC  DHJU 

    (JU-BC  (JUB-JTU  (JUPSJDJPVT
  6. (JUϒϥ΢βJO)BUFOB ⿣ ࣾ಺޲͚(JUϦϙδτϦϒϥ΢β  DPNNJUEJ⒎Λ63-ͰࢦఆͰ͖ΔͷͰ ίʔυϨϏϡʔਐߦ֬ೝʹॏๅ ⿣ ໰୊  3VCZͰॻ͔ΕͯΔ࠷ۙ͸ϝϯς͕

     ίʔυʹؔ͢Δ৘ใίϛϡχέʔ γϣϯͱίʔυ͕෼ࢄ͕ͪ͠
  7. )BUFOB$PEF'SJEHF ⿣ ࣾ಺޲͚(JUϦϙδτϦϒϥ΢β  1FSMͰ͔͔ΕͯΔʂϝϯςͰ͖Δ  ϥϑʹίϛϡχέʔγϣϯͰ͖ͨΓ  ߹॓Ͱ੎͍Ͱ࡞ͬͨ

  8. (JUXJUI1FSM

  9. ϓϩάϥϜ͔Βͷ(JU ⿣ MJCHJU  IUUQMJCHJUHJUIVCDPN  $Ͱॻ͔Εͨ(JUૢ࡞ϥΠϒϥϦ  lBWBJMBCMFBTCJOEJOHTGPSBMM NBKPSTDSJQUJOHMBOHVBHFTz

    3VCZ0CKFDUJWF$1ZUIPO/FU1)1 -VB%FMQIJOPEFKTHP&SMBOHQBSSPU
  10. 1FSM͔Βͷ(JU ⿣ HJUίϚϯυͷXSBQQFS  ಺෦ͰHJUίϚϯυΛ࣮ߦ͢Δʂ wεέʔϧͤ͞Δͷ͸೉͍͠ wͱ͸͍͑ɺ͍͍ͩͨͳΜͰ΋Ͱ͖Δ  ͜Ε·Ͱͷࣾ಺(JUϦϙδτϦ ϒϥ΢β͸਺೥շదʹ࢖͑ͯΔ

  11. 1FSM͔Βͷ(JU ❖Git.pm  HJUʹ෇ଐͯ͠Δ  $1"/Ϟδϡʔϧ͡Όͳ͍ ❖Git::Class/Git::Wrapper  JOUFSBDUJWFͳίϚϯυ͕࢖͑ͳ͍ ❖Git::Repository

     "1*͕γϯϓϧͰׂΓ੾ͬͯΔ  JOUFSBDUJWFͳίϚϯυ͕࢖͑Δ TFFIUUQTFBSDIDQBOPSHdCPPL(JU3FQPTJUPSZMJC(JU 3FQPTJUPSZQN05)&[email protected]&[email protected](*[email protected]"11&34
  12. (JU3FQPTJUPSZ 1 use Git::Repository; 2 3 # ϦϙδτϦͷࢦఆ 4 my

    $git; 5 $git = Git::Repository->new( 6 git_dif => '/path/to/.git' ); 7 $git = Git::Repository->new( 8 work_tree => '/path/to/working_copy' ); 9 18
  13. (JU3FQPTJUPSZ 10 # ίϚϯυͷ࣮ߦ 11 my $status = $git->run('status'); 12

    my @diff = $git->run('diff', 'HEAD^...HEAD'); 13 14 # ίϚϯυͷ࣮ߦ࣌ʹೖग़ྗΛ੍ޚ 15 my $cmd = $git->command('add', '-p', '-u'); 16 $cmd->stdout; 17 $cmd->stdin; 18
  14. (JU3FQPTJUPSZ ⿣ ϦϙδτϦͷ৔ॴΛࢦఆ͢Δͱ HJUίϚϯυ͕࣮ߦͰ͖Δ  SVODPNNBOE ⿣ ࣮ߦ݁Ռ͸ࣗ෼Ͱॲཧ͢Δ  ݁ՌΛؾ߹Ͱύʔε

    wSBXϞʔυͱ͔Λ׆༻
  15. CSBODIS 1 use Git::Repository; 2 3 my $git; 4 $git

    = Git::Repository->new( 5 git_dif => '/path/to/.git' ); 6 7 my @branches = 8 map { $_ =~ s/\s+//g; $_ } 9 $self->git->run('branch', '-r'); 10 origin/fix_bug origin/workerenchance origin/xpath_entryimage
  16. EJ⒎ ύʔε͸ུ 1 diff --git a/lib/Guita/Mapper/Git.pm b/lib/Guita/Mapper/Git.pm 2 index 9ee4a36..5dd6ed5

    100644 3 --- a/lib/Guita/Mapper/Git.pm 4 +++ b/lib/Guita/Mapper/Git.pm 5 @@ -226,4 +226,9 @@ sub ls_tree { 6 return $results; 7 } 8 9 +sub config { 10 + my $self = shift; 11 + $self->git->run('config', @_); 12 +} 13 + 14 1; 15 diff --git a/lib/Guita/Pick.pm b/lib/Guita/Pick.pm 16 index 4c37820..29f75cb 100644 17 --- a/lib/Guita/Pick.pm 18 +++ b/lib/Guita/Pick.pm 19 @@ -37,10 +37,14 @@ sub create { 20 Guita::Git->run(init => $work_tree->stringify);
  17. ࣮ߦ݁Ռͷॲཧ ⿣ (JU3FQPTJUPSZ1MVHJOΛ࢖͏  HJUMPHͷΑ͏ͳϝιου͕௥Ճ  ͦΜͳʹ੝Γ্͕ͬͯͳ͍ wMPHCMBNFͷΈ ⿣ ඞཁʹԠͯࣗ͡෼Ͱॻ͘

     ݁Ռͷѻ͍͸ΞϓϦέʔγϣϯґଘ
  18. ࢀߟ ⿣ SVCZHJU  IUUQTHJUIVCDPNTDIBDPOSVCZ HJU  3VCZͷHJUίϚϯυXSBQQFSܥͷ Ϟδϡʔϧ

  19. (VJUB ❖Guita::Mapper::Git - add/commit/tree/blob/logs/diff/ rev_parse/branch/cat_file/ls_tree  (JU0CKFDUʹରԠ͢ΔΦϒδΣΫτ wCMPCUSFFDPNNJU IUUQTHJUIVCDPNIBLPCF(VJUB

  20. (VJUB ⿣ HJTUDMPOF  ࣾ಺޲͚HJTU΄͍͠͠࡞ͬͨ  ̋1FSMͰॻ͔ΕͯΔ  ✕MJCHJU࢖ͬͯͳ͍ 

    ࢖͍͍ͨͻͱ͓͓͔ͬͨΒؤுΓ͍ͨ  σϞ IUUQTHJUIVCDPNIBLPCF(VJUB
  21. ·ͱΊ ⿣ (JUΛϓϩάϥϜ͔Βૢ࡞͍ͨ͠  ࣾ಺(JUϦϙδτϦ࡞Δͱ͔ ⿣ MJCHJU͸1FSMͰ͸࢖͑ͳ͍ ⿣ (JUܥϞδϡʔϧ͸(JU3FQPTJUPSZ ͓͢͢Ί

    ⿣ (VJUB HJTUDMPOF  ·ͣ͸ࣾ಺ͱ͔Ͱ࢖ͬͯΈΔ