Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit13ac6b6

Browse files
committed
Merge commit 'origin/improvements_for_mainline' into integration
* commit 'origin/improvements_for_mainline': Moved compatibility information of possible future release into right spot ( to the top of the release list ) repo_tests: fixed duplicate test-method name which would redefine the previous one which never ran Fixed Diff class which used Commits instead of Blobs - as Blobs contain the path ( in the 'name' member variable ), the a|b_path members of Diff have been removed. Tests were adjusted and run git.git.Git.__init__ takes None as default argument as the execute method handles this correctly Fixed git.blob.Blob.blame function which would return the text-per-commit as individual characters improved repo documentation Improved head and tag object documentation slightly Added docs for the error module Added missing information to docstrings of commit and stats module improved git.cmd documentation Improved documentation on Actor and Blob
2 parents4c39f9d +f4874ca commit13ac6b6

14 files changed

+340
-195
lines changed

‎CHANGES

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
=======
22
CHANGES
33
=======
4+
5+
0.1.X
6+
=====
7+
( Future Release )
8+
General
9+
-------
10+
* See changes in Diff class as your client code needs adjustments to work with it
11+
12+
Diff
13+
----
14+
* Members a a_commit and b_commit renamed to a_blob and b_blob - they are populated
15+
with Blob objects if possible
16+
* Members a_path and b_path removed as this information is kept in the blobs
17+
418

519
0.1.6
620
=====

‎lib/git/actor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
importre
88

99
classActor(object):
10+
"""Actors hold information about a person acting on the repository. They
11+
can be committers and authors or anything with a name and an email as
12+
mentioned in the git log entries."""
1013
def__init__(self,name,email):
1114
self.name=name
1215
self.email=email

‎lib/git/blob.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
fromcommitimportCommit
1313

1414
classBlob(object):
15+
"""A Blob encapsulates a git blob object"""
1516
DEFAULT_MIME_TYPE="text/plain"
1617

1718
def__init__(self,repo,id,mode=None,name=None):
@@ -48,6 +49,9 @@ def size(self):
4849
4950
Returns
5051
int
52+
53+
NOTE
54+
The size will be cached after the first access
5155
"""
5256
ifself._sizeisNone:
5357
self._size=int(self.repo.git.cat_file(self.id,s=True).rstrip())
@@ -60,6 +64,9 @@ def data(self):
6064
6165
Returns
6266
str
67+
68+
NOTE
69+
The data will be cached after the first access.
6370
"""
6471
self.data_stored=self.data_storedorself.repo.git.cat_file(self.id,p=True,with_raw_output=True)
6572
returnself.data_stored
@@ -71,6 +78,9 @@ def mime_type(self):
7178
7279
Returns
7380
str
81+
82+
NOTE
83+
Defaults to 'text/plain' in case the actual file type is unknown.
7484
"""
7585
guesses=None
7686
ifself.name:
@@ -79,6 +89,10 @@ def mime_type(self):
7989

8090
@property
8191
defbasename(self):
92+
"""
93+
Returns
94+
The basename of the Blobs file name
95+
"""
8296
returnos.path.basename(self.name)
8397

8498
@classmethod
@@ -88,6 +102,9 @@ def blame(cls, repo, commit, file):
88102
89103
Returns
90104
list: [git.Commit, list: [<line>]]
105+
A list of tuples associating a Commit object with a list of lines that
106+
changed within the given commit. The Commit objects will be given in order
107+
of appearance.
91108
"""
92109
data=repo.git.blame(commit,'--',file,p=True)
93110
commits= {}
@@ -135,7 +152,7 @@ def blame(cls, repo, commit, file):
135152
m=re.search(r'^\t(.*)$',line)
136153
text,=m.groups()
137154
blames[-1][0]=c
138-
blames[-1][1]+=text
155+
blames[-1][1].append(text )
139156
info=None
140157

141158
returnblames

‎lib/git/cmd.py

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,47 @@
2222

2323
classGit(object):
2424
"""
25-
The Git class manages communication with the Git binary
25+
The Git class manages communication with the Git binary.
26+
27+
It provides a convenient interface to calling the Git binary, such as in::
28+
29+
g = Git( git_dir )
30+
g.init() # calls 'git init' program
31+
rval = g.ls_files()# calls 'git ls-files' program
32+
33+
``Debugging``
34+
Set the GIT_PYTHON_TRACE environment variable print each invocation
35+
of the command to stdout.
36+
Set its value to 'full' to see details about the returned values.
2637
"""
27-
def__init__(self,git_dir):
38+
def__init__(self,git_dir=None):
39+
"""
40+
Initialize this instance with:
41+
42+
``git_dir``
43+
Git directory we should work in. If None, we always work in the current
44+
directory as returned by os.getcwd()
45+
"""
2846
super(Git,self).__init__()
2947
self.git_dir=git_dir
3048

3149
def__getattr__(self,name):
50+
"""
51+
A convenience method as it allows to call the command as if it was
52+
an object.
53+
Returns
54+
Callable object that will execute call _call_process with your arguments.
55+
"""
3256
ifname[:1]=='_':
3357
raiseAttributeError(name)
3458
returnlambda*args,**kwargs:self._call_process(name,*args,**kwargs)
3559

3660
@property
3761
defget_dir(self):
62+
"""
63+
Returns
64+
Git directory we are working on
65+
"""
3866
returnself.git_dir
3967

4068
defexecute(self,command,
@@ -49,7 +77,9 @@ def execute(self, command,
4977
the returned information (stdout)
5078
5179
``command``
52-
The command argument list to execute
80+
The command argument list to execute.
81+
It should be a string, or a sequence of program arguments. The
82+
program to execute is the first item in the args sequence or string.
5383
5484
``istream``
5585
Standard input filehandle passed to subprocess.Popen.
@@ -68,11 +98,18 @@ def execute(self, command,
6898
``with_raw_output``
6999
Whether to avoid stripping off trailing whitespace.
70100
71-
Returns
72-
str(output) # extended_output = False (Default)
73-
tuple(int(status), str(output)) # extended_output = True
101+
Returns::
102+
103+
str(output) # extended_output = False (Default)
104+
tuple(int(status), str(stdout), str(stderr)) # extended_output = True
105+
106+
Raise
107+
GitCommandError
108+
109+
NOTE
110+
If you add additional keyword arguments to the signature of this method,
111+
you must update the execute_kwargs tuple housed in this module.
74112
"""
75-
76113
ifGIT_PYTHON_TRACEandnotGIT_PYTHON_TRACE=='full':
77114
print' '.join(command)
78115

@@ -146,7 +183,8 @@ def _call_process(self, method, *args, **kwargs):
146183
the result as a String
147184
148185
``method``
149-
is the command
186+
is the command. Contained "_" characters will be converted to dashes,
187+
such as in 'ls_files' to call 'ls-files'.
150188
151189
``args``
152190
is the list of arguments
@@ -156,7 +194,7 @@ def _call_process(self, method, *args, **kwargs):
156194
This function accepts the same optional keyword arguments
157195
as execute().
158196
159-
Examples
197+
Examples::
160198
git.rev_list('master', max_count=10, header=True)
161199
162200
Returns

‎lib/git/commit.py

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,44 @@
1414
importstats
1515

1616
classCommit(LazyMixin):
17+
"""
18+
Wraps a git Commit object.
19+
20+
This class will act lazily on some of its attributes and will query the
21+
value on demand only if it involves calling the git binary.
22+
"""
1723
def__init__(self,repo,id,tree=None,author=None,authored_date=None,
1824
committer=None,committed_date=None,message=None,parents=None):
1925
"""
20-
Instantiate a new Commit
26+
Instantiate a new Commit. All keyword arguments taking None as default will
27+
be implicitly set if id names a valid sha.
28+
29+
The parameter documentation indicates the type of the argument after a colon ':'.
2130
2231
``id``
23-
is the id of the commit
32+
is theshaid of the commit
2433
25-
``parents``
26-
is a list of commit ids (will be converted into Commit instances)
34+
``parents`` : list( Commit, ... )
35+
is a list of commit ids
2736
28-
``tree``
29-
is thecorrespdonding tree id (will be converted into a Tree object)
37+
``tree`` : Tree
38+
is thecorresponding tree id
3039
31-
``author``
32-
is the author string
40+
``author`` : Actor
41+
is the author string ( will be implicitly converted into an Actor object )
3342
34-
``authored_date``
43+
``authored_date`` : (tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst )
3544
is the authored DateTime
3645
37-
``committer``
46+
``committer`` : Actor
3847
is the committer string
3948
40-
``committed_date``
49+
``committed_date`` : (tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst)
4150
is the committed DateTime
4251
43-
``message``
52+
``message`` : string
4453
is the commit message
4554
46-
``parents``
47-
is the list of the parents of the commit
48-
4955
Returns
5056
git.Commit
5157
"""
@@ -68,6 +74,10 @@ def __init__(self, repo, id, tree=None, author=None, authored_date=None,
6874
self.tree=Tree(repo,id=tree)
6975

7076
def__bake__(self):
77+
"""
78+
Called by LazyMixin superclass when the first uninitialized member needs
79+
to be set as it is queried.
80+
"""
7181
temp=Commit.find_all(self.repo,self.id,max_count=1)[0]
7282
self.parents=temp.parents
7383
self.tree=temp.tree
@@ -79,10 +89,18 @@ def __bake__(self):
7989

8090
@property
8191
defid_abbrev(self):
92+
"""
93+
Returns
94+
First 7 bytes of the commit's sha id as an abbreviation of the full string.
95+
"""
8296
returnself.id[0:7]
8397

8498
@property
8599
defsummary(self):
100+
"""
101+
Returns
102+
First line of the commit message.
103+
"""
86104
returnself.message.split('\n',1)[0]
87105

88106
@classmethod
@@ -115,10 +133,11 @@ def find_all(cls, repo, ref, path='', **kwargs):
115133
is the ref from which to begin (SHA1 or name)
116134
117135
``path``
118-
is an optinal path
136+
is an optinal path, if set only Commits that include the path
137+
will be considered
119138
120-
``options``
121-
is a Hash ofoptional arguments to git where
139+
``kwargs``
140+
optional keyword arguments to git where
122141
``max_count`` is the maximum number of commits to fetch
123142
``skip`` is the number of commits to skip
124143
@@ -140,7 +159,7 @@ def list_from_string(cls, repo, text):
140159
is the Repo
141160
142161
``text``
143-
is the text output from the git command (raw format)
162+
is the text output from the git-rev-list command (raw format)
144163
145164
Returns
146165
git.Commit[]
@@ -173,7 +192,7 @@ def list_from_string(cls, repo, text):
173192
@classmethod
174193
defdiff(cls,repo,a,b=None,paths=None):
175194
"""
176-
Show diffs between two trees:
195+
Creates diffs between a tree and the index or between two trees:
177196
178197
``repo``
179198
is the Repo
@@ -187,10 +206,13 @@ def diff(cls, repo, a, b=None, paths=None):
187206
given paths.
188207
189208
``paths``
190-
is a list of paths to limit the diff.
209+
is a list of paths to limit the diff to.
191210
192211
Returns
193-
git.Diff[]
212+
git.Diff[]::
213+
214+
between tree and the index if only a is given
215+
between two trees if a and b are given and are commits
194216
"""
195217
paths=pathsor []
196218

@@ -209,6 +231,12 @@ def diff(cls, repo, a, b=None, paths=None):
209231

210232
@property
211233
defdiffs(self):
234+
"""
235+
Returns
236+
git.Diff[]
237+
Diffs between this commit and its first parent or all changes if this
238+
commit is the first commit and has no parent.
239+
"""
212240
ifnotself.parents:
213241
d=self.repo.git.show(self.id,'-M',full_index=True,pretty='raw')
214242
ifre.search(r'diff --git a',d):
@@ -223,6 +251,13 @@ def diffs(self):
223251

224252
@property
225253
defstats(self):
254+
"""
255+
Create a git stat from changes between this commit and its first parent
256+
or from all changes done if this is the very first commit.
257+
258+
Return
259+
git.Stats
260+
"""
226261
ifnotself.parents:
227262
text=self.repo.git.diff_tree(self.id,'--',numstat=True,root=True)
228263
text2=""
@@ -247,7 +282,7 @@ def actor(cls, line):
247282
Parse out the actor (author or committer) info
248283
249284
Returns
250-
[str (actor name and email), time(acted at time)]
285+
[Actor, gmtime(acted at time)]
251286
"""
252287
m=re.search(r'^.+? (.*) (\d+) .*$',line)
253288
actor,epoch=m.groups()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp