[PATCH v4 22/31] git-remote-mediawiki: Modify strings for a better coding-style

2013-06-11 Thread Célestin Matte
- strings which don't need interpolation are single-quoted for more clarity and
slight gain of performance
- interpolation is preferred over concatenation in many cases, for more clarity
- variables are always used with the ${} operator inside strings
- strings including double-quotes are written with qq() so that the quotes do
not have to be escaped

Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |  247 +--
 1 file changed, 123 insertions(+), 124 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index da022af..e89bb02 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -18,13 +18,13 @@ use DateTime::Format::ISO8601;
 use warnings;
 
 # By default, use UTF-8 to communicate with Git and the user
-binmode STDERR, :encoding(UTF-8);
-binmode STDOUT, :encoding(UTF-8);
+binmode STDERR, ':encoding(UTF-8)';
+binmode STDOUT, ':encoding(UTF-8)';
 
 use URI::Escape;
 
 # Mediawiki filenames can contain forward slashes. This variable decides by 
which pattern they should be replaced
-use constant SLASH_REPLACEMENT = %2F;
+use constant SLASH_REPLACEMENT = '%2F';
 
 # It's not always possible to delete pages (may require some
 # privileges). Deleted pages are replaced with this content.
@@ -35,7 +35,7 @@ use constant DELETED_CONTENT = [[Category:Deleted]]\n;
 use constant EMPTY_CONTENT = !-- empty page --\n;
 
 # used to reflect file creation or deletion in diff.
-use constant NULL_SHA1 = ;
+use constant NULL_SHA1 = '';
 
 # Used on Git's side to reflect empty edit messages on the wiki
 use constant EMPTY_MESSAGE = '*Empty MediaWiki Message*';
@@ -49,35 +49,35 @@ my $url = $ARGV[1];
 
 # Accept both space-separated and multiple keys in config file.
 # Spaces should be written as _ anyway because we'll use chomp.
-my @tracked_pages = split(/[ \n]/, run_git(config --get-all remote.. 
$remotename ..pages));
+my @tracked_pages = split(/[ \n]/, run_git(config --get-all 
remote.${remotename}.pages));
 chomp(@tracked_pages);
 
 # Just like @tracked_pages, but for MediaWiki categories.
-my @tracked_categories = split(/[ \n]/, run_git(config --get-all remote.. 
$remotename ..categories));
+my @tracked_categories = split(/[ \n]/, run_git(config --get-all 
remote.${remotename}.categories));
 chomp(@tracked_categories);
 
 # Import media files on pull
-my $import_media = run_git(config --get --bool remote.. $remotename 
..mediaimport);
+my $import_media = run_git(config --get --bool 
remote.${remotename}.mediaimport);
 chomp($import_media);
-$import_media = ($import_media eq true);
+$import_media = ($import_media eq 'true');
 
 # Export media files on push
-my $export_media = run_git(config --get --bool remote.. $remotename 
..mediaexport);
+my $export_media = run_git(config --get --bool 
remote.${remotename}.mediaexport);
 chomp($export_media);
-$export_media = !($export_media eq false);
+$export_media = !($export_media eq 'false');
 
-my $wiki_login = run_git(config --get remote.. $remotename ..mwLogin);
+my $wiki_login = run_git(config --get remote.${remotename}.mwLogin);
 # Note: mwPassword is discourraged. Use the credential system instead.
-my $wiki_passwd = run_git(config --get remote.. $remotename ..mwPassword);
-my $wiki_domain = run_git(config --get remote.. $remotename ..mwDomain);
+my $wiki_passwd = run_git(config --get remote.${remotename}.mwPassword);
+my $wiki_domain = run_git(config --get remote.${remotename}.mwDomain);
 chomp($wiki_login);
 chomp($wiki_passwd);
 chomp($wiki_domain);
 
 # Import only last revisions (both for clone and fetch)
-my $shallow_import = run_git(config --get --bool remote.. $remotename 
..shallow);
+my $shallow_import = run_git(config --get --bool 
remote.${remotename}.shallow);
 chomp($shallow_import);
-$shallow_import = ($shallow_import eq true);
+$shallow_import = ($shallow_import eq 'true');
 
 # Fetch (clone and pull) by revisions instead of by pages. This behavior
 # is more efficient when we have a wiki with lots of pages and we fetch
@@ -85,13 +85,13 @@ $shallow_import = ($shallow_import eq true);
 # Possible values:
 # - by_rev: perform one query per new revision on the remote wiki
 # - by_page: query each tracked page for new revision
-my $fetch_strategy = run_git(config --get remote.$remotename.fetchStrategy);
+my $fetch_strategy = run_git(config --get 
remote.${remotename}.fetchStrategy);
 unless ($fetch_strategy) {
-   $fetch_strategy = run_git(config --get mediawiki.fetchStrategy);
+   $fetch_strategy = run_git('config --get mediawiki.fetchStrategy');
 }
 chomp($fetch_strategy);
 unless ($fetch_strategy) {
-   $fetch_strategy = by_page;
+   $fetch_strategy = 'by_page';
 }
 
 # Remember the timestamp corresponding to a 

[PATCH v3 1/4] toposort: rename lifo field

2013-06-11 Thread Junio C Hamano
The primary invariant of sort_in_topological_order() is that a
parent commit is not emitted until all children of it are.  When
traversing a forked history like this with git log C E:

ABC
 \
  DE

we ensure that A is emitted after all of B, C, D, and E are done, B
has to wait until C is done, and D has to wait until E is done.

In some applications, however, we would further want to control how
these child commits B, C, D and E on two parallel ancestry chains
are shown.

Most of the time, we would want to see C and B emitted together, and
then E and D, and finally A (i.e. the --topo-order output).  The
lifo parameter of the sort_in_topological_order() function is used
to control this behaviour.  We start the traversal by knowing two
commits, C and E.  While keeping in mind that we also need to
inspect E later, we pick C first to inspect, and we notice and
record that B needs to be inspected.  By structuring the work to be
done set as a LIFO stack, we ensure that B is inspected next,
before other in-flight commits we had known that we will need to
inspect, e.g. E.

When showing in --date-order, we would want to see commits ordered
by timestamps, i.e. show C, E, B and D in this order before showing
A, possibly mixing commits from two parallel histories together.
When lifo parameter is set to false, the function keeps the work
to be done set sorted in the date order to realize this semantics.
After inspecting C, we add B to the work to be done set, but the
next commit we inspect from the set is E which is newer than B.

The name lifo, however, is too strongly tied to the way how the
function implements its behaviour, and does not describe what the
behaviour _means_.

Replace this field with an enum rev_sort_order, with two possible
values: REV_SORT_IN_GRAPH_ORDER and REV_SORT_BY_COMMIT_DATE, and
update the existing code.  The mechanical replacement rule is:

  lifo == 0 is equivalent to sort_order == REV_SORT_BY_COMMIT_DATE
  lifo == 1 is equivalent to sort_order == REV_SORT_IN_GRAPH_ORDER

Signed-off-by: Junio C Hamano gits...@pobox.com
---
 builtin/log.c |  2 +-
 builtin/show-branch.c | 14 --
 commit.c  | 12 
 commit.h  | 14 +++---
 revision.c| 10 +-
 revision.h|  6 +-
 6 files changed, 38 insertions(+), 20 deletions(-)

diff --git a/builtin/log.c b/builtin/log.c
index 8f0b2e8..8d26042 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -205,7 +205,7 @@ static void log_show_early(struct rev_info *revs, struct 
commit_list *list)
int i = revs-early_output;
int show_header = 1;
 
-   sort_in_topological_order(list, revs-lifo);
+   sort_in_topological_order(list, revs-sort_order);
while (list  i) {
struct commit *commit = list-item;
switch (simplify_commit(revs, commit)) {
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index d208fd6..7c57985 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -631,7 +631,7 @@ int cmd_show_branch(int ac, const char **av, const char 
*prefix)
int num_rev, i, extra = 0;
int all_heads = 0, all_remotes = 0;
int all_mask, all_revs;
-   int lifo = 1;
+   enum rev_sort_order sort_order = REV_SORT_IN_GRAPH_ORDER;
char head[128];
const char *head_p;
int head_len;
@@ -666,15 +666,17 @@ int cmd_show_branch(int ac, const char **av, const char 
*prefix)
N_(show possible merge bases)),
OPT_BOOLEAN(0, independent, independent,
N_(show refs unreachable from any other ref)),
-   OPT_BOOLEAN(0, topo-order, lifo,
-   N_(show commits in topological order)),
+   OPT_SET_INT(0, topo-order, sort_order,
+   N_(show commits in topological order),
+   REV_SORT_IN_GRAPH_ORDER),
OPT_BOOLEAN(0, topics, topics,
N_(show only commits not on the first branch)),
OPT_SET_INT(0, sparse, dense,
N_(show merges reachable from only one tip), 0),
-   OPT_SET_INT(0, date-order, lifo,
+   OPT_SET_INT(0, date-order, sort_order,
N_(show commits where no parent comes before its 
-  children), 0),
+  children),
+   REV_SORT_BY_COMMIT_DATE),
{ OPTION_CALLBACK, 'g', reflog, reflog_base, 
N_(n[,base]),
N_(show n most recent ref-log entries starting 
at 
   base),
@@ -901,7 +903,7 @@ int cmd_show_branch(int ac, const char **av, const char 
*prefix)
exit(0);
 
/* Sort topologically */
-   sort_in_topological_order(seen, lifo);
+   sort_in_topological_order(seen, sort_order);
 
 

[PATCH v4 26/31] git-remote-mediawiki: Put non-trivial numeric values in constants.

2013-06-11 Thread Célestin Matte
Non-trivial numeric values (e.g., different from 0, 1 and 2) are placed in
constants at the top of the code to be easily modifiable and to make more sense

Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |   20 ++--
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index 0bf9a0d..89b2120 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -42,6 +42,16 @@ use constant EMPTY_MESSAGE = '*Empty MediaWiki Message*';
 
 use constant EMPTY = q{};
 
+# Number of pages taken into account at once in submodule get_mw_page_list
+use constant SLICE_SIZE = 50;
+
+# Number of linked mediafile to get at once in get_linked_mediafiles
+# The query is split in small batches because of the MW API limit of
+# the number of links to be returned (500 links max).
+use constant BATCH_SIZE = 10;
+
+use constant HTTP_CODE_OK = 200;
+
 if (@ARGV != 2) {
exit_error_usage();
 }
@@ -227,13 +237,13 @@ sub get_mw_page_list {
my $pages = shift;
my @some_pages = @$page_list;
while (@some_pages) {
-   my $last_page = 50;
+   my $last_page = SLICE_SIZE;
if ($#some_pages  $last_page) {
$last_page = $#some_pages;
}
my @slice = @some_pages[0..$last_page];
get_mw_first_pages(\@slice, $pages);
-   @some_pages = @some_pages[51..$#some_pages];
+   @some_pages = @some_pages[(SLICE_SIZE + 1)..$#some_pages];
}
return;
 }
@@ -389,9 +399,7 @@ sub get_linked_mediafiles {
my $pages = shift;
my @titles = map { $_-{title} } values(%{$pages});
 
-   # The query is split in small batches because of the MW API limit of
-   # the number of links to be returned (500 links max).
-   my $batch = 10;
+   my $batch = BATCH_SIZE;
while (@titles) {
if ($#titles  $batch) {
$batch = $#titles;
@@ -473,7 +481,7 @@ sub download_mw_mediafile {
my $download_url = shift;
 
my $response = $mediawiki-{ua}-get($download_url);
-   if ($response-code == 200) {
+   if ($response-code == HTTP_CODE_OK) {
return $response-decoded_content;
} else {
print {*STDERR} Error downloading mediafile from :\n;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 12/31] git-remote-mediawiki: Change style in a regexp

2013-06-11 Thread Célestin Matte
Change '[\n]' to '\n': brackets are useless here.

Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index 267c164..86229a1 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -1271,7 +1271,7 @@ sub get_mw_namespace_id {
# Look at configuration file, if the record for that namespace 
is
# already cached. Namespaces are stored in form:
# Name_of_namespace:Id_namespace, ex.: File:6.
-   my @temp = split(/[\n]/, run_git(config --get-all remote.
+   my @temp = split(/\n/, run_git(config --get-all remote.
. $remotename 
..namespaceCache));
chomp(@temp);
foreach my $ns (@temp) {
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 30/31] git-remote-mediawiki: add a perlcritic rule in Makefile

2013-06-11 Thread Célestin Matte
Option -2 launches perlcritic with level 2. Levels go from 5 (most pertinent)
to 1. Rules of level 1 are mostly a question of style, and are therefore
ignored.

Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/Makefile |5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/contrib/mw-to-git/Makefile b/contrib/mw-to-git/Makefile
index 8976aa3..e08b19f 100644
--- a/contrib/mw-to-git/Makefile
+++ b/contrib/mw-to-git/Makefile
@@ -18,4 +18,7 @@ build install clean:
$(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL=$(SCRIPT_PERL_FULL) \
 $@-perl-script
$(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL=$(SCRIPT_PERL_PREVIEW_FULL) \
-$@-perl-script
\ No newline at end of file
+$@-perl-script
+
+perlcritic:
+   perlcritic -2 *.perl
\ No newline at end of file
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 2/4] prio-queue: priority queue of pointers to structs

2013-06-11 Thread Junio C Hamano
Traditionally we used a singly linked list of commits to hold a set
of in-flight commits while traversing history.  The most typical use
of the list is to add commits that are newly discovered to it, keep
the list sorted by commit timestamp, pick up the newest one from the
list, and keep digging.  The cost of keeping the singly linked list
sorted is nontrivial, and this typical use pattern better matches a
priority queue.

Introduce a prio-queue structure, that can be used either as a LIFO
stack, or a priority queue.  This will be used in the next patch to
hold in-flight commits during sort-in-topological-order.

Tests and the idea to make it usable for any void * pointers to
things are by Jeff King.  Bugs are mine.

Signed-off-by: Junio C Hamano gits...@pobox.com
---
 .gitignore|  1 +
 Makefile  |  3 +++
 prio-queue.c  | 71 +++
 prio-queue.h  | 45 
 t/t0009-prio-queue.sh | 50 
 test-prio-queue.c | 39 
 6 files changed, 209 insertions(+)
 create mode 100644 prio-queue.c
 create mode 100644 prio-queue.h
 create mode 100755 t/t0009-prio-queue.sh
 create mode 100644 test-prio-queue.c

diff --git a/.gitignore b/.gitignore
index 6669bf0..b753817 100644
--- a/.gitignore
+++ b/.gitignore
@@ -190,6 +190,7 @@
 /test-mktemp
 /test-parse-options
 /test-path-utils
+/test-prio-queue
 /test-regex
 /test-revision-walking
 /test-run-command
diff --git a/Makefile b/Makefile
index 598d631..0246194 100644
--- a/Makefile
+++ b/Makefile
@@ -552,6 +552,7 @@ TEST_PROGRAMS_NEED_X += test-mergesort
 TEST_PROGRAMS_NEED_X += test-mktemp
 TEST_PROGRAMS_NEED_X += test-parse-options
 TEST_PROGRAMS_NEED_X += test-path-utils
+TEST_PROGRAMS_NEED_X += test-prio-queue
 TEST_PROGRAMS_NEED_X += test-regex
 TEST_PROGRAMS_NEED_X += test-revision-walking
 TEST_PROGRAMS_NEED_X += test-run-command
@@ -685,6 +686,7 @@ LIB_H += parse-options.h
 LIB_H += patch-ids.h
 LIB_H += pathspec.h
 LIB_H += pkt-line.h
+LIB_H += prio-queue.h
 LIB_H += progress.h
 LIB_H += prompt.h
 LIB_H += quote.h
@@ -824,6 +826,7 @@ LIB_OBJS += pathspec.o
 LIB_OBJS += pkt-line.o
 LIB_OBJS += preload-index.o
 LIB_OBJS += pretty.o
+LIB_OBJS += prio-queue.o
 LIB_OBJS += progress.o
 LIB_OBJS += prompt.o
 LIB_OBJS += quote.o
diff --git a/prio-queue.c b/prio-queue.c
new file mode 100644
index 000..f2a4973
--- /dev/null
+++ b/prio-queue.c
@@ -0,0 +1,71 @@
+#include cache.h
+#include commit.h
+#include prio-queue.h
+
+void clear_prio_queue(struct prio_queue *queue)
+{
+   free(queue-array);
+   queue-nr = 0;
+   queue-alloc = 0;
+   queue-array = NULL;
+}
+
+void prio_queue_put(struct prio_queue *queue, void *thing)
+{
+   prio_queue_compare_fn compare = queue-compare;
+   int ix, parent;
+
+   /* Append at the end */
+   ALLOC_GROW(queue-array, queue-nr + 1, queue-alloc);
+   queue-array[queue-nr++] = thing;
+   if (!compare)
+   return; /* LIFO */
+
+   /* Bubble up the new one */
+   for (ix = queue-nr - 1; ix; ix = parent) {
+   parent = (ix - 1) / 2;
+   if (compare(queue-array[parent], queue-array[ix],
+   queue-cb_data) = 0)
+   break;
+
+   thing = queue-array[parent];
+   queue-array[parent] = queue-array[ix];
+   queue-array[ix] = thing;
+   }
+}
+
+void *prio_queue_get(struct prio_queue *queue)
+{
+   void *result, *swap;
+   int ix, child;
+   prio_queue_compare_fn compare = queue-compare;
+
+   if (!queue-nr)
+   return NULL;
+   if (!compare)
+   return queue-array[--queue-nr]; /* LIFO */
+
+   result = queue-array[0];
+   if (!--queue-nr)
+   return result;
+
+   queue-array[0] = queue-array[queue-nr];
+
+   /* Push down the one at the root */
+   for (ix = 0; ix * 2 + 1  queue-nr; ix = child) {
+   child = ix * 2 + 1; /* left */
+   if ((child + 1  queue-nr) 
+   (compare(queue-array[child], queue-array[child + 1],
+queue-cb_data) = 0))
+   child++; /* use right child */
+
+   if (compare(queue-array[ix], queue-array[child],
+   queue-cb_data) = 0)
+   break;
+
+   swap = queue-array[child];
+   queue-array[child] = queue-array[ix];
+   queue-array[ix] = swap;
+   }
+   return result;
+}
diff --git a/prio-queue.h b/prio-queue.h
new file mode 100644
index 000..ed354a5
--- /dev/null
+++ b/prio-queue.h
@@ -0,0 +1,45 @@
+#ifndef PRIO_QUEUE_H
+#define PRIO_QUEUE_H
+
+/*
+ * A priority queue implementation, primarily for keeping track of
+ * commits in the 'date-order' so that we process them from new to old
+ * as they are discovered, but can be used to 

[PATCH v3 4/4] log: --author-date-order

2013-06-11 Thread Junio C Hamano
Sometimes people would want to view the commits in parallel
histories in the order of author dates, not committer dates.

Teach topo-order sort machinery to do so, using a commit-info slab
to record the author dates of each commit, and prio-queue to sort
them.

Signed-off-by: Junio C Hamano gits...@pobox.com
---

 * This re-reads the commit object when commit-buf has already been
   freed, which is necessary to sort by the author date.

 Documentation/rev-list-options.txt |  4 +++
 commit.c   | 74 ++
 commit.h   |  3 +-
 revision.c |  3 ++
 4 files changed, 83 insertions(+), 1 deletion(-)

diff --git a/Documentation/rev-list-options.txt 
b/Documentation/rev-list-options.txt
index 3bdbf5e..8302402 100644
--- a/Documentation/rev-list-options.txt
+++ b/Documentation/rev-list-options.txt
@@ -617,6 +617,10 @@ By default, the commits are shown in reverse chronological 
order.
Show no parents before all of its children are shown, but
otherwise show commits in the commit timestamp order.
 
+--author-date-order::
+   Show no parents before all of its children are shown, but
+   otherwise show commits in the author timestamp order.
+
 --topo-order::
Show no parents before all of its children are shown, and
avoid showing commits on multiple lines of history
diff --git a/commit.c b/commit.c
index 8b84ebf..076c1fa 100644
--- a/commit.c
+++ b/commit.c
@@ -510,6 +510,68 @@ struct commit *pop_commit(struct commit_list **stack)
 /* count number of children that have not been emitted */
 define_commit_slab(indegree_slab, int);
 
+/* record author-date for each commit object */
+define_commit_slab(author_date_slab, unsigned long);
+
+static void record_author_date(struct author_date_slab *author_date,
+  struct commit *commit)
+{
+   const char *buf, *line_end;
+   char *buffer = NULL;
+   struct ident_split ident;
+   char *date_end;
+   unsigned long date;
+
+   if (!commit-buffer) {
+   unsigned long size;
+   enum object_type type;
+   buffer = read_sha1_file(commit-object.sha1, type, size);
+   if (!buffer)
+   return;
+   }
+
+   for (buf = commit-buffer ? commit-buffer : buffer;
+buf;
+buf = line_end + 1) {
+   line_end = strchrnul(buf, '\n');
+   if (prefixcmp(buf, author )) {
+   if (!line_end[0] || line_end[1] == '\n')
+   return; /* end of header */
+   continue;
+   }
+   if (split_ident_line(ident,
+buf + strlen(author ),
+line_end - (buf + strlen(author ))) ||
+   !ident.date_begin || !ident.date_end)
+   goto fail_exit; /* malformed author line */
+   break;
+   }
+
+   date = strtoul(ident.date_begin, date_end, 10);
+   if (date_end != ident.date_end)
+   goto fail_exit; /* malformed date */
+   *(author_date_slab_at(author_date, commit)) = date;
+
+fail_exit:
+   free(buffer);
+}
+
+static int compare_commits_by_author_date(const void *a_, const void *b_,
+ void *cb_data)
+{
+   const struct commit *a = a_, *b = b_;
+   struct author_date_slab *author_date = cb_data;
+   unsigned long a_date = *(author_date_slab_at(author_date, a));
+   unsigned long b_date = *(author_date_slab_at(author_date, b));
+
+   /* newer commits with larger date first */
+   if (a_date  b_date)
+   return 1;
+   else if (a_date  b_date)
+   return -1;
+   return 0;
+}
+
 static int compare_commits_by_commit_date(const void *a_, const void *b_, void 
*unused)
 {
const struct commit *a = a_, *b = b_;
@@ -531,6 +593,7 @@ void sort_in_topological_order(struct commit_list **list, 
enum rev_sort_order so
struct indegree_slab indegree;
struct prio_queue queue;
struct commit *commit;
+   struct author_date_slab author_date;
 
if (!orig)
return;
@@ -538,6 +601,7 @@ void sort_in_topological_order(struct commit_list **list, 
enum rev_sort_order so
 
init_indegree_slab(indegree);
memset(queue, '\0', sizeof(queue));
+
switch (sort_order) {
default: /* REV_SORT_IN_GRAPH_ORDER */
queue.compare = NULL;
@@ -545,12 +609,20 @@ void sort_in_topological_order(struct commit_list **list, 
enum rev_sort_order so
case REV_SORT_BY_COMMIT_DATE:
queue.compare = compare_commits_by_commit_date;
break;
+   case REV_SORT_BY_AUTHOR_DATE:
+   init_author_date_slab(author_date);
+   queue.compare = compare_commits_by_author_date;
+

[PATCH v4 03/31] git-remote-mediawiki: Replace :utf8 by :encoding(UTF-8)

2013-06-11 Thread Célestin Matte
Follow perlcritic's InputOutput::RequireEncodingWithUTF8Layer policy

Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index 863ecc9..5e198e0 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -18,8 +18,8 @@ use DateTime::Format::ISO8601;
 use warnings;
 
 # By default, use UTF-8 to communicate with Git and the user
-binmode STDERR, :utf8;
-binmode STDOUT, :utf8;
+binmode STDERR, :encoding(UTF-8);
+binmode STDOUT, :encoding(UTF-8);
 
 use URI::Escape;
 use IPC::Open2;
@@ -587,7 +587,7 @@ sub literal_data_raw {
utf8::downgrade($content);
binmode STDOUT, :raw;
print STDOUT data , bytes::length($content), \n, $content;
-   binmode STDOUT, :utf8;
+   binmode STDOUT, :encoding(UTF-8);
 }
 
 sub mw_capabilities {
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 27/31] git-remote-mediawiki: Fix a typo (mediwiki instead of mediawiki)

2013-06-11 Thread Célestin Matte
Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index 89b2120..6b6adf2 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -1094,14 +1094,14 @@ sub mw_push_file {
# edit conflicts, considered as non-fast-forward
print {*STDERR} 'Warning: Error ' .
$mediawiki-{error}-{code} .
-   ' from mediwiki: ' . 
$mediawiki-{error}-{details} .
+   ' from mediawiki: ' . 
$mediawiki-{error}-{details} .
.\n;
return ($oldrevid, 'non-fast-forward');
} else {
# Other errors. Shouldn't happen = just die()
die 'Fatal: Error ' .
$mediawiki-{error}-{code} .
-   ' from mediwiki: ' . 
$mediawiki-{error}-{details} . \n;
+   ' from mediawiki: ' . 
$mediawiki-{error}-{details} . \n;
}
}
$newrevid = $result-{edit}-{newrevid};
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 28/31] git-remote-mediawiki: Clearly rewrite double dereference

2013-06-11 Thread Célestin Matte
@$var structures are re-written in the following way: @{$var}
It makes them more readable.

Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index 6b6adf2..5e1fee7 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -235,7 +235,7 @@ sub get_mw_tracked_pages {
 sub get_mw_page_list {
my $page_list = shift;
my $pages = shift;
-   my @some_pages = @$page_list;
+   my @some_pages = @{$page_list};
while (@some_pages) {
my $last_page = SLICE_SIZE;
if ($#some_pages  $last_page) {
@@ -885,7 +885,7 @@ sub mw_import_revids {
my $n_actual = 0;
my $last_timestamp = 0; # Placeholer in case $rev-timestamp is 
undefined
 
-   foreach my $pagerevid (@$revision_ids) {
+   foreach my $pagerevid (@{$revision_ids}) {
# Count page even if we skip it, since we display
# $n/$total and $total includes skipped pages.
$n++;
@@ -920,7 +920,7 @@ sub mw_import_revids {
my $page_title = $result_page-{title};
 
if (!exists($pages-{$page_title})) {
-   print {*STDERR} ${n}/, scalar(@$revision_ids),
+   print {*STDERR} ${n}/, scalar(@{$revision_ids}),
: Skipping revision #$rev-{revid} of 
${page_title}\n;
next;
}
@@ -953,7 +953,7 @@ sub mw_import_revids {
# If this is a revision of the media page for new version
# of a file do one common commit for both file and media page.
# Else do commit only for that page.
-   print {*STDERR} ${n}/, scalar(@$revision_ids), : Revision 
#$rev-{revid} of $commit{title}\n;
+   print {*STDERR} ${n}/, scalar(@{$revision_ids}), : Revision 
#$rev-{revid} of $commit{title}\n;
import_file_revision(\%commit, ($fetch_from == 1), $n_actual, 
\%mediafile);
}
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 31/31] git-remote-mediawiki: Make error message more precise

2013-06-11 Thread Célestin Matte
In subroutine parse_command, error messages were not correct. For the import
function, having too much or incorrect arguments displayed both
invalid arguments, while it displayed too many arguments for the option
functions under the same conditions.
Separate the two error messages in both cases.

Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |   10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index 5e1fee7..ab221ab 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -175,12 +175,16 @@ sub parse_command {
die(Too many arguments for list\n) if (defined($cmd[2]));
mw_list($cmd[1]);
} elsif ($cmd[0] eq 'import') {
-   die(Invalid arguments for import\n)
-   if ($cmd[1] eq EMPTY || defined($cmd[2]));
+   die(Invalid argument for import\n)
+   if ($cmd[1] eq EMPTY);
+   die(Too many arguments for import\n)
+   if (defined($cmd[2]));
mw_import($cmd[1]);
} elsif ($cmd[0] eq 'option') {
+   die(Invalid arguments for option\n)
+   if ($cmd[1] eq EMPTY || $cmd[2] eq EMPTY);
die(Too many arguments for option\n)
-   if ($cmd[1] eq EMPTY || $cmd[2] eq EMPTY || 
defined($cmd[3]));
+   if (defined($cmd[3]));
mw_option($cmd[1],$cmd[2]);
} elsif ($cmd[0] eq 'push') {
mw_push($cmd[1]);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 25/31] git-remote-mediawiki: Don't use quotes for empty strings

2013-06-11 Thread Célestin Matte
Empty strings are replaced by an $EMPTY constant.

Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |   18 ++
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index 4764be5..0bf9a0d 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -40,6 +40,8 @@ use constant NULL_SHA1 = 
'';
 # Used on Git's side to reflect empty edit messages on the wiki
 use constant EMPTY_MESSAGE = '*Empty MediaWiki Message*';
 
+use constant EMPTY = q{};
+
 if (@ARGV != 2) {
exit_error_usage();
 }
@@ -164,11 +166,11 @@ sub parse_command {
mw_list($cmd[1]);
} elsif ($cmd[0] eq 'import') {
die(Invalid arguments for import\n)
-   if ($cmd[1] eq  || defined($cmd[2]));
+   if ($cmd[1] eq EMPTY || defined($cmd[2]));
mw_import($cmd[1]);
} elsif ($cmd[0] eq 'option') {
die(Too many arguments for option\n)
-   if ($cmd[1] eq  || $cmd[2] eq  || defined($cmd[3]));
+   if ($cmd[1] eq EMPTY || $cmd[2] eq EMPTY || 
defined($cmd[3]));
mw_option($cmd[1],$cmd[2]);
} elsif ($cmd[0] eq 'push') {
mw_push($cmd[1]);
@@ -559,7 +561,7 @@ sub mediawiki_clean {
# Mediawiki does not allow blank space at the end of a page and ends 
with a single \n.
# This function right trims a string and adds a \n at the end to follow 
this rule
$string =~ s/\s+$//;
-   if ($string eq   $page_created) {
+   if ($string eq EMPTY  $page_created) {
# Creating empty pages is forbidden.
$string = EMPTY_CONTENT;
}
@@ -570,7 +572,7 @@ sub mediawiki_clean {
 sub mediawiki_smudge {
my $string = shift;
if ($string eq EMPTY_CONTENT) {
-   $string = ;
+   $string = EMPTY;
}
# This \n is important. This is due to mediawiki's way to handle end of 
files.
return ${string}\n;
@@ -996,7 +998,7 @@ sub mw_upload_file {
} else {
# Don't let perl try to interpret file content as UTF-8 = use 
raw
my $content = run_git(cat-file blob ${new_sha1}, 'raw');
-   if ($content ne ) {
+   if ($content ne EMPTY) {
mw_connect_maybe();
$mediawiki-{config}-{upload_url} =
${url}/index.php/Special:Upload;
@@ -1038,7 +1040,7 @@ sub mw_push_file {
my $newrevid;
 
if ($summary eq EMPTY_MESSAGE) {
-   $summary = '';
+   $summary = EMPTY;
}
 
my $new_sha1 = $diff_info_split[3];
@@ -1049,7 +1051,7 @@ sub mw_push_file {
 
my ($title, $extension) = $complete_file_name =~ /^(.*)\.([^\.]*)$/;
if (!defined($extension)) {
-   $extension = ;
+   $extension = EMPTY;
}
if ($extension eq 'mw') {
my $ns = get_mw_namespace_id_for_page($complete_file_name);
@@ -1117,7 +1119,7 @@ sub mw_push {
if ($force) {
print {*STDERR} Warning: forced push not allowed on a 
MediaWiki.\n;
}
-   if ($local eq ) {
+   if ($local eq EMPTY) {
print {*STDERR} Cannot delete remote branch on a 
MediaWiki\n;
print {*STDOUT} error ${remote} cannot delete\n;
next;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 07/31] git-remote-mediawiki: Rewrite unclear line of instructions

2013-06-11 Thread Célestin Matte
Subroutines' parameters should be assigned to variable before doing anything
else
Besides, existing instruction affected a variable inside a if, which break
Git's coding style

Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index 431e063..2db6467 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -1333,7 +1333,8 @@ sub get_mw_namespace_id {
 }
 
 sub get_mw_namespace_id_for_page {
-   if (my ($namespace) = $_[0] =~ /^([^:]*):/) {
+   my $namespace = shift;
+   if ($namespace =~ /^([^:]*):/) {
return get_mw_namespace_id($namespace);
} else {
return;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 05/31] git-remote-mediawiki: Move a variable declaration at the top of the code

2013-06-11 Thread Célestin Matte
%basetimestamps declaration was lost in the middle of subroutines

Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index f19b276..fe1343d 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -95,6 +95,9 @@ unless ($fetch_strategy) {
$fetch_strategy = by_page;
 }
 
+# Remember the timestamp corresponding to a revision id.
+my %basetimestamps;
+
 # Dumb push: don't update notes and mediawiki ref to reflect the last push.
 #
 # Configurable with mediawiki.dumbPush, or per-remote with
@@ -480,9 +483,6 @@ sub get_last_local_revision {
return $lastrevision_number;
 }
 
-# Remember the timestamp corresponding to a revision id.
-my %basetimestamps;
-
 # Get the last remote revision without taking in account which pages are
 # tracked or not. This function makes a single request to the wiki thus
 # avoid a loop onto all tracked pages. This is useful for the fetch-by-rev
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 08/31] git-remote-mediawiki: Remove useless regexp modifier (m)

2013-06-11 Thread Célestin Matte
m// and // is used randomly. It is better to use the m modifier only when
needed, e.g., when the regexp uses another separator than //.

Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index 2db6467..7ce640f 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -761,7 +761,7 @@ sub get_more_refs {
my @refs;
while (1) {
my $line = STDIN;
-   if ($line =~ m/^$cmd (.*)$/) {
+   if ($line =~ /^$cmd (.*)$/) {
push(@refs, $1);
} elsif ($line eq \n) {
return @refs;
@@ -1167,11 +1167,11 @@ sub mw_push_revision {
my @local_ancestry = split(/\n/, run_git(rev-list --boundary 
--parents $local ^$parsed_sha1));
my %local_ancestry;
foreach my $line (@local_ancestry) {
-   if (my ($child, $parents) = $line =~ m/^-?([a-f0-9]+) 
([a-f0-9 ]+)/) {
+   if (my ($child, $parents) = $line =~ /^-?([a-f0-9]+) 
([a-f0-9 ]+)/) {
foreach my $parent (split(' ', $parents)) {
$local_ancestry{$parent} = $child;
}
-   } elsif (!$line =~ m/^([a-f0-9]+)/) {
+   } elsif (!$line =~ /^([a-f0-9]+)/) {
die Unexpected output from git rev-list: 
$line;
}
}
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 16/31] git-remote-mediawiki: Remove unused variable $entry

2013-06-11 Thread Célestin Matte
Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |1 -
 1 file changed, 1 deletion(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index 6024791..ef9e60a 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -127,7 +127,6 @@ $wiki_name =~ s{[^/]*://}{};
 $wiki_name =~ s/^.*@//;
 
 # Commands parser
-my $entry;
 my @cmd;
 while (STDIN) {
chomp;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 13/31] git-remote-mediawiki: Add newline in the end of die() error messages

2013-06-11 Thread Célestin Matte
Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |   26 +-
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index 86229a1..44c5e0e 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -135,16 +135,16 @@ while (STDIN) {
if (defined($cmd[0])) {
# Line not blank
if ($cmd[0] eq capabilities) {
-   die(Too many arguments for capabilities) unless 
(!defined($cmd[1]));
+   die(Too many arguments for capabilities\n) unless 
(!defined($cmd[1]));
mw_capabilities();
} elsif ($cmd[0] eq list) {
-   die(Too many arguments for list) unless 
(!defined($cmd[2]));
+   die(Too many arguments for list\n) unless 
(!defined($cmd[2]));
mw_list($cmd[1]);
} elsif ($cmd[0] eq import) {
-   die(Invalid arguments for import) unless ($cmd[1] ne 
  !defined($cmd[2]));
+   die(Invalid arguments for import\n) unless ($cmd[1] 
ne   !defined($cmd[2]));
mw_import($cmd[1]);
} elsif ($cmd[0] eq option) {
-   die(Too many arguments for option) unless ($cmd[1] ne 
  $cmd[2] ne   !defined($cmd[3]));
+   die(Too many arguments for option\n) unless ($cmd[1] 
ne   $cmd[2] ne   !defined($cmd[3]));
mw_option($cmd[1],$cmd[2]);
} elsif ($cmd[0] eq push) {
mw_push($cmd[1]);
@@ -241,7 +241,7 @@ sub get_mw_tracked_categories {
cmtitle = $category,
cmlimit = 'max' } )
|| die $mediawiki-{error}-{code} . ': '
-   . $mediawiki-{error}-{details};
+   . $mediawiki-{error}-{details} . \n;
foreach my $page (@{$mw_pages}) {
$pages-{$page-{title}} = $page;
}
@@ -766,7 +766,7 @@ sub get_more_refs {
} elsif ($line eq \n) {
return @refs;
} else {
-   die(Invalid command in a '$cmd' batch: . $_);
+   die(Invalid command in a '$cmd' batch: $_\n);
}
}
return;
@@ -878,7 +878,7 @@ sub mw_import_revids {
my $result = $mediawiki-api($query);
 
if (!$result) {
-   die Failed to retrieve modified page for revision 
$pagerevid;
+   die Failed to retrieve modified page for revision 
$pagerevid\n;
}
 
if (defined($result-{query}-{badrevids}-{$pagerevid})) {
@@ -887,7 +887,7 @@ sub mw_import_revids {
}
 
if (!defined($result-{query}-{pages})) {
-   die Invalid revision $pagerevid.;
+   die Invalid revision $pagerevid.\n;
}
 
my @result_pages = values(%{$result-{query}-{pages}});
@@ -998,7 +998,7 @@ sub mw_upload_file {
}, {
skip_encoding = 1
} ) || die $mediawiki-{error}-{code} . ':'
-. $mediawiki-{error}-{details};
+. $mediawiki-{error}-{details} . \n;
my $last_file_page = $mediawiki-get_page({title = 
$path});
$newrevid = $last_file_page-{revid};
print STDERR Pushed file: $new_sha1 - 
$complete_file_name.\n;
@@ -1078,7 +1078,7 @@ sub mw_push_file {
# Other errors. Shouldn't happen = just die()
die 'Fatal: Error ' .
$mediawiki-{error}-{code} .
-   ' from mediwiki: ' . 
$mediawiki-{error}-{details};
+   ' from mediwiki: ' . 
$mediawiki-{error}-{details} . \n;
}
}
$newrevid = $result-{edit}-{newrevid};
@@ -1100,7 +1100,7 @@ sub mw_push {
my $pushed;
for my $refspec (@refsspecs) {
my ($force, $local, $remote) = $refspec =~ 
/^(\+)?([^:]*):([^:]*)$/
-   or die(Invalid refspec for push. Expected src:dst or 
+src:dst);
+   or die(Invalid refspec for push. Expected src:dst or 
+src:dst\n);
if ($force) {
print STDERR Warning: forced push not allowed on a 
MediaWiki.\n;
}
@@ -1172,7 +1172,7 @@ sub mw_push_revision {

[PATCH v4 20/31] git-remote-mediawiki: remove import of unused open2

2013-06-11 Thread Célestin Matte
Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |1 -
 1 file changed, 1 deletion(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index d95119f..7acbec8 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -22,7 +22,6 @@ binmode STDERR, :encoding(UTF-8);
 binmode STDOUT, :encoding(UTF-8);
 
 use URI::Escape;
-use IPC::Open2;
 
 # Mediawiki filenames can contain forward slashes. This variable decides by 
which pattern they should be replaced
 use constant SLASH_REPLACEMENT = %2F;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 14/31] git-remote-mediawiki: Change the name of a variable

2013-06-11 Thread Célestin Matte
Local variable $url has the same name as a global variable. Changing the name
of the local variable prevents future possible misunderstanding.

Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index 44c5e0e..63d1530 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -454,14 +454,14 @@ sub get_mw_mediafile_for_page_revision {
 }
 
 sub download_mw_mediafile {
-   my $url = shift;
+   my $download_url = shift;
 
-   my $response = $mediawiki-{ua}-get($url);
+   my $response = $mediawiki-{ua}-get($download_url);
if ($response-code == 200) {
return $response-decoded_content;
} else {
print STDERR Error downloading mediafile from :\n;
-   print STDERR URL: $url\n;
+   print STDERR URL: $download_url\n;
print STDERR Server response:  . $response-code .   . 
$response-message . \n;
exit 1;
}
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 17/31] git-remote-mediawiki: Rename a variable ($last) which has the name of a keyword

2013-06-11 Thread Célestin Matte
Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index ef9e60a..0610daa 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -214,11 +214,11 @@ sub get_mw_page_list {
my $pages = shift;
my @some_pages = @$page_list;
while (@some_pages) {
-   my $last = 50;
-   if ($#some_pages  $last) {
-   $last = $#some_pages;
+   my $last_page = 50;
+   if ($#some_pages  $last_page) {
+   $last_page = $#some_pages;
}
-   my @slice = @some_pages[0..$last];
+   my @slice = @some_pages[0..$last_page];
get_mw_first_pages(\@slice, $pages);
@some_pages = @some_pages[51..$#some_pages];
}
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 01/31] git-remote-mediawiki: Make a regexp clearer

2013-06-11 Thread Célestin Matte
Perl's split function takes a regex pattern argument. You can also
feed it an expression, which is then compiled into a regex at runtime.
It therefore works to pass your pattern via single quotes, but it is
much less obvious to a reader that the argument is meant to be a
regex, not a static string. Using the traditional slash-delimiters
makes this easier to read.

Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index 410eae9..a7bb397 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -1170,7 +1170,7 @@ sub mw_push_revision {
# history (linearized with --first-parent)
print STDERR Warning: no common ancestor, pushing complete 
history\n;
my $history = run_git(rev-list --first-parent --children 
$local);
-   my @history = split('\n', $history);
+   my @history = split(/\n/, $history);
@history = @history[1..$#history];
foreach my $line (reverse @history) {
my @commit_info_split = split(/ |\n/, $line);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 09/31] git-remote-mediawiki: Change the behaviour of a split

2013-06-11 Thread Célestin Matte
A split ' ' is turned into a split / /, which changes its behaviour: the
old method matched a run of whitespaces (/\s*/), while the new one will match a
single whitespace, which is what we want here. Indeed, in other contexts,
changing split(' ') to split(/ /) could potentially be a regression, however,
here, when parsing the output of rev-list --parents, whose output SHA-1's are
each separated by a single space, splitting on a single space is perfectly
correct.

Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index 7ce640f..7537305 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -1168,7 +1168,7 @@ sub mw_push_revision {
my %local_ancestry;
foreach my $line (@local_ancestry) {
if (my ($child, $parents) = $line =~ /^-?([a-f0-9]+) 
([a-f0-9 ]+)/) {
-   foreach my $parent (split(' ', $parents)) {
+   foreach my $parent (split(/ /, $parents)) {
$local_ancestry{$parent} = $child;
}
} elsif (!$line =~ /^([a-f0-9]+)/) {
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 23/31] git-remote-mediawiki: Brace file handles for print for more clarity

2013-06-11 Thread Célestin Matte
This follows the following rule:
InputOutput::RequireBracedFileHandleWithPrint (Severity: 1)
The `print' and `printf' functions have a unique syntax that supports an
optional file handle argument. Conway suggests wrapping this argument in
braces to make it visually stand out from the other arguments. When you
put braces around any of the special package-level file handles like
`STDOUT', `STDERR', and `DATA', you must the `'*'' sigil or else it
won't compile under `use strict 'subs''.

  print $FH   Mary had a little lamb\n;  #not ok
  print {$FH} Mary had a little lamb\n;  #ok

  print   STDERR   $foo, $bar, $baz;  #not ok
  print  {STDERR}  $foo, $bar, $baz;  #won't compile under 'strict'
  print {*STDERR}  $foo, $bar, $baz;  #perfect!

Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |  202 +--
 1 file changed, 101 insertions(+), 101 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index e89bb02..5174080 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -173,7 +173,7 @@ sub parse_command {
} elsif ($cmd[0] eq 'push') {
mw_push($cmd[1]);
} else {
-   print STDERR Unknown command. Aborting...\n;
+   print {*STDERR} Unknown command. Aborting...\n;
return 0;
}
return 1;
@@ -200,10 +200,10 @@ sub mw_connect_maybe {
   lgdomain = $wiki_domain};
if ($mediawiki-login($request)) {
Git::credential \%credential, 'approve';
-   print STDERR qq(Logged in mediawiki user 
$credential{username}.\n);
+   print {*STDERR} qq(Logged in mediawiki user 
$credential{username}.\n);
} else {
-   print STDERR qq(Failed to log in mediawiki user 
$credential{username} on ${url}\n);
-   print STDERR '  (error ' .
+   print {*STDERR} qq(Failed to log in mediawiki user 
$credential{username} on ${url}\n);
+   print {*STDERR} '  (error ' .
$mediawiki-{error}-{code} . ': ' .
$mediawiki-{error}-{details} . )\n;
Git::credential \%credential, 'reject';
@@ -268,9 +268,9 @@ sub get_mw_all_pages {
aplimit = 'max'
});
if (!defined($mw_pages)) {
-   print STDERR fatal: could not get the list of wiki pages.\n;
-   print STDERR fatal: '${url}' does not appear to be a 
mediawiki\n;
-   print STDERR fatal: make sure '${url}/api.php' is a valid 
page.\n;
+   print {*STDERR} fatal: could not get the list of wiki 
pages.\n;
+   print {*STDERR} fatal: '${url}' does not appear to be a 
mediawiki\n;
+   print {*STDERR} fatal: make sure '${url}/api.php' is a valid 
page.\n;
exit 1;
}
foreach my $page (@{$mw_pages}) {
@@ -295,14 +295,14 @@ sub get_mw_first_pages {
titles = $titles,
});
if (!defined($mw_pages)) {
-   print STDERR fatal: could not query the list of wiki pages.\n;
-   print STDERR fatal: '${url}' does not appear to be a 
mediawiki\n;
-   print STDERR fatal: make sure '${url}/api.php' is a valid 
page.\n;
+   print {*STDERR} fatal: could not query the list of wiki 
pages.\n;
+   print {*STDERR} fatal: '${url}' does not appear to be a 
mediawiki\n;
+   print {*STDERR} fatal: make sure '${url}/api.php' is a valid 
page.\n;
exit 1;
}
while (my ($id, $page) = each(%{$mw_pages-{query}-{pages}})) {
if ($id  0) {
-   print STDERR Warning: page $page-{title} not found on 
wiki\n;
+   print {*STDERR} Warning: page $page-{title} not found 
on wiki\n;
} else {
$pages-{$page-{title}} = $page;
}
@@ -314,7 +314,7 @@ sub get_mw_first_pages {
 sub get_mw_pages {
mw_connect_maybe();
 
-   print STDERR Listing pages on remote wiki...\n;
+   print {*STDERR} Listing pages on remote wiki...\n;
 
my %pages; # hash on page titles to avoid duplicates
my $user_defined;
@@ -332,14 +332,14 @@ sub get_mw_pages {
get_mw_all_pages(\%pages);
}
if ($import_media) {
-   print STDERR Getting media files for selected pages...\n;
+   print {*STDERR} Getting media files for selected pages...\n;
if ($user_defined) {
get_linked_mediafiles(\%pages);
} else {

[PATCH v4 02/31] git-remote-mediawiki: Move use warnings; before any instruction

2013-06-11 Thread Célestin Matte
Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index a7bb397..863ecc9 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -15,6 +15,7 @@ use strict;
 use MediaWiki::API;
 use Git;
 use DateTime::Format::ISO8601;
+use warnings;
 
 # By default, use UTF-8 to communicate with Git and the user
 binmode STDERR, :utf8;
@@ -23,8 +24,6 @@ binmode STDOUT, :utf8;
 use URI::Escape;
 use IPC::Open2;
 
-use warnings;
-
 # Mediawiki filenames can contain forward slashes. This variable decides by 
which pattern they should be replaced
 use constant SLASH_REPLACEMENT = %2F;
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 21/31] git-remote-mediawiki: Put long code into a subroutine

2013-06-11 Thread Célestin Matte
Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |   50 +--
 1 file changed, 31 insertions(+), 19 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index 7acbec8..da022af 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -126,28 +126,13 @@ $wiki_name =~ s{[^/]*://}{};
 $wiki_name =~ s/^.*@//;
 
 # Commands parser
-my @cmd;
+my @cmds;
 while (STDIN) {
chomp;
-   @cmd = split(/ /);
-   if (defined($cmd[0])) {
+   @cmds = split(/ /);
+   if (defined($cmds[0])) {
# Line not blank
-   if ($cmd[0] eq capabilities) {
-   die(Too many arguments for capabilities\n) if 
(defined($cmd[1]));
-   mw_capabilities();
-   } elsif ($cmd[0] eq list) {
-   die(Too many arguments for list\n) if 
(defined($cmd[2]));
-   mw_list($cmd[1]);
-   } elsif ($cmd[0] eq import) {
-   die(Invalid arguments for import\n) if ($cmd[1] eq  
|| defined($cmd[2]));
-   mw_import($cmd[1]);
-   } elsif ($cmd[0] eq option) {
-   die(Too many arguments for option\n) if ($cmd[1] eq 
 || $cmd[2] eq  || defined($cmd[3]));
-   mw_option($cmd[1],$cmd[2]);
-   } elsif ($cmd[0] eq push) {
-   mw_push($cmd[1]);
-   } else {
-   print STDERR Unknown command. Aborting...\n;
+   if (!parse_command(\@cmds)) {
last;
}
} else {
@@ -167,6 +152,33 @@ sub exit_error_usage {
 die ERROR: git-remote-mediawiki module was not called with a correct 
number of parameters\n;
 }
 
+sub parse_command {
+   my $cmdref = shift;
+   my @cmd = @{$cmdref};
+   if ($cmd[0] eq capabilities) {
+   die(Too many arguments for capabilities\n)
+   if (defined($cmd[1]));
+   mw_capabilities();
+   } elsif ($cmd[0] eq list) {
+   die(Too many arguments for list\n) if (defined($cmd[2]));
+   mw_list($cmd[1]);
+   } elsif ($cmd[0] eq import) {
+   die(Invalid arguments for import\n)
+   if ($cmd[1] eq  || defined($cmd[2]));
+   mw_import($cmd[1]);
+   } elsif ($cmd[0] eq option) {
+   die(Too many arguments for option\n)
+   if ($cmd[1] eq  || $cmd[2] eq  || defined($cmd[3]));
+   mw_option($cmd[1],$cmd[2]);
+   } elsif ($cmd[0] eq push) {
+   mw_push($cmd[1]);
+   } else {
+   print STDERR Unknown command. Aborting...\n;
+   return 0;
+   }
+   return 1;
+}
+
 # MediaWiki API instance, created lazily.
 my $mediawiki;
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 06/31] git-remote-mediawiki: Change syntax of map calls

2013-06-11 Thread Célestin Matte
Put first parameter of map inside a block, for better readability.
Follow BuiltinFunctions::RequireBlockMap

Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |   14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index fe1343d..431e063 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -371,7 +371,7 @@ sub get_all_mediafiles {
 
 sub get_linked_mediafiles {
my $pages = shift;
-   my @titles = map $_-{title}, values(%{$pages});
+   my @titles = map { $_-{title} } values(%{$pages});
 
# The query is split in small batches because of the MW API limit of
# the number of links to be returned (500 links max).
@@ -399,11 +399,13 @@ sub get_linked_mediafiles {
while (my ($id, $page) = each(%{$result-{query}-{pages}})) {
my @media_titles;
if (defined($page-{links})) {
-   my @link_titles = map $_-{title}, 
@{$page-{links}};
+   my @link_titles
+   = map { $_-{title} } @{$page-{links}};
push(@media_titles, @link_titles);
}
if (defined($page-{images})) {
-   my @image_titles = map $_-{title}, 
@{$page-{images}};
+   my @image_titles
+   = map { $_-{title} } @{$page-{images}};
push(@media_titles, @image_titles);
}
if (@media_titles) {
@@ -833,7 +835,7 @@ sub mw_import_ref_by_pages {
my ($n, @revisions) = fetch_mw_revisions(\@pages, $fetch_from);
 
@revisions = sort {$a-{revid} = $b-{revid}} @revisions;
-   my @revision_ids = map $_-{revid}, @revisions;
+   my @revision_ids = map { $_-{revid} } @revisions;
 
return mw_import_revids($fetch_from, \@revision_ids, \%pages_hash);
 }
@@ -1246,8 +1248,8 @@ sub get_allowed_file_extensions {
siprop = 'fileextensions'
};
my $result = $mediawiki-api($query);
-   my @file_extensions= map 
$_-{ext},@{$result-{query}-{fileextensions}};
-   my %hashFile = map {$_ = 1}@file_extensions;
+   my @file_extensions = map { $_-{ext}} 
@{$result-{query}-{fileextensions}};
+   my %hashFile = map { $_ = 1 } @file_extensions;
 
return %hashFile;
 }
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 11/31] git-remote-mediawiki: Change style in a regexp

2013-06-11 Thread Célestin Matte
In this regexp, ' |\n' is used, whereas its equivalent '[ \n]', which is
clearer, is used elsewhere. Make the style coherent.

Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index b01d402..267c164 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -1192,7 +1192,7 @@ sub mw_push_revision {
my @history = split(/\n/, $history);
@history = @history[1..$#history];
foreach my $line (reverse @history) {
-   my @commit_info_split = split(/ |\n/, $line);
+   my @commit_info_split = split(/[ \n]/, $line);
push(@commit_pairs, \@commit_info_split);
}
}
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 10/31] git-remote-mediawiki: Change separator of some regexps

2013-06-11 Thread Célestin Matte
Use {}{} instead of /// when slashes are used inside the regexp so as not to
escape it.

Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index 7537305..b01d402 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -120,7 +120,7 @@ chomp($dumb_push);
 $dumb_push = ($dumb_push eq true);
 
 my $wiki_name = $url;
-$wiki_name =~ s/[^\/]*:\/\///;
+$wiki_name =~ s{[^/]*://}{};
 # If URL is like http://user:passw...@example.com/, we clearly don't
 # want the password in $wiki_name. While we're there, also remove user
 # and '@' sign, to avoid author like MWUser@httpu...@host.com
@@ -564,7 +564,7 @@ sub mediawiki_smudge {
 
 sub mediawiki_clean_filename {
my $filename = shift;
-   $filename =~ s/@{[SLASH_REPLACEMENT]}/\//g;
+   $filename =~ s{@{[SLASH_REPLACEMENT]}}{/}g;
# [, ], |, {, and } are forbidden by MediaWiki, even URL-encoded.
# Do a variant of URL-encoding, i.e. looks like URL-encoding,
# but with _ added to prevent MediaWiki from thinking this is
@@ -578,7 +578,7 @@ sub mediawiki_clean_filename {
 
 sub mediawiki_smudge_filename {
my $filename = shift;
-   $filename =~ s/\//@{[SLASH_REPLACEMENT]}/g;
+   $filename =~ s{/}{@{[SLASH_REPLACEMENT]}}g;
$filename =~ s/ /_/g;
# Decode forbidden characters encoded in mediawiki_clean_filename
$filename =~ s/_%_([0-9a-fA-F][0-9a-fA-F])/sprintf(%c, hex($1))/ge;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 18/31] git-remote-mediawiki: Assign a variable as undef and make proper indentation

2013-06-11 Thread Célestin Matte
Explicitly assign local variable $/ as undef and make a proper
one-instruction-by-line indentation

Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index 0610daa..15ad19b 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -338,7 +338,10 @@ sub run_git {
my $args = shift;
my $encoding = (shift || encoding(UTF-8));
open(my $git, -|:$encoding, git  . $args);
-   my $res = do { local $/; $git };
+   my $res = do {
+   local $/ = undef;
+   $git
+   };
close($git);
 
return $res;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 04/31] git-remote-mediawiki: Always end a subroutine with a return

2013-06-11 Thread Célestin Matte
Follow Subroutines::RequireFinalReturn

Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |   18 ++
 1 file changed, 18 insertions(+)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index 5e198e0..f19b276 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -197,12 +197,14 @@ sub mw_connect_maybe {
exit 1;
}
}
+   return;
 }
 
 ## Functions for listing pages on the remote wiki
 sub get_mw_tracked_pages {
my $pages = shift;
get_mw_page_list(\@tracked_pages, $pages);
+   return;
 }
 
 sub get_mw_page_list {
@@ -218,6 +220,7 @@ sub get_mw_page_list {
get_mw_first_pages(\@slice, $pages);
@some_pages = @some_pages[51..$#some_pages];
}
+   return;
 }
 
 sub get_mw_tracked_categories {
@@ -240,6 +243,7 @@ sub get_mw_tracked_categories {
$pages-{$page-{title}} = $page;
}
}
+   return;
 }
 
 sub get_mw_all_pages {
@@ -259,6 +263,7 @@ sub get_mw_all_pages {
foreach my $page (@{$mw_pages}) {
$pages-{$page-{title}} = $page;
}
+   return;
 }
 
 # queries the wiki for a set of pages. Meant to be used within a loop
@@ -289,6 +294,7 @@ sub get_mw_first_pages {
$pages-{$page-{title}} = $page;
}
}
+   return;
 }
 
 # Get the list of pages to be fetched according to configuration.
@@ -357,6 +363,7 @@ sub get_all_mediafiles {
foreach my $page (@{$mw_pages}) {
$pages-{$page-{title}} = $page;
}
+   return;
 }
 
 sub get_linked_mediafiles {
@@ -403,6 +410,7 @@ sub get_linked_mediafiles {
 
@titles = @titles[($batch+1)..$#titles];
}
+   return;
 }
 
 sub get_mw_mediafile_for_page_revision {
@@ -578,6 +586,7 @@ sub mediawiki_smudge_filename {
 sub literal_data {
my ($content) = @_;
print STDOUT data , bytes::length($content), \n, $content;
+   return;
 }
 
 sub literal_data_raw {
@@ -588,6 +597,7 @@ sub literal_data_raw {
binmode STDOUT, :raw;
print STDOUT data , bytes::length($content), \n, $content;
binmode STDOUT, :encoding(UTF-8);
+   return;
 }
 
 sub mw_capabilities {
@@ -599,6 +609,7 @@ sub mw_capabilities {
print STDOUT list\n;
print STDOUT push\n;
print STDOUT \n;
+   return;
 }
 
 sub mw_list {
@@ -607,11 +618,13 @@ sub mw_list {
print STDOUT ? refs/heads/master\n;
print STDOUT \@refs/heads/master HEAD\n;
print STDOUT \n;
+   return;
 }
 
 sub mw_option {
print STDERR remote-helper command 'option $_[0]' not yet 
implemented\n;
print STDOUT unsupported\n;
+   return;
 }
 
 sub fetch_mw_revisions_for_page {
@@ -733,6 +746,7 @@ sub import_file_revision {
print STDOUT N inline :$n\n;
literal_data(mediawiki_revision:  . $commit{mw_revision});
print STDOUT \n\n;
+   return;
 }
 
 # parse a sequence of
@@ -753,6 +767,7 @@ sub get_more_refs {
die(Invalid command in a '$cmd' batch: . $_);
}
}
+   return;
 }
 
 sub mw_import {
@@ -762,6 +777,7 @@ sub mw_import {
mw_import_ref($ref);
}
print STDOUT done\n;
+   return;
 }
 
 sub mw_import_ref {
@@ -805,6 +821,7 @@ sub mw_import_ref {
# thrown saying that HEAD is referring to unknown object 
000
# and the clone fails.
}
+   return;
 }
 
 sub mw_import_ref_by_pages {
@@ -,6 +1128,7 @@ sub mw_push {
print STDERR   git pull --rebase\n;
print STDERR \n;
}
+   return;
 }
 
 sub mw_push_revision {
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 19/31] git-remote-mediawiki: Check return value of open

2013-06-11 Thread Célestin Matte
Signed-off-by: Célestin Matte celestin.ma...@ensimag.fr
Signed-off-by: Matthieu Moy matthieu@grenoble-inp.fr
---
 contrib/mw-to-git/git-remote-mediawiki.perl |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl 
b/contrib/mw-to-git/git-remote-mediawiki.perl
index 15ad19b..d95119f 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -337,7 +337,8 @@ sub get_mw_pages {
 sub run_git {
my $args = shift;
my $encoding = (shift || encoding(UTF-8));
-   open(my $git, -|:$encoding, git  . $args);
+   open(my $git, -|:$encoding, git  . $args)
+   or die Unable to open: $!\n;
my $res = do {
local $/ = undef;
$git
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 0/4] log --author-date-order

2013-06-11 Thread Junio C Hamano
The first one is unchanged.  The second one was redone with Peff's
help, and the other two patches have been adjusted for it.

Adding tests to t4202 and/or t6012 is left as an exercise to readers.

Junio C Hamano (4):
  toposort: rename lifo field
  prio-queue: priority queue of pointers to structs
  sort-in-topological-order: use prio-queue
  log: --author-date-order

 .gitignore |   1 +
 Documentation/rev-list-options.txt |   4 +
 Makefile   |   3 +
 builtin/log.c  |   2 +-
 builtin/show-branch.c  |  14 ++--
 commit.c   | 145 ++---
 commit.h   |  15 +++-
 prio-queue.c   |  84 +
 prio-queue.h   |  48 
 revision.c |  13 ++--
 revision.h |   6 +-
 t/t0009-prio-queue.sh  |  50 +
 test-prio-queue.c  |  39 ++
 13 files changed, 381 insertions(+), 43 deletions(-)
 create mode 100644 prio-queue.c
 create mode 100644 prio-queue.h
 create mode 100755 t/t0009-prio-queue.sh
 create mode 100644 test-prio-queue.c

-- 
1.8.3.1-494-g51b8af5

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 21/28] git-remote-mediawiki: Put long code into a subroutine

2013-06-11 Thread Célestin Matte
Oops, forgot to take this into account before sending v4 of my series of
patch. I just noticed that, sorry...

Le 11/06/2013 17:42, Junio C Hamano a écrit :
 I am guessing that the new sub, parse_command, uses a local @cmd and
 this is an attempt to avoid using the same name, but this renaming
 of the variable is not explained.

This is indeed what I intended to do.

 I also wonder if you need this global @cmd/@cmds.  Instead of
 passing cmdref, wouldn't it be simpler to have the helper split the
 line, i.e. something like...
 
   sub parse_command {
   my ($line) = @_;
 my @cmd = split(/ /, $line);
   unless (defined @cmd) {
   return 0;
   }
 ... check capabilities, list, etc
   return 1;
   }
 
 while (STDIN) {
   chomp;
 if (!parse_command($_)) {
   unknown command, aborting
 last;
   }
   }
 
 


-- 
Célestin Matte
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


What's cooking in git.git (Jun 2013, #04; Tue, 11)

2013-06-11 Thread Junio C Hamano
Here are the topics that have been cooking.  Commits prefixed with
'-' are only in 'pu' (proposed updates) while commits prefixed with
'+' are in 'next'.

You can find the changes described here in the integration branches
of the repositories listed at

http://git-blame.blogspot.com/p/git-public-repositories.html

--
[Graduated to master]

* ar/wildmatch-foldcase (2013-06-02) 1 commit
  (merged to 'next' on 2013-06-04 at 3180bcc)
 + wildmatch: properly fold case everywhere

 The wildmatch engine did not honor WM_CASEFOLD option correctly.


* cb/log-follow-with-combined (2013-05-28) 1 commit
  (merged to 'next' on 2013-06-04 at d5bf4f3)
 + fix segfault with git log -c --follow


* cm/gitweb-project-list-persistent-cgi-fix (2013-06-07) 1 commit
  (merged to 'next' on 2013-06-07 at b16ca1f)
 + gitweb: fix problem causing erroneous project list

 gitweb forgot to clear a global variable $search_regexp upon each
 request, mistakenly carrying over the previous search to a new one
 when used as a persistent CGI.


* cr/git-work-tree-sans-git-dir (2013-06-03) 1 commit
  (merged to 'next' on 2013-06-04 at bebedca)
 + git.txt: remove stale comment regarding GIT_WORK_TREE

 These days, git --work-tree=there cmd without specifying an
 explicit --git-dir=here will do the usual discovery, but we had a
 description of older behaviour in the documentation.


* fc/at-head (2013-05-08) 13 commits
  (merged to 'next' on 2013-06-04 at f334a2a)
 + sha1_name: compare variable with constant, not constant with variable
 + Add new @ shortcut for HEAD
 + sha1_name: refactor reinterpret()
 + sha1_name: check @{-N} errors sooner
 + sha1_name: reorganize get_sha1_basic()
 + sha1_name: don't waste cycles in the @-parsing loop
 + sha1_name: remove unnecessary braces
 + sha1_name: remove no-op
 + tests: at-combinations: @{N} versus HEAD@{N}
 + tests: at-combinations: increase coverage
 + tests: at-combinations: improve nonsense()
 + tests: at-combinations: check ref names directly
 + tests: at-combinations: simplify setup

 Instead of typing four capital letters HEAD, you can say @.


* fc/completion-less-ls-remote (2013-06-02) 1 commit
  (merged to 'next' on 2013-06-03 at 6624f0b)
 + completion: avoid ls-remote in certain scenarios


* fc/do-not-use-the-index-in-add-to-index (2013-06-03) 2 commits
  (merged to 'next' on 2013-06-04 at 94e7b60)
 + read-cache: trivial style cleanups
 + read-cache: fix wrong 'the_index' usage


* fc/remote-bzr (2013-05-28) 8 commits
  (merged to 'next' on 2013-06-04 at a603082)
 + remote-bzr: add fallback check for a partial clone
 + remote-bzr: reorganize the way 'wanted' works
 + remote-bzr: trivial cleanups
 + remote-bzr: change global repo
 + remote-bzr: delay cloning/pulling
 + remote-bzr: simplify get_remote_branch()
 + remote-bzr: fix for files with spaces
 + remote-bzr: recover from failed clones


* fc/remote-hg (2013-05-28) 50 commits
  (merged to 'next' on 2013-06-04 at 9ee7dab)
 + remote-hg: add support for --force
 + remote-hg: add support for --dry-run
 + remote-hg: check if a fetch is needed
 + remote-hg: trivial cleanup
 + remote-helpers: improve marks usage
 + remote-hg: add check_push() helper
 + remote-hg: add setup_big_push() helper
 + remote-hg: remove files before modifications
 + remote-hg: improve lightweight tag author
 + remote-hg: use remote 'default' not local one
 + remote-hg: improve branch listing
 + remote-hg: simplify branch_tip()
 + remote-hg: check diverged bookmarks
 + remote-hg: pass around revision refs
 + remote-hg: implement custom checkheads()
 + remote-hg: implement custom push()
 + remote-hg: only update necessary revisions
 + remote-hg: force remote bookmark push selectively
 + remote-hg: reorganize bookmark handling
 + remote-hg: add test for failed double push
 + remote-hg: add test for big push
 + remote-hg: add test for new bookmark special
 + remote-hg: add test for bookmark diverge
 + remote-hg: add test for diverged push
 + remote-hg: add test to push new bookmark
 + remote-hg: add remote tests
 + remote-hg: update bookmarks when using a remote
 + remote-hg: add check_bookmark() test helper
 + remote-bzr: simplify test checks
 + remote-hg: add tests for 'master' bookmark
 + remote-hg: always point HEAD to master
 + remote-hg: improve progress calculation
 + remote-hg: trivial cleanups
 + remote-hg: ensure remote rebasing works
 + remote-hg: upgrade version 1 marks
 + remote-hg: switch from revisions to SHA-1 noteids
 + remote-hg: add version checks to the marks
 + remote-hg: improve node traversing
 + remote-hg: shuffle some code
 + remote-hg: use a shared repository store
 + remote-hg: load all extensions
 + remote-hg: test: simplify previous branch checkout
 + remote-helpers: test: simplify remote URLs
 + remote-helpers: tests: general improvements
 + remote-helpers: test: cleanup style
 + remote-helpers: test: cleanup white-spaces
 + remote-hg: trivial reorganization
 + remote-hg: test: be a little 

[PATCH 0/2] module_list enhancements

2013-06-11 Thread Fredrik Gustafsson
Cleanup and enhanced module_list (see patches for details). All new 
functionality is
in the first patch, the second one deals only with cleanup. I would prefer if 
both
got applied.

Fredrik Gustafsson (2):
  [submodule] handle multibyte characters in name
  [submodule] Replace perl-code with sh

 git-submodule.sh   | 55 +-
 t/t7400-submodule-basic.sh |  5 +
 2 files changed, 30 insertions(+), 30 deletions(-)

-- 
1.8.3.253.g20b40b5.dirty

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/2] [submodule] handle multibyte characters in name

2013-06-11 Thread Fredrik Gustafsson
Bugg reported here:
http://thread.gmane.org/gmane.comp.version-control.git/218922/focus=226791

Note that newline (\n) is still not supported and will not be until the
sh-script is replaced by something in an other language. This however
let us to use mostly all other strange characters.

Signed-off-by: Fredrik Gustafsson iv...@iveqy.com
---
 git-submodule.sh   | 3 ++-
 t/t7400-submodule-basic.sh | 5 +
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index 79bfaac..31524d3 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -113,9 +113,10 @@ resolve_relative_url ()
 module_list()
 {
(
-   git ls-files --error-unmatch --stage -- $@ ||
+   git ls-files --error-unmatch --stage -z -- $@ ||
echo unmatched pathspec exists
) |
+   sed -e 's/\x00/\n/g' |
perl -e '
my %unmerged = ();
my ($null_sha1) = (0 x 40);
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index ff26535..47ab7e7 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -868,4 +868,9 @@ test_expect_success 'submodule deinit fails when submodule 
has a .git directory
test -n $(git config --get-regexp submodule\.example\.)
 '
 
+test_expect_success 'submodule with strange name works å äö' '
+   git init å äö 
+   git submodule add ./å äö 
+   test -n $(cat .gitmodules | grep å äö)
+'
 test_done
-- 
1.8.3.253.g20b40b5.dirty

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/2] [submodule] Replace perl-code with sh

2013-06-11 Thread Fredrik Gustafsson
This is a work built on
http://thread.gmane.org/gmane.comp.version-control.git/198873/focus=198930

Basically git-submodule.sh needs to use something else than sh to handle
newline in filenames (and therefore needs to use a language that accepts
\0 in strings).

However, since we're not there yet. I've thrown out the only
perl-dependency for git-submodule.sh. It decreases the number of
lines of code and uses the same solution as the rest of the script
already do.

This would lead to less forks and faster code. A simple testrun of
t7400-submodule-basic.sh before this patch resulted in:
real0m8.359s
user0m8.921s
sys 0m3.888s

real0m9.062s
user0m9.025s
sys 0m3.784s

real0m8.490s
user0m9.065s
sys 0m3.740s

After this patch was applied:
real0m7.417s
user0m8.717s
sys 0m3.804s

real0m7.873s
user0m8.821s
sys 0m3.692s

real0m8.950s
user0m8.765s
sys 0m3.760s

Signed-off-by: Fredrik Gustafsson iv...@iveqy.com
---
 git-submodule.sh | 52 +++-
 1 file changed, 23 insertions(+), 29 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index 31524d3..1652781 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -112,39 +112,33 @@ resolve_relative_url ()
 #
 module_list()
 {
+   null_sha1=
+   unmerged=
(
git ls-files --error-unmatch --stage -z -- $@ ||
-   echo unmatched pathspec exists
+   echo #unmatched
) |
sed -e 's/\x00/\n/g' |
-   perl -e '
-   my %unmerged = ();
-   my ($null_sha1) = (0 x 40);
-   my @out = ();
-   my $unmatched = 0;
-   while (STDIN) {
-   if (/^unmatched pathspec/) {
-   $unmatched = 1;
-   next;
-   }
-   chomp;
-   my ($mode, $sha1, $stage, $path) =
-   /^([0-7]+) ([0-9a-f]{40}) ([0-3])\t(.*)$/;
-   next unless $mode eq 16;
-   if ($stage ne 0) {
-   if (!$unmerged{$path}++) {
-   push @out, $mode $null_sha1 U\t$path\n;
-   }
-   next;
-   }
-   push @out, $_\n;
-   }
-   if ($unmatched) {
-   print #unmatched\n;
-   } else {
-   print for (@out);
-   }
-   '
+   while read mode sha1 stage path
+   do
+   if test $mode = #unmatched
+   then
+   echo #unmatched
+   fi
+   if test $mode = 16
+   then
+   if test $stage != 0
+   then
+   if test $unmerged != $path
+   then
+   echo $mode $null_sha1 U $path
+   fi
+   unmerged=$path
+   else
+   echo $mode $sha1 $stage $path
+   fi
+   fi
+   done
 }
 
 die_if_unmatched ()
-- 
1.8.3.253.g20b40b5.dirty

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] Documentation/CommunityGuidelines

2013-06-11 Thread Felipe Contreras
On Tue, Jun 11, 2013 at 3:55 PM, Junio C Hamano gits...@pobox.com wrote:
 Jeff King p...@peff.net writes:

 So there are no hard rules, and this is not a democracy[1]. For the most
 part the community runs itself in an open and collective fashion, and
 the dictator's job is easy; but ultimately, he or she is in charge of
 what gets applied and what doesn't. Rules like break ties in favor of
 reviewers are just a guideline for the dictator to use in making
 decisions.

 I do not think any of that is news to you, but I think the point needs
 to be made, as it applies to any concrete rules.

 My original draft had I am hoping we do not have to come to that
 after (I heard some communities break ties this way), but I
 removed it by mistake.

 And I think you are right. I also am hoping that I am being fair to
 dictate ;-)

Fair? Fairness requires to judge each action without biases, nor
double standards. In the case of an open source community it requires
you to listen to the arguments before dismissing them, and consider
the patches before dropping them on the floor. Fairness requires no
favoritism.

You think you are being fair? You have acted the equivalent of a judge
that says oh, you again? I don't need to look at the case, you are a
drunk and you go to jail. I'm not saying that's wrong, I'm saying you
can't call that fair.

-- 
Felipe Contreras
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: What's cooking in git.git (Jun 2013, #04; Tue, 11)

2013-06-11 Thread Felipe Contreras
On Tue, Jun 11, 2013 at 5:34 PM, Junio C Hamano gits...@pobox.com wrote:

 * fc/remote-helpers-use-specified-python (2013-05-28) 4 commits
  - remote-helpers: add exec-path links
  - remote-helpers: allow direct test execution
  - remote-helpers: rename tests
  - remote-helpers: generate scripts

  I do not particularly think the second from the bottom is a good
  change, but it takes the remainder of the series hostage.

  Waiting for a reroll.

Waiting for a reroll? This is the first time I hear you are not going
to merge these.

You say actions have consequences... well, you are right, you can stop
waiting for a reroll.

-- 
Felipe Contreras
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: What's cooking in git.git (Jun 2013, #04; Tue, 11)

2013-06-11 Thread Junio C Hamano
Felipe Contreras felipe.contre...@gmail.com writes:

 On Tue, Jun 11, 2013 at 5:34 PM, Junio C Hamano gits...@pobox.com wrote:

 * fc/remote-helpers-use-specified-python (2013-05-28) 4 commits
  - remote-helpers: add exec-path links
  - remote-helpers: allow direct test execution
  - remote-helpers: rename tests
  - remote-helpers: generate scripts

  I do not particularly think the second from the bottom is a good
  change, but it takes the remainder of the series hostage.

  Waiting for a reroll.

 Waiting for a reroll? This is the first time I hear you are not going
 to merge these.

 You say actions have consequences... well, you are right, you can stop
 waiting for a reroll.

It has been listed in that state in the previous issue #03 as well.
And if you do not want to reroll, that is fine.  We can discard it
for now and the next person who finds the need to can redo the
change.

Will discard the topic, then.

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] Documentation/CommunityGuidelines

2013-06-11 Thread Felipe Contreras
On Tue, Jun 11, 2013 at 1:43 PM, Michael Haggerty mhag...@alum.mit.edu wrote:
 On 06/11/2013 08:16 PM, Ramkumar Ramachandra wrote:
 This is an exercise.  I can easily be more tactful (as evidenced by
 other threads), but I'm choosing not to be.  I want you to focus on
 the argument, and not the tone.

 I stopped reading your email here.

Yeah, you are ignoring the arguments, what a surprise.

 In German there is an expression Der Ton macht die Musik: the tone
 makes the music, by which they mean that the *way* something is said is
 at least as important as what is said.

I know you don't care about reality, but you are committing the
is-ought fallacy. You are describing the way things are, not the way
things should be.

Yes, most people can't handle rational arguments, or truth, and need
hypocrites to hide things from them. That's why politics is surrounded
by people who never say the truth.. not really.

That doesn't mean that's the way things _ought_ to be, specially not
the way *you* should act.

-- 
Felipe Contreras
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] Documentation/CommunityGuidelines

2013-06-11 Thread John Szakmeister
On Tue, Jun 11, 2013 at 3:46 PM, Philip Oakley philipoak...@iee.org wrote:
 From: Michael Haggerty mhag...@alum.mit.edu
 Sent: Tuesday, June 11, 2013 7:52 PM
 [...]


 That's a very good point (and a good illustration, too).  How do you
 like the new second and third sentences below?

 * When reviewing other peoples' code, be tactful and constructive.
 Remember that submitting patches for public critique can be very
 intimidating


 I found this to be true. The tone on the list could at times feel un-helpful
 (to the new person). It is almost as if it is an initiation - those on the
 list know the protocols, and new folk either arrive like a bull in a china
 shop, or more likely, timidly push the patch under the door and run away
 (and variations in between) - some never push out their (drafted) patch.

Interesting!  I've had the opposite opinion.  I've often been
surprised at how much constructive feedback has been given, and the
thoughtfulness of the reviewers to offer up alternative solutions,
show examples, etc.  Junio, Jeff, and especially Jonathan have been
particularly good on that front--at least those are some of the
regulars that stick out in my mind.  Overall, I've been pretty happy
with the community, and while I haven't contributed much, I generally
enjoy reading the emails.  I feel like I learn something new all the
time. :-)

-John
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/3] Move create_notes_commit() from notes-merge.c into notes-utils.c

2013-06-11 Thread Johan Herland
create_notes_commit() is needed by both the notes-merge code, and by
commit_notes() in notes-utils. Since it is generally useful, and not
bound to the notes-merge machinery, we move it from (the more specific)
notes-merge to (the more general) notes-utils.

Signed-off-by: Johan Herland jo...@herland.net
---
 notes-merge.c | 27 +--
 notes-merge.h | 14 --
 notes-utils.c | 27 ++-
 notes-utils.h | 14 ++
 4 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/notes-merge.c b/notes-merge.c
index 0f67bd3..ab18857 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -9,6 +9,7 @@
 #include notes.h
 #include notes-merge.h
 #include strbuf.h
+#include notes-utils.h
 
 struct notes_merge_pair {
unsigned char obj[20], base[20], local[20], remote[20];
@@ -530,32 +531,6 @@ static int merge_from_diffs(struct notes_merge_options *o,
return conflicts ? -1 : 1;
 }
 
-void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
-const struct strbuf *msg, unsigned char *result_sha1)
-{
-   unsigned char tree_sha1[20];
-
-   assert(t-initialized);
-
-   if (write_notes_tree(t, tree_sha1))
-   die(Failed to write notes tree to database);
-
-   if (!parents) {
-   /* Deduce parent commit from t-ref */
-   unsigned char parent_sha1[20];
-   if (!read_ref(t-ref, parent_sha1)) {
-   struct commit *parent = lookup_commit(parent_sha1);
-   if (!parent || parse_commit(parent))
-   die(Failed to find/parse commit %s, t-ref);
-   commit_list_insert(parent, parents);
-   }
-   /* else: t-ref points to nothing, assume root/orphan commit */
-   }
-
-   if (commit_tree(msg, tree_sha1, parents, result_sha1, NULL, NULL))
-   die(Failed to commit notes tree to database);
-}
-
 int notes_merge(struct notes_merge_options *o,
struct notes_tree *local_tree,
unsigned char *result_sha1)
diff --git a/notes-merge.h b/notes-merge.h
index 0c11b17..1d01f6a 100644
--- a/notes-merge.h
+++ b/notes-merge.h
@@ -26,20 +26,6 @@ struct notes_merge_options {
 void init_notes_merge_options(struct notes_merge_options *o);
 
 /*
- * Create new notes commit from the given notes tree
- *
- * Properties of the created commit:
- * - tree: the result of converting t to a tree object with write_notes_tree().
- * - parents: the given parents OR (if NULL) the commit referenced by t-ref.
- * - author/committer: the default determined by commmit_tree().
- * - commit message: msg
- *
- * The resulting commit SHA1 is stored in result_sha1.
- */
-void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
-const struct strbuf *msg, unsigned char *result_sha1);
-
-/*
  * Merge notes from o-remote_ref into o-local_ref
  *
  * The given notes_tree 'local_tree' must be the notes_tree referenced by the
diff --git a/notes-utils.c b/notes-utils.c
index 2ae5cb2..9107c37 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -2,7 +2,32 @@
 #include commit.h
 #include refs.h
 #include notes-utils.h
-#include notes-merge.h // need create_notes_commit()
+
+void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
+const struct strbuf *msg, unsigned char *result_sha1)
+{
+   unsigned char tree_sha1[20];
+
+   assert(t-initialized);
+
+   if (write_notes_tree(t, tree_sha1))
+   die(Failed to write notes tree to database);
+
+   if (!parents) {
+   /* Deduce parent commit from t-ref */
+   unsigned char parent_sha1[20];
+   if (!read_ref(t-ref, parent_sha1)) {
+   struct commit *parent = lookup_commit(parent_sha1);
+   if (!parent || parse_commit(parent))
+   die(Failed to find/parse commit %s, t-ref);
+   commit_list_insert(parent, parents);
+   }
+   /* else: t-ref points to nothing, assume root/orphan commit */
+   }
+
+   if (commit_tree(msg, tree_sha1, parents, result_sha1, NULL, NULL))
+   die(Failed to commit notes tree to database);
+}
 
 void commit_notes(struct notes_tree *t, const char *msg)
 {
diff --git a/notes-utils.h b/notes-utils.h
index 0661e99..b4cb1bf 100644
--- a/notes-utils.h
+++ b/notes-utils.h
@@ -3,6 +3,20 @@
 
 #include notes.h
 
+/*
+ * Create new notes commit from the given notes tree
+ *
+ * Properties of the created commit:
+ * - tree: the result of converting t to a tree object with write_notes_tree().
+ * - parents: the given parents OR (if NULL) the commit referenced by t-ref.
+ * - author/committer: the default determined by commmit_tree().
+ * - commit message: msg
+ *
+ * The resulting commit SHA1 is stored in result_sha1.
+ */
+void 

[PATCH 2/3] Move copy_note_for_rewrite + friends from builtin/notes.c to notes-utils.c

2013-06-11 Thread Johan Herland
This is a pure code movement of the machinery for copying notes to
rewritten objects. This code was located in builtin/notes.c for
historical reasons. In order to make it available to builtin/commit.c
it was declared in builtin.h. This was more of an accident of history
than a concious design, and we now want to make this machinery more
widely available.

Hence, this patch moves the code into the new notes-utils.[hc] files
which are included into libgit.a. Except for adjusting #includes
accordingly, this patch merely moves the relevant functions verbatim
into the new files.

Cc: Thomas Rast tr...@inf.ethz.ch
Signed-off-by: Johan Herland jo...@herland.net
---
 Makefile |   2 +
 builtin.h|  16 ---
 builtin/commit.c |   1 +
 builtin/notes.c  | 131 +-
 notes-utils.c| 132 +++
 notes-utils.h|  23 ++
 6 files changed, 159 insertions(+), 146 deletions(-)
 create mode 100644 notes-utils.c
 create mode 100644 notes-utils.h

diff --git a/Makefile b/Makefile
index 0f931a2..22deee1 100644
--- a/Makefile
+++ b/Makefile
@@ -682,6 +682,7 @@ LIB_H += merge-recursive.h
 LIB_H += mergesort.h
 LIB_H += notes-cache.h
 LIB_H += notes-merge.h
+LIB_H += notes-utils.h
 LIB_H += notes.h
 LIB_H += object.h
 LIB_H += pack-refs.h
@@ -815,6 +816,7 @@ LIB_OBJS += name-hash.o
 LIB_OBJS += notes.o
 LIB_OBJS += notes-cache.o
 LIB_OBJS += notes-merge.o
+LIB_OBJS += notes-utils.o
 LIB_OBJS += object.o
 LIB_OBJS += pack-check.o
 LIB_OBJS += pack-refs.o
diff --git a/builtin.h b/builtin.h
index 78fb14d..72bb2a8 100644
--- a/builtin.h
+++ b/builtin.h
@@ -5,7 +5,6 @@
 #include strbuf.h
 #include cache.h
 #include commit.h
-#include notes.h
 
 #define DEFAULT_MERGE_LOG_LEN 20
 
@@ -23,21 +22,6 @@ struct fmt_merge_msg_opts {
 extern int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
 struct fmt_merge_msg_opts *);
 
-struct notes_rewrite_cfg {
-   struct notes_tree **trees;
-   const char *cmd;
-   int enabled;
-   combine_notes_fn combine;
-   struct string_list *refs;
-   int refs_from_env;
-   int mode_from_env;
-};
-
-struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd);
-int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
- const unsigned char *from_obj, const unsigned char 
*to_obj);
-void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c, const char 
*msg);
-
 extern int textconv_object(const char *path, unsigned mode, const unsigned 
char *sha1, int sha1_valid, char **buf, unsigned long *buf_size);
 
 extern int cmd_add(int argc, const char **argv, const char *prefix);
diff --git a/builtin/commit.c b/builtin/commit.c
index f8df8ca..ce40176 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -29,6 +29,7 @@
 #include gpg-interface.h
 #include column.h
 #include sequencer.h
+#include notes-utils.h
 
 static const char * const builtin_commit_usage[] = {
N_(git commit [options] [--] pathspec...),
diff --git a/builtin/notes.c b/builtin/notes.c
index 6a80714..9ed2508 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -18,9 +18,7 @@
 #include parse-options.h
 #include string-list.h
 #include notes-merge.h
-
-static void commit_notes(struct notes_tree *t, const char *msg);
-static combine_notes_fn parse_combine_notes_fn(const char *v);
+#include notes-utils.h
 
 static const char * const git_notes_usage[] = {
N_(git notes [--ref notes_ref] [list [object]]),
@@ -287,133 +285,6 @@ static int parse_reedit_arg(const struct option *opt, 
const char *arg, int unset
return parse_reuse_arg(opt, arg, unset);
 }
 
-static void commit_notes(struct notes_tree *t, const char *msg)
-{
-   struct strbuf buf = STRBUF_INIT;
-   unsigned char commit_sha1[20];
-
-   if (!t)
-   t = default_notes_tree;
-   if (!t-initialized || !t-ref || !*t-ref)
-   die(_(Cannot commit uninitialized/unreferenced notes tree));
-   if (!t-dirty)
-   return; /* don't have to commit an unchanged tree */
-
-   /* Prepare commit message and reflog message */
-   strbuf_addstr(buf, msg);
-   if (buf.buf[buf.len - 1] != '\n')
-   strbuf_addch(buf, '\n'); /* Make sure msg ends with newline */
-
-   create_notes_commit(t, NULL, buf, commit_sha1);
-   strbuf_insert(buf, 0, notes: , 7); /* commit message starts at index 
7 */
-   update_ref(buf.buf, t-ref, commit_sha1, NULL, 0, DIE_ON_ERR);
-
-   strbuf_release(buf);
-}
-
-static combine_notes_fn parse_combine_notes_fn(const char *v)
-{
-   if (!strcasecmp(v, overwrite))
-   return combine_notes_overwrite;
-   else if (!strcasecmp(v, ignore))
-   return combine_notes_ignore;
-   else if (!strcasecmp(v, concatenate))
-   return combine_notes_concatenate;
-   else if (!strcasecmp(v, cat_sort_uniq))
-   return 

[PATCH 1/3] finish_copy_notes_for_rewrite(): Let caller provide commit message

2013-06-11 Thread Johan Herland
When copying notes for a rewritten object, the resulting notes commit
would have the following hardcoded commit message:

  Notes added by 'git notes copy'

This is obviously bogus when the notes rewriting is performed by
'git commit --amend'.

Therefore, let the caller specify an appropriate notes commit message
instead of hardcoding it. The above message is used for 'git notes copy',
but when calling finish_copy_notes_for_rewrite() from builtin/commit.c,
we use the following message instead:

  Notes added by 'git commit --amend'

Cc: Thomas Rast tr...@inf.ethz.ch
Signed-off-by: Johan Herland jo...@herland.net
---
 builtin.h| 2 +-
 builtin/commit.c | 2 +-
 builtin/notes.c  | 9 +
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/builtin.h b/builtin.h
index faef559..78fb14d 100644
--- a/builtin.h
+++ b/builtin.h
@@ -36,7 +36,7 @@ struct notes_rewrite_cfg {
 struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd);
 int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
  const unsigned char *from_obj, const unsigned char 
*to_obj);
-void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c);
+void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c, const char 
*msg);
 
 extern int textconv_object(const char *path, unsigned mode, const unsigned 
char *sha1, int sha1_valid, char **buf, unsigned long *buf_size);
 
diff --git a/builtin/commit.c b/builtin/commit.c
index d2f30d9..f8df8ca 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1591,7 +1591,7 @@ int cmd_commit(int argc, const char **argv, const char 
*prefix)
if (cfg) {
/* we are amending, so current_head is not NULL */
copy_note_for_rewrite(cfg, current_head-object.sha1, 
sha1);
-   finish_copy_notes_for_rewrite(cfg);
+   finish_copy_notes_for_rewrite(cfg, Notes added by 'git 
commit --amend');
}
run_rewrite_hook(current_head-object.sha1, sha1);
}
diff --git a/builtin/notes.c b/builtin/notes.c
index 57748a6..6a80714 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -403,11 +403,11 @@ int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
return ret;
 }
 
-void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c)
+void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c, const char 
*msg)
 {
int i;
for (i = 0; c-trees[i]; i++) {
-   commit_notes(c-trees[i], Notes added by 'git notes copy');
+   commit_notes(c-trees[i], msg);
free_notes(c-trees[i]);
}
free(c-trees);
@@ -420,6 +420,7 @@ static int notes_copy_from_stdin(int force, const char 
*rewrite_cmd)
struct notes_rewrite_cfg *c = NULL;
struct notes_tree *t = NULL;
int ret = 0;
+   const char *msg = Notes added by 'git notes copy';
 
if (rewrite_cmd) {
c = init_copy_notes_for_rewrite(rewrite_cmd);
@@ -461,10 +462,10 @@ static int notes_copy_from_stdin(int force, const char 
*rewrite_cmd)
}
 
if (!rewrite_cmd) {
-   commit_notes(t, Notes added by 'git notes copy');
+   commit_notes(t, msg);
free_notes(t);
} else {
-   finish_copy_notes_for_rewrite(c);
+   finish_copy_notes_for_rewrite(c, msg);
}
return ret;
 }
-- 
1.8.1.3.704.g33f7d4f

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 0/3] Refactor useful notes functions into notes-utils.[ch]

2013-06-11 Thread Johan Herland
 There is only one right solution.  If a useful function is buried in
 builtin/*.o as a historical accident (i.e. it started its life as a
 helper for that particular command, and nobody else used it from
 outside so far) and that makes it impossible to use the function
 from outside builtin/*.o, refactor the function and its callers and
 move it to libgit.a.

Here goes...

...Johan

Johan Herland (3):
  finish_copy_notes_for_rewrite(): Let caller provide commit message
  Move copy_note_for_rewrite + friends from builtin/notes.c to notes-utils.c
  Move create_notes_commit() from notes-merge.c into notes-utils.c

 Makefile |   2 +
 builtin.h|  16 --
 builtin/commit.c |   3 +-
 builtin/notes.c  | 136 ++-
 notes-merge.c|  27 +-
 notes-merge.h|  14 -
 notes-utils.c| 157 +++
 notes-utils.h|  37 +
 8 files changed, 203 insertions(+), 189 deletions(-)
 create mode 100644 notes-utils.c
 create mode 100644 notes-utils.h

-- 
1.8.1.3.704.g33f7d4f

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] Move copy_note_for_rewrite + friends from builtin/notes.c to notes-utils.c

2013-06-11 Thread Felipe Contreras
On Tue, Jun 11, 2013 at 7:13 PM, Johan Herland jo...@herland.net wrote:
 This is a pure code movement of the machinery for copying notes to
 rewritten objects. This code was located in builtin/notes.c for
 historical reasons. In order to make it available to builtin/commit.c
 it was declared in builtin.h. This was more of an accident of history
 than a concious design, and we now want to make this machinery more
 widely available.

 Hence, this patch moves the code into the new notes-utils.[hc] files
 which are included into libgit.a. Except for adjusting #includes
 accordingly, this patch merely moves the relevant functions verbatim
 into the new files.

 Cc: Thomas Rast tr...@inf.ethz.ch
 Signed-off-by: Johan Herland jo...@herland.net

I wonder where you got that idea from. Did you come up with that out thin air?

And here goes my bet; nobody will ever use these notes-utils outside
of the git binary. Ever.

-- 
Felipe Contreras
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


<    1   2