Commit Graph

44 Commits

Author SHA1 Message Date
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
Joel Brobecker
912527e4e6 Reject notes updates for unknown commits...
... Enforcing the policy that users should push their "regular"
commits first (update a branch, for instance), and then push
the notes commits.

Fixes LC24-002.
2012-12-24 15:29:03 +04:00
Joel Brobecker
29d0361030 Remove git.GitCommit and git.rev_list_commits
I would like to keep the git.py module as a low-level layer to access
git. The higher-level, more git-hooks-oriented functionality, should
(and is) elsewhere.

The patch adjusts the one caller to rev_list_commits, which really
doesn't need such an elaborate function to get what it needs.

It also renames "load_commit" into commit_rev, as it now returns
just the commit revision, rather than a GitCommit object.
The "commit_oneline" is adjusted accordingly also.

And finally, this introduces a function called "commit_subject".
2012-12-12 07:04:23 +04:00
Joel Brobecker
09794e058a Rework the old_rev..new_rev expansion entirely.
I think that the old algorithm was completely (logically) flawed.
The new approach returns a list of commits that provides:
  - the expansion of old_rev..new_rev
  - which commits in this expanded let are new for the repo
    (and thus requires a commit email).

This will help generate a more descriptive cover email.
2012-12-10 09:59:11 +04:00
Joel Brobecker
d9e6ea08b8 Simplified implementation for git.rev_list_commits. 2012-12-09 19:09:34 +04:00
Joel Brobecker
3f3aef3ba2 Add Updates.pre_update_refs attribute.
This attribute is used to store the value of all references
before an update is applied.

This was computed on-demand by expand_new_commit_to_list, but we want
to make this a parameter of this function, in order to allow us to
call this function from any hook.  In particular, in the post-receive
hook, all reference values have already been updated, so the only
way to get the value of a reference prior to the update is by reverse-
applying the ref updates passed by argument to the post-receive hook.

The ultimate goal of this patch is to re-use expand_new_commit_to_list
during the phase where we send emails for each new commit.
2012-12-09 14:30:25 +04:00
Joel Brobecker
367944b675 Get rid of _quiet option for git_run.
For our purposes, we would always want _quiet to be True, whereas
the default was False, leading to a lot of situations where we forgot
to set it.  So we delete the option.  To access the command's output
in case of command failure, now use the CalledProcessError exception's
output method.

One of the changes also introduced by this patch is the fact that
stderr is now redirected to stdout.

This will avoid seeing some inexplicable spaces in the output
printed by git push commands. These spaces were in fact coming
from the "print" statements that we just got rid of - triggered
by the fact that some calls to git_run were missing the _quiet
option.
2012-11-25 12:40:36 +01:00
Joel Brobecker
725af63035 Make git_show_ref return a more structured data structure.
Each element in the list returned is now a tuple that can be
directly used, rather than requiring each client to parse it.
2012-11-24 16:01:20 -08:00
Joel Brobecker
1ec61d9003 git.py: Standardize on commit_rev or rev instead of commit_id or id.
The former is what seems to be used most throughout the project.
2012-11-24 15:32:53 -08:00