Commit Graph

52 Commits

Author SHA1 Message Date
Joel Brobecker
9c82498e7b Introduce (the concept of) git command output decoding
This commit is preparation work for the transition to Python 3.x,
where the output obtained by running Git commands will become
bytes as opposed to a string. In the vast majority of cases,
we'll want to decode that output into a string. Ideally, we would
want to do this in a way that is both compatible with Python 2.x
and Python 3.x, but we have found that this requires a lot of
work with many changes spread all over the code. So, instead,
what this commit does is introduce the concept of decoding
the output, but with the decoding only occurring when running
under Python 3.x.

That way, we can make progress towards Python 3.x while preserving
the behavior under Python 2.x intact.

Change-Id: I189577798ee96cba1fa55c7356babf102575642f
TN: U530-006
2021-10-06 11:27:20 -07:00
Joel Brobecker
473a7d3fe6 git_show_ref: Avoid changing dict size while iterating over it
This is another Python 3.x preparation patch, which fixes a situation
where we change a dictionary size while iterating over it, something
that became apparent while exercizing the hooks with Python 3.x.

This commit avoids this by rewriting this part of the function
in a way that aboves the dictionary iteration entirely.

TN: U530-006
Change-Id: Ia22b28919ac2dabc3e22ed1b3652e14d799e566b
2021-07-11 17:31:17 -07:00
Joel Brobecker
c9bbac817c git.diff_tree: Remove support for **kwargs
I noticed while working on the transition to Python 3.x that
this argument is not actually used, so this commit removes it.
It makes the API for this function simpler and also helps avoid
some pitfalls (as shown by one of the limitations we documented
that this commit removes).

TN: U530-006
Change-Id: I5ced7c6a979c5381d35498b06f1af8c569a3f9ed
2021-06-15 05:55:15 -07:00
Joel Brobecker
8de30044a4 .pre-commit-config.yaml: Update to black version 21.5b1
This commit updates the pre-commit hook to black version 21.5b1.
The hooks where then re-run on all files to update their formatting
to this new version of black.

Change-Id: Ib0866745ef8432cf93380a4d83fa23a479eb4a49
2021-06-15 05:52:32 -07:00
Joel Brobecker
34950804d3 Simplify git.commit_subject
The use of the "git log" command allows us to avoid having to
post-process the command's output in order to extra the subject.

Found while working on U530-006 (transition to Python 3).

Change-Id: I96e9545deece7a2094f9637b75d5e7fb6f334d9a
2021-06-04 17:06:38 -07:00
Joel Brobecker
a075b1653e reformat all the code using black
Change-Id: Idbc70777233ab2d40ab59765abb9cbbeeb88ec63
2021-04-18 14:59:01 +04:00
Joel Brobecker
35e7ad4add replace use of dict.iteritems with dict.items instead
dict.iteritems is Python2-only, so this commit replaces it by
the equivalent call to the "items" method instead.

Change-Id: Ifd2a4e0ce2f00d7d69af9d88a9c959662801a972
2021-04-18 14:45:39 +04:00
Joel Brobecker
24a81783d7 hooks/git.py: Replace reference to "basestring" by "str"
This type will disappear when using a Python 3.x interpreter.

In the meantime, while this code is still run using a Python 2.7
interpreter, it's not a loss in practice to use "str" instead
because we do not use this code in a context where we pass
a unicode string as the _outfile parameter.

Change-Id: Ib56c1521324ee8a8b8b89a7d3b97f43328c313bb
2020-11-23 12:12:14 +01:00
Joel Brobecker
ff8d81cb4a compute each commit's revlog once and then cache it
This is preparatory work for being to pass a certain amount of data
to user-defined hooks. The intent of this change is to limit the number
of times we compute that information to at most once.

Generally speaking, the main part of this change consists in adding
the following new methods to class CommitInfo:
  - raw_revlog;
  - raw_revlog_lines; and

The rest of this change is mostly adjustments to the code that needs
to access commits' rev logs to get them from a shared CommitInfo object
rather than from a play revision (SHA1).

Additionally, the function is_revert_commit in git.py, which took
a commit revision as a paramenter and needed a call to "git log"
to get the commit's body, has been replaced by a new method in
class CommitInfo. An alternative approach might have been to
keep the function, and change its parameter to be a CommitInfo object.
But it seemed more natural to make this a method of the CommitInfo
class instead, so this is what this change does.

Change-Id: Ia4bf23f24226d1e9eddafc61afd37db37f0f5287
TN: T209-005
2020-07-12 17:24:39 -07:00
Joel Brobecker
af06d5ea54 git_run: stop strip-ing the start of the command's output
This change modifies the git_run function, which is a generic
function at the center of all calls to Git, to stop stripping
the start of the output of whitespaces and newlines.

While running the testsuite without any stripping at all clearly
reveals why stripping of the end of the output is necessary (see
added comment for that), stripping of the start of the output
introduces some limitations. For instance, we might want to verify
that commit subjects don't start with spaces.

Since there is no reason that we know of that we would want to strip
the start of the output of Git commands, this change adjusts git_run
accordingly.

TN: T209-005

Change-Id: Ic48a10b4f6115eecc7dbe1c7bb2300ba6070d867
2020-07-10 15:58:46 +02:00
Joel Brobecker
087a8bcdf0 disable all checks on revert commits
For QB08-047.
2017-11-09 07:57:00 -08:00
Joel Brobecker
e70a745ab5 Handle filenames with special characters properly
For Q224-008.
2017-02-27 08:54:09 +01:00
Joel Brobecker
e64e072e8b ignore 'refs/changes/.*' references by default.
This patch introduces a git-hooks config which allows users to tell
the git-hooks to ignore a set of references (as if these references
actually did not exist). By default, the list of ignored references
has one entry, which corresponds to some references that gerrit
creates internally (refs/changes/.*).

For P812-021.
2016-12-06 11:04:27 +01:00
Joel Brobecker
1a73bf7874 git.py: Fix pep8 error 2016-12-06 11:04:25 +01:00
Joel Brobecker
0b66cc2341 enhance git.py to allow passing a specific environment when calling git
This can be useful in any situation, but the use-case that prompted
this enhancement came from the fact that git calls the hooks with
the GIT_DIR environment variable set. If we want to manipulate another
git repository, this GIT_DIR gets in the way, as it points right back
to the original repository. By being able to pass the environment,
we can pass a copy which does not include GIT_DIR.

For P531-036.
2016-06-07 09:27:26 -07:00
Joel Brobecker
147c356fd5 git.py: Small enhancement allowing us to run git from dir of our choice
This will become useful when we need to run git from another directory.

For P531-036.
2016-06-07 09:27:25 -07:00
Joel Brobecker
cd96002f1a Minor space reformatting in function description. 2015-01-12 08:50:51 +04:00
Joel Brobecker
91484a9bdf Better handling of commit parents in CommitInfo object.
The CommitInfo currently has a base_rev attribute which currently
was only half-handled. Part of it was set up by commit_info_list,
except that it wasn't really done properly, so the updates class
was re-doing it afterwards. And then we had this slightly confusing
situation I wasn't sure whether a None base_rev meant no base
(root commit), or un-calculated yet.

This patch clarifies this by getting rid of the "base_rev" attribute,
replacing it by a "parent_revs" attribute, which is either None if
un-calculated yet, or else a list, which would be empty if the commit
has no parent (root commit).

This allows us to simplify a couple of areas, but otherwise, this
is just fallout from those changes.

This should also help us prepare for having easy access to the list
of changes a commit introduces, which is going to be necessary to
handle the FSF's binutils-gdb.git repository.

For NC07-001.
2014-12-13 17:19:15 -05:00
Joel Brobecker
6c2261e951 git.py: Remove unused import 2013-12-26 15:15:28 +04:00
Joel Brobecker
c8aac46beb git.py: Fix pep8 warnings. 2013-12-26 14:42:42 +04:00
Joel Brobecker
5a51d2e303 Tag date parsing problem with newer versions of git.
With git version 1.8.3.2, "git cat-file -p" no longer pretty-prints
the date, printing a timestamp instead. This patch adjust the code
that gets tagger name/email and date to work around this new behavior,
in a way that should with both old and new versions of git.

Add a gigantic comment explaining how we do it and why.
2013-12-24 07:27:18 +04:00
Joel Brobecker
557c5fcae7 Remove unused code in git.git_show_ref. 2013-01-12 16:29:25 +04:00
Joel Brobecker
440219443d commit_subject: Only request one commit in call to "git rev-list"...
... instead of getting the entire list of commits, only to keep
the first one.  This dramatically improves performance in repositories
such as GDB where branches contain a very large number of commits.
Combined with the identical type of fix done in commit_oneline,
the time required for a "git push" in the GDB repository went down
from 40 seconds down to 3.5 seconds!
2013-01-06 15:42:56 +04:00
Joel Brobecker
1ed153d0c7 commit_oneline: Only request one commit during call to "git rev-list"...
... instead of getting the entire list of commits only to keep the
first one. This dramatically improves performance during the
post-receive phase, when the repository has branches with a very
large number of commits (such as GDB, for instance).
2013-01-06 15:33:23 +04:00
Joel Brobecker
c5fb520215 git.commit_rev: Query only one element, instead of all of them...
... since we are only ever going to use the first one anyway.

This change dramatically improves the performance for projects
such as GCC or GDB, which already have a very long history of
commits. With the GDB project, it was measured to reduce the
duration of a push by 57%!
2013-01-03 11:29:09 +04:00