未加星标

Poking around /usr/lib/git-core

字体大小 | |
[系统(linux) 所属分类 系统(linux) | 发布者 店小二04 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

A somewhat unknown bit of git trivia is that git rebase is implemented as a ~600 line shell script . A few months ago, I did a full-distro upgrade on my machine. I kept working while it updated, and was surprised when git add --patch failed, because I was using other git commands just fine. Even weirder, plain git add worked! The message I got mentioned Perl and .pm files.

This made me a bit curious to find out what other bits of git were outside the git binary and not in C. Knowing that rebase was a shell script, and that the convention for external subcommands was git-$SUBCOMMAND , I could strace git to find out where that script lived:

$ strace -fe execve git rebase 2>&1 >/dev/null | grep git-rebase [pid 21289] execve("/usr/lib/git-core/git-rebase", ["git-rebase"], [/* 51 vars */]) = 0

Ok, so /usr/lib/git-core is the place to look! How many executables in there?

$ find /usr/lib/git-core -type f -executable | wc -l 37

How many are shell scripts?

$ file /usr/lib/git-core/* | grep 'shell script' | wc -l 18

Let’s see which ones!

$ file /usr/lib/git-core/* \ > | grep 'shell script' \ > | cut -f1 -d: \ > | xargs basename -a \ > | column git-gui--askpass git-filter-branch git-submodule git-citool git-merge-one-file git-stash git-gui git-merge-resolve git-rebase git-difftool--helper git-request-pull git-bisect git-mergetool git-web--browse git-quiltimport git-merge-octopus git-instaweb git-subtree

Some of the surprising ones for me: git submodule , and git subtree because they seem ‘important’, as well as git-stash which seems like a ‘built-in’ facility. Of course, they are all important and built-in in that they come with git-core! I think this is mostly a reflection of my programming background: I’d never implement something complex in shell because I just can’t do it quickly enough for it to make any sense.

How about stats on the types of files?

$ find /usr/lib/git-core/ -type f -executable \ > | xargs file \ > | cut -d' ' -f 2- \ > | sed 's/^ *//;s/, interp.*//' \ > | sort \ > | uniq -c 16 ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked 3 Perl script text executable 17 POSIX shell script, ASCII text executable 1 POSIX shell script, ASCII text executable, with very long lines

We came here curious about git add --patch and Perl, and here we’ve got 3 Perl scripts. What are they?

$ file /usr/lib/git-core/* \ > | grep 'shell script' \ > | cut -f1 -d: \ > | xargs basename -a git-difftool git-relink git-add--interactive

Aha! git-add--interactive sounds very likely. Of course we could have checked this much earlier on:

$ strace -fe execve git add -p 2>&1 >/dev/null | grep add execve("/usr/bin/git", ["git", "add", "-p"], [/* 49 vars */]) = 0 [pid 22871] execve("/usr/lib/git-core/git", ["git", "add--interactive", "--patch", "--"], [/* 51 vars */]) = 0 [pid 22872] execve("/usr/lib/git-core/git-add--interactive", ["git-add--interactive", "--patch", "--"], [/* 51 vars */]) = 0

Proof. :-)

本文系统(linux)相关术语:linux系统 鸟哥的linux私房菜 linux命令大全 linux操作系统

主题: PerlUBSU
分页:12
转载请注明
本文标题:Poking around /usr/lib/git-core
本站链接:http://www.codesec.net/view/481194.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(linux) | 评论(0) | 阅读(51)