Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2019-01-10 16:53:47 +0300
committerJacob Vosmaer <jacob@gitlab.com>2019-01-10 16:53:47 +0300
commitad82b8e701f84380282de2b1ee78e60ab41add37 (patch)
treee2a5ea7546565f3fb0db19954b804a9d1a90daf1
parent87ae7aeb4ad3ce6fe155263318d4ce83e42a2dd0 (diff)
Refactor validations
-rw-r--r--internal/service/repository/raw_changes.go23
1 files changed, 13 insertions, 10 deletions
diff --git a/internal/service/repository/raw_changes.go b/internal/service/repository/raw_changes.go
index a5ae0b51c..1a8b243c0 100644
--- a/internal/service/repository/raw_changes.go
+++ b/internal/service/repository/raw_changes.go
@@ -32,18 +32,16 @@ func (s *server) GetRawChanges(req *gitalypb.GetRawChangesRequest, stream gitaly
}
func validateRawChangesRequest(req *gitalypb.GetRawChangesRequest, batch *catfile.Batch) error {
- if req.GetRepository() == nil {
- return fmt.Errorf("repository argument must be present")
- }
-
- from := req.FromRevision
- if _, err := batch.Info(from); err != nil && from != git.NullSHA {
- return fmt.Errorf("invalid 'from' revision: %q", from)
+ if from := req.FromRevision; from != git.NullSHA {
+ if _, err := batch.Info(from); err != nil {
+ return fmt.Errorf("invalid 'from' revision: %q", from)
+ }
}
- to := req.ToRevision
- if _, err := batch.Info(to); err != nil && to != git.NullSHA {
- return fmt.Errorf("invalid 'to' revision: %q", to)
+ if to := req.ToRevision; to != git.NullSHA {
+ if _, err := batch.Info(to); err != nil {
+ return fmt.Errorf("invalid 'to' revision: %q", to)
+ }
}
return nil
@@ -108,6 +106,11 @@ func getRawChanges(stream gitalypb.RepositoryService_GetRawChangesServer, repo *
return nil
}
+// Ordinarily, Git uses 0000000000000000000000000000000000000000, the
+// "null SHA", to represent a non-existing object. In the output of `git
+// diff --raw` however there are only abbreviated SHA's, i.e. with less
+// than 40 characters. Within this context the null SHA is a string that
+// consists of 1 to 40 zeroes.
var zeroRegexp = regexp.MustCompile(`\A0+\z`)
const submoduleTreeEntryMode = "160000"